Skip to content

Commit 7fae9b3

Browse files
committed
Refactor
1 parent dbd7578 commit 7fae9b3

32 files changed

Lines changed: 3247 additions & 2893 deletions

services/main-frontend/src/app/manage/course-plans/[id]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import withErrorBoundary from "@/shared-module/common/utils/withErrorBoundary"
1414
import { QueryResult } from "@/shared-module/components"
1515
import { optionalGeneratedQueryOptions } from "@/utils/optionalGeneratedQueryOptions"
1616

17+
/** Redirects to schedule wizard or workspace based on plan status. */
1718
function CoursePlanHubRedirect() {
1819
const params = useParams<{ id: string }>()
1920
const router = useRouter()

services/main-frontend/src/app/manage/course-plans/[id]/schedule/components/MonthBlock.tsx

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,13 @@
11
"use client"
22

33
import { css } from "@emotion/css"
4-
import {
5-
Berries,
6-
Cabin,
7-
Campfire,
8-
CandleLight,
9-
Leaf,
10-
MapleLeaf,
11-
MistyCloud,
12-
PineTree,
13-
Sleigh,
14-
Sunrise,
15-
WaterLiquid,
16-
WinterSnowflake,
17-
} from "@vectopus/atlas-icons-react"
184
import { format } from "date-fns"
195
import { motion } from "motion/react"
206
import { forwardRef } from "react"
217

228
import { StageMonth } from "../scheduleMappers"
239

24-
const MONTH_ICONS = [
25-
WinterSnowflake,
26-
Sleigh,
27-
Sunrise,
28-
WaterLiquid,
29-
Leaf,
30-
Campfire,
31-
Cabin,
32-
Berries,
33-
MapleLeaf,
34-
MistyCloud,
35-
CandleLight,
36-
PineTree,
37-
] as const
10+
import { COURSE_PLAN_MONTH_ICONS } from "@/app/manage/course-plans/monthIcons"
3811

3912
const stageMonthBlockStyles = css`
4013
min-width: 84px;
@@ -81,7 +54,7 @@ const MonthBlock = forwardRef<HTMLDivElement, MonthBlockProps>(function MonthBlo
8154
{ month, reduceMotion, layoutId },
8255
ref,
8356
) {
84-
const MonthIcon = MONTH_ICONS[month.date.getMonth()]
57+
const MonthIcon = COURSE_PLAN_MONTH_ICONS[month.date.getMonth()]
8558

8659
return (
8760
<motion.div

services/main-frontend/src/app/manage/course-plans/[id]/schedule/components/ScheduleWizardPage.tsx

Lines changed: 0 additions & 202 deletions
This file was deleted.

services/main-frontend/src/app/manage/course-plans/[id]/schedule/components/steps/NameStep.tsx

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"use client"
22

33
import { css } from "@emotion/css"
4-
import { useEffect } from "react"
5-
import { useForm } from "react-hook-form"
64
import { useTranslation } from "react-i18next"
75

6+
import { useWizardTextField } from "../../hooks/useWizardStepFields"
7+
88
import { baseTheme } from "@/shared-module/common/styles"
99
import { Button, TextField } from "@/shared-module/components"
1010

@@ -35,23 +35,8 @@ interface NameStepProps {
3535

3636
export default function NameStep({ planName, onPlanNameChange, onContinue }: NameStepProps) {
3737
const { t } = useTranslation()
38-
const { control, setValue, watch } = useForm<{ planName: string }>({
39-
defaultValues: { planName },
40-
})
41-
42-
useEffect(() => {
43-
setValue("planName", planName)
44-
}, [planName, setValue])
45-
46-
useEffect(() => {
47-
const subscription = watch((values, meta) => {
48-
if (meta.name === "planName") {
49-
onPlanNameChange(values.planName ?? "")
50-
}
51-
})
52-
53-
return () => subscription.unsubscribe()
54-
}, [onPlanNameChange, watch])
38+
// eslint-disable-next-line i18next/no-literal-string
39+
const { control, fieldName } = useWizardTextField("planName", planName, onPlanNameChange)
5540

5641
return (
5742
<>
@@ -60,8 +45,7 @@ export default function NameStep({ planName, onPlanNameChange, onContinue }: Nam
6045
<div className={fieldStyles}>
6146
<TextField
6247
id="course-plan-name"
63-
// eslint-disable-next-line i18next/no-literal-string
64-
name="planName"
48+
name={fieldName}
6549
control={control}
6650
label={t("course-plans-plan-name-label")}
6751
placeholder={t("course-plans-untitled-plan")}

services/main-frontend/src/app/manage/course-plans/[id]/schedule/components/steps/SetupStep.tsx

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"use client"
22

33
import { css } from "@emotion/css"
4-
import { useEffect, useMemo } from "react"
5-
import { useForm } from "react-hook-form"
4+
import { useMemo } from "react"
65
import { useTranslation } from "react-i18next"
76

7+
import { useSetupStepFields } from "../../hooks/useWizardStepFields"
8+
89
import { CourseDesignerCourseSize } from "@/generated/api/types.generated"
910
import { Button, Select, YearMonthField } from "@/shared-module/components"
1011

@@ -50,14 +51,12 @@ export default function SetupStep({
5051
onContinue,
5152
}: SetupStepProps) {
5253
const { t } = useTranslation()
53-
const { control, setValue, watch } = useForm<{
54-
courseSize: CourseDesignerCourseSize
55-
startsOnMonth: string
56-
}>({
57-
defaultValues: {
58-
courseSize,
59-
startsOnMonth,
60-
},
54+
55+
const { control } = useSetupStepFields({
56+
courseSize,
57+
startsOnMonth,
58+
onCourseSizeChange,
59+
onStartsOnMonthChange,
6160
})
6261

6362
const courseSizeOptions = useMemo(
@@ -72,27 +71,6 @@ export default function SetupStep({
7271
[t],
7372
)
7473

75-
useEffect(() => {
76-
setValue("courseSize", courseSize)
77-
}, [courseSize, setValue])
78-
79-
useEffect(() => {
80-
setValue("startsOnMonth", startsOnMonth)
81-
}, [startsOnMonth, setValue])
82-
83-
useEffect(() => {
84-
const subscription = watch((values, meta) => {
85-
if (meta.name === "courseSize" && values.courseSize) {
86-
onCourseSizeChange(values.courseSize)
87-
}
88-
if (meta.name === "startsOnMonth") {
89-
onStartsOnMonthChange(values.startsOnMonth ?? "")
90-
}
91-
})
92-
93-
return () => subscription.unsubscribe()
94-
}, [onCourseSizeChange, onStartsOnMonthChange, watch])
95-
9674
return (
9775
<>
9876
<h2>{t("course-plans-wizard-step-size-and-date")}</h2>

0 commit comments

Comments
 (0)