diff --git a/frontend/src/certs/NewRegister/RegisterPreview.tsx b/frontend/src/certs/NewRegister/RegisterPreview.tsx index dfe7937..c21e536 100644 --- a/frontend/src/certs/NewRegister/RegisterPreview.tsx +++ b/frontend/src/certs/NewRegister/RegisterPreview.tsx @@ -4,6 +4,7 @@ import { XIcon } from "../../icons/XIcon"; import { allCourses } from "../../utils/allCourses"; import { RegisterBatchCreate } from "../../types/Register"; import { RegistrationPreview } from "."; +import { loadCustomLabels } from "../../utils/allCustomLabels"; function isoDateToLocalDate(date: string): string { @@ -13,16 +14,19 @@ function isoDateToLocalDate(date: string): string { export function RegisterPreview(props: {selections: Array, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) { const submit = async() => { - const registers: RegisterBatchCreate = props.selections.map(({courseId, date}) => ({ + const registers: RegisterBatchCreate = props.selections.map(({courseId, date, customLabel}) => ({ person_id: props.personId!, course_id: courseId, date, + custom_label: customLabel, })); const result = await createRegisters(registers); if (result === null) { console.log("Create register: success"); + // Custom labels may have changed, reload them + loadCustomLabels(); } else { console.log(`error. ${result}`); } diff --git a/frontend/src/types/Register.ts b/frontend/src/types/Register.ts index f9b540e..3bef655 100644 --- a/frontend/src/types/Register.ts +++ b/frontend/src/types/Register.ts @@ -5,6 +5,10 @@ export type RegisterBatchCreate = Array<{ * YYYY-MM-DD */ date: string, + /** + * Value of the custom label + */ + custom_label: string, }> export type Register = { diff --git a/frontend/src/utils/allCustomLabels.ts b/frontend/src/utils/allCustomLabels.ts index e18fd04..f5d4c50 100644 --- a/frontend/src/utils/allCustomLabels.ts +++ b/frontend/src/utils/allCustomLabels.ts @@ -5,8 +5,7 @@ type CustomLabelsMap = {[k: number]: CustomLabel}; export const [customLabelsMap, setCustomLabelsMap] = createSignal<{[k: number]: CustomLabel}>({}); -(() => { - // Get all labels from the API +export function loadCustomLabels() { fetch(`${import.meta.env.VITE_BACKEND_URL}/api/label`) .then((res) => res.json()) .then((data: Array) => { @@ -16,4 +15,7 @@ export const [customLabelsMap, setCustomLabelsMap] = createSignal<{[k: number]: } setCustomLabelsMap(map); }); -})(); +} + +loadCustomLabels(); +