Skip to content

Commit

Permalink
create page aliases for admin (#1239)
Browse files Browse the repository at this point in the history
  • Loading branch information
mipyykko committed Aug 30, 2023
1 parent f1d6c8a commit d82baf2
Show file tree
Hide file tree
Showing 26 changed files with 109 additions and 39 deletions.
17 changes: 12 additions & 5 deletions frontend/components/Dashboard/CourseCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ButtonWithPaddingAndMargin as StyledButton } from "/components/Buttons/
import CourseImage from "/components/CourseImage"
import { CardTitle } from "/components/Text/headers"
import { useFilterContext } from "/contexts/FilterContext"
import useIsNew from "/hooks/useIsNew"
import { useTranslator } from "/hooks/useTranslator"
import CoursesTranslations from "/translations/courses"
import { formatDateTime } from "/util/dataFormatFunctions"
Expand Down Expand Up @@ -173,6 +174,9 @@ interface CourseCardProps {

const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
const t = useTranslator(CoursesTranslations)
const isNewLayout = useIsNew()
const baseUrl = isNewLayout ? "/_new/admin" : ""

const { onStatusClick } = useFilterContext()
const courseFound = !loading && !!course

Expand All @@ -185,7 +189,10 @@ const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
<CourseImage photo={course.photo} alt={course.name} />
)}
{isNew && (
<StyledLink href="/courses/new" aria-label={t("courseNewCourse")}>
<StyledLink
href={`${baseUrl}/courses/new`}
aria-label={t("courseNewCourse")}
>
<CreateCourseIconContainer>
<AddCircleIcon fontSize="large" />
</CreateCourseIconContainer>
Expand Down Expand Up @@ -234,7 +241,7 @@ const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
{courseFound && (
<>
<StyledButton
href={`/courses/${course.slug}`}
href={`${baseUrl}/courses/${course.slug}`}
prefetch={false}
aria-label={t("courseToCoursePage", { name: course.name })}
variant="text"
Expand All @@ -243,7 +250,7 @@ const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
Dashboard
</StyledButton>
<StyledButton
href={`/courses/new?clone=${course.slug}`}
href={`${baseUrl}/courses/new?clone=${course.slug}`}
prefetch={false}
aria-label={t("courseCloneCourse", { name: course.name })}
variant="text"
Expand All @@ -253,7 +260,7 @@ const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
Clone...
</StyledButton>
<StyledButton
href={`/courses/${course.slug}/edit`}
href={`${baseUrl}/courses/${course.slug}/edit`}
prefetch={false}
aria-label={t("courseEditCourse", { name: course.name })}
variant="text"
Expand All @@ -266,7 +273,7 @@ const CourseCard = ({ course, loading, isNew }: CourseCardProps) => {
{isNew && (
<StyledButton
prefetch={false}
href="/courses/new"
href={`${baseUrl}/courses/new`}
aria-label={t("courseNewCourse")}
variant="text"
color="secondary"
Expand Down
7 changes: 5 additions & 2 deletions frontend/components/Dashboard/StudyModules/ModuleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { css, styled } from "@mui/material/styles"
import { ButtonWithPaddingAndMargin } from "/components/Buttons/ButtonWithPaddingAndMargin"
import LoaderImage from "/components/LoaderImage"
import { ClickableDiv } from "/components/Surfaces/ClickableCard"
import useIsNew from "/hooks/useIsNew"
import { useTranslator } from "/hooks/useTranslator"
import StudyModulesTranslations from "/translations/study-modules"

Expand Down Expand Up @@ -117,6 +118,8 @@ interface ModuleCardProps {

function ModuleCard({ studyModule, image, loading }: ModuleCardProps) {
const t = useTranslator(StudyModulesTranslations)
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""
const moduleFound = !loading && studyModule
const moduleNotFound = !loading && !studyModule

Expand Down Expand Up @@ -162,7 +165,7 @@ function ModuleCard({ studyModule, image, loading }: ModuleCardProps) {
)}
{moduleFound && (
<ModuleButton
href={`/study-modules/${studyModule.slug}/edit`}
href={`${baseUrl}/study-modules/${studyModule.slug}/edit`}
aria-label={t("editStudyModule")}
variant="text"
color="secondary"
Expand All @@ -173,7 +176,7 @@ function ModuleCard({ studyModule, image, loading }: ModuleCardProps) {
)}
{moduleNotFound && (
<ModuleButton
href="/study-modules/new"
href={`${baseUrl}/study-modules/new`}
aria-label={t("newStudyModule")}
variant="text"
color="secondary"
Expand Down
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/courses/[slug]/completions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CourseCompletionPage from "pages/courses/[slug]/completions"

export default CourseCompletionPage
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/courses/[slug]/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CourseEditPage from "pages/courses/[slug]/edit"

export default CourseEditPage
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/courses/[slug]/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CourseIndexPage from "pages/courses/[slug]/index"

export default CourseIndexPage
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ManualCompletionsPage from "pages/courses/[slug]/manual-completions"

export default ManualCompletionsPage
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/courses/[slug]/points.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CoursePointsPage from "pages/courses/[slug]/points"

export default CoursePointsPage
File renamed without changes.
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/courses/new.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import NewCoursePage from "pages/courses/new"

export default NewCoursePage
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/email-templates/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import EmailTemplateEditPage from "pages/email-templates/[id]"

export default EmailTemplateEditPage
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/study-modules/[slug]/edit.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import StudyModuleEditPage from "pages/study-modules/[slug]/edit"

export default StudyModuleEditPage
File renamed without changes.
3 changes: 3 additions & 0 deletions frontend/pages/_new/admin/study-modules/new.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import NewStudyModulePage from "pages/study-modules/new"

export default NewStudyModulePage
2 changes: 1 addition & 1 deletion frontend/pages/_new/study-modules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function StudyModules() {
useBreadcrumbs([
{
translation: "studyModules",
href: "/study-modules",
href: "/_new/study-modules",
},
])

Expand Down
11 changes: 7 additions & 4 deletions frontend/pages/courses/[slug]/completions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Spinner from "/components/Spinner"
import { H1NoBackground, SubtitleNoBackground } from "/components/Text/headers"
import CourseLanguageContext from "/contexts/CourseLanguageContext"
import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import { useTranslator } from "/hooks/useTranslator"
import withAdmin from "/lib/with-admin"
Expand All @@ -32,6 +33,8 @@ const ContentArea = styled("div")`
`

const Completions = () => {
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""
const t = useTranslator(CoursesTranslations)
const slug = useQueryParameter("slug")
const router = useRouter()
Expand All @@ -44,7 +47,7 @@ const Completions = () => {
(e: ChangeEvent<HTMLInputElement>) => {
// prevents reloading page, URL changes

const href = `/courses/${slug}/completions?language=${e.target.value}`
const href = `${baseUrl}/courses/${slug}/completions?language=${e.target.value}`
changeLng(e.target.value)
router.replace(router.pathname, href, { shallow: true })
},
Expand All @@ -71,15 +74,15 @@ const Completions = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
label: data?.course?.name,
href: `/courses/${slug}`,
href: `${baseUrl}/courses/${slug}`,
},
{
translation: "courseCompletions",
href: `/courses/${slug}/completions`,
href: `${baseUrl}/courses/${slug}/completions`,
},
])
const title = data?.course?.name ?? "..."
Expand Down
11 changes: 7 additions & 4 deletions frontend/pages/courses/[slug]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import ModifiableErrorMessage from "/components/ModifiableErrorMessage"
import { H1Background } from "/components/Text/headers"
import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import { useEditorCourses } from "/hooks/useEditorCourses"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import { useTranslator } from "/hooks/useTranslator"
import withAdmin from "/lib/with-admin"
Expand All @@ -38,6 +39,8 @@ const LegacyCourseEdit = dynamic(

const EditCourse = () => {
const t = useTranslator(CoursesTranslations)
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""
const slug = useQueryParameter("slug") ?? ""
const legacy = useQueryParameter("legacy", { enforce: false })
const router = useRouter()
Expand All @@ -55,7 +58,7 @@ const EditCourse = () => {

if (!loading && !course) {
redirectTimeout = setTimeout(
() => router.push("/courses", undefined, { shallow: true }),
() => router.push(`${baseUrl}/courses`, undefined, { shallow: true }),
5000,
)
}
Expand All @@ -70,15 +73,15 @@ const EditCourse = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
label: error || (!loading && !course) ? slug : course?.name,
href: `/courses/${slug}`,
href: `${baseUrl}/courses/${slug}`,
},
{
translation: "courseEdit",
href: `/courses/${slug}/edit`,
href: `${baseUrl}/courses/${slug}/edit`,
},
])

Expand Down
11 changes: 7 additions & 4 deletions frontend/pages/courses/[slug]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ModifiableErrorMessage from "/components/ModifiableErrorMessage"
import Spinner from "/components/Spinner"
import { H1NoBackground, SubtitleNoBackground } from "/components/Text/headers"
import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import { useTranslator } from "/hooks/useTranslator"
import withAdmin from "/lib/with-admin"
Expand Down Expand Up @@ -50,6 +51,8 @@ const Row = styled(Paper)`
`

const Course = () => {
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""
const slug = useQueryParameter("slug")
const t = useTranslator(CoursesTranslations)
const confirm = useConfirm()
Expand All @@ -71,11 +74,11 @@ const Course = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
label: data?.course?.name,
href: `/courses/${slug}`,
href: `${baseUrl}/courses/${slug}`,
},
])
const title = data?.course?.name ?? "..."
Expand Down Expand Up @@ -176,7 +179,7 @@ const Course = () => {
<Row>
{data.course?.completion_email != null ? (
<Link
href={`/email-templates/${data.course.completion_email?.id}`}
href={`${baseUrl}/email-templates/${data.course.completion_email?.id}`}
prefetch={false}
passHref
>
Expand All @@ -194,7 +197,7 @@ const Course = () => {
{data.course?.course_stats_email !== null ? (
<>
<Link
href={`/email-templates/${data.course.course_stats_email?.id}`}
href={`${baseUrl}/email-templates/${data.course.course_stats_email?.id}`}
prefetch={false}
passHref
>
Expand Down
9 changes: 6 additions & 3 deletions frontend/pages/courses/[slug]/manual-completions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { AdapterLuxon } from "@mui/x-date-pickers/AdapterLuxon"
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"

import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import withAdmin from "/lib/with-admin"

Expand All @@ -47,6 +48,8 @@ interface CompletionData {
}

const ManualCompletions = () => {
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""
const { locale } = useRouter()
const confirm = useConfirm()
const [submitting, setSubmitting] = useState(false)
Expand Down Expand Up @@ -78,15 +81,15 @@ const ManualCompletions = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
label: courseData?.course?.name,
href: `/courses/${slug}`,
href: `${baseUrl}/courses/${slug}`,
},
{
translation: "courseManualCompletions",
href: `/courses/${slug}/manual-completions`,
href: `${baseUrl}/courses/${slug}/manual-completions`,
},
])
const title = courseData?.course?.name ?? "..."
Expand Down
9 changes: 6 additions & 3 deletions frontend/pages/courses/[slug]/points.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ModifiableErrorMessage from "/components/ModifiableErrorMessage"
import Spinner from "/components/Spinner"
import { H1NoBackground, SubtitleNoBackground } from "/components/Text/headers"
import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import { useTranslator } from "/hooks/useTranslator"
import withAdmin from "/lib/with-admin"
Expand All @@ -19,6 +20,8 @@ import { CourseFromSlugDocument } from "/graphql/generated"

const Points = () => {
const t = useTranslator(CoursesTranslations)
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""

const slug = useQueryParameter("slug")

Expand All @@ -29,15 +32,15 @@ const Points = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
label: data?.course?.name,
href: `/courses/${slug}`,
href: `${baseUrl}/courses/${slug}`,
},
{
translation: "coursePoints",
href: `/courses/${slug}/points`,
href: `${baseUrl}/courses/${slug}/points`,
},
])
const title = data?.course?.name ?? "..."
Expand Down
7 changes: 5 additions & 2 deletions frontend/pages/courses/new.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ModifiableErrorMessage from "/components/ModifiableErrorMessage"
import { H1NoBackground } from "/components/Text/headers"
import { useBreadcrumbs } from "/hooks/useBreadcrumbs"
import { useEditorCourses } from "/hooks/useEditorCourses"
import useIsNew from "/hooks/useIsNew"
import { useQueryParameter } from "/hooks/useQueryParameter"
import { useTranslator } from "/hooks/useTranslator"
import withAdmin from "/lib/with-admin"
Expand All @@ -31,6 +32,8 @@ const LegacyCourseEdit = dynamic(

const NewCourse = () => {
const t = useTranslator(CoursesTranslations)
const isNew = useIsNew()
const baseUrl = isNew ? "/_new/admin" : ""

const clone = useQueryParameter("clone", { enforce: false })
const legacy = useQueryParameter("legacy", { enforce: false })
Expand All @@ -44,11 +47,11 @@ const NewCourse = () => {
useBreadcrumbs([
{
translation: "courses",
href: `/courses`,
href: `${baseUrl}/courses`,
},
{
translation: "courseNew",
href: `/courses/new`,
href: `${baseUrl}/courses/new`,
},
])

Expand Down
Loading

0 comments on commit d82baf2

Please sign in to comment.