Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit fe3c0f8

Browse files
committed
fixes typing by changing priority to type number
1 parent 5487e9c commit fe3c0f8

3 files changed

Lines changed: 25 additions & 20 deletions

File tree

apps/ui/components/application/Form.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ApplicationEventScheduleFormTypeSchema = z.object({
2828
day: z.number().min(0).max(6),
2929
begin: z.string(),
3030
end: z.string(),
31-
priority: z.union([z.literal(100), z.literal(200), z.literal(300)]),
31+
priority: z.number(),
3232
});
3333

3434
export type ApplicationEventScheduleFormType = z.infer<

apps/ui/components/application/Page2.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@ import { useTranslation } from "next-i18next";
44
import { useRouter } from "next/router";
55
import styled from "styled-components";
66
import { useFormContext } from "react-hook-form";
7-
import type {
8-
ApplicationEvent,
9-
ApplicationEventSchedulePriority,
10-
} from "common/types/common";
7+
import type { ApplicationEventSchedulePriority } from "common/types/common";
118
import type {
129
ApplicationEventScheduleNode,
1310
ApplicationNode,
@@ -35,15 +32,15 @@ type Props = {
3532

3633
type OpeningHourPeriod = {
3734
begin: string;
38-
beginValue: number;
3935
end: string;
40-
endValue: number;
41-
};
36+
} | null;
4237

43-
type DailyOpeningHours = {
44-
closed: boolean;
45-
reservableTimes?: OpeningHourPeriod[];
46-
}[];
38+
type DailyOpeningHours =
39+
| {
40+
closed: boolean;
41+
reservableTimes?: OpeningHourPeriod[] | null;
42+
}[]
43+
| null;
4744

4845
const SubHeading = styled.p`
4946
margin-top: var(--spacing-2-xs);
@@ -78,14 +75,14 @@ const applicationEventSchedulesToCells = (
7875
const dayOpeningHours =
7976
openingHours?.[j]?.reservableTimes?.map((t) => {
8077
return {
81-
beginValue: +t.begin.split(":")[0],
82-
endValue: +t.end.split(":")[0] === 0 ? 24 : +t.end.split(":")[0],
78+
begin: t && +t.begin.split(":")[0],
79+
end: t && +t.end.split(":")[0] === 0 ? 24 : t && +t.end.split(":")[0],
8380
};
8481
}) ?? [];
8582
// state is 50 if the cell is outside of the opening hours, 100 if it's inside
8683
for (let i = firstSlotStart; i <= lastSlotStart; i += 1) {
8784
const isAvailable = dayOpeningHours.some(
88-
(t) => t.beginValue <= i && t.endValue > i
85+
(t) => t.begin != null && t.end != null && t?.begin <= i && t?.end > i
8986
);
9087
day.push({
9188
key: `${i}-${j}`,
@@ -224,15 +221,16 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
224221
QueryApplicationRoundsArgs
225222
>(RESERVATION_UNIT, {
226223
variables: {
227-
pk: application.applicationRound.pk,
224+
pk: [application.applicationRound.pk ?? 0],
228225
},
226+
skip: !application.applicationRound.pk,
229227
fetchPolicy: "no-cache",
230228
});
231229
const [successMsg, setSuccessMsg] = useState("");
232230
const [errorMsg, setErrorMsg] = useState("");
233231
const [minDurationMsg, setMinDurationMsg] = useState(true);
234232
const router = useRouter();
235-
const openingHours: DailyOpeningHours =
233+
const openingHours =
236234
applicationRound?.reservationUnitByPk?.applicationRoundTimeSlots ?? [];
237235

238236
const { getValues, setValue, watch, handleSubmit } =
@@ -259,7 +257,7 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
259257
// TODO: day is incorrect (empty days at the start are missing, and 200 / 300 priority on the same day gets split into two days)
260258
// TODO refactor the Cell -> ApplicationEventSchedule conversion to use FormTypes
261259
selectedAppEvents.forEach((appEventSchedule, i) => {
262-
const val = appEventSchedule.map((appEvent: ApplicationEvent) => {
260+
const val = appEventSchedule.map((appEvent) => {
263261
const { day } = appEvent;
264262
// debug check
265263
if (day == null || day < 0 || day > 6) {
@@ -318,7 +316,14 @@ const Page2 = ({ application, onNext }: Props): JSX.Element => {
318316
const selectedAppEvents = selectorData
319317
.map((cell) => cellsToApplicationEventSchedules(cell))
320318
.map((aes) =>
321-
aes.filter((ae) => ae.priority === 300 || ae.priority === 200)
319+
aes
320+
.filter((ae) => ae.priority === 300 || ae.priority === 200)
321+
.map((ae) => {
322+
return {
323+
...ae,
324+
priority: ae.priority === 300 ? (300 as const) : (200 as const),
325+
};
326+
})
322327
)
323328
.flat();
324329
if (selectedAppEvents.length === 0) {

packages/common/types/common.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export type ApplicationEvent = {
103103

104104
export type DAY = 0 | 1 | 2 | 3 | 4 | 5 | 6;
105105

106-
export type ApplicationEventSchedulePriority = 50 | 100 | 200 | 300;
106+
export type ApplicationEventSchedulePriority = number;
107107

108108
// @deprecated required by pdf export
109109
export type ReservationState =

0 commit comments

Comments
 (0)