[FE] Send custom_label to backend
This commit is contained in:
parent
77bd3ba00f
commit
9e38942a2e
@ -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<RegistrationPreview>, 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}`);
|
||||
}
|
||||
|
@ -5,6 +5,10 @@ export type RegisterBatchCreate = Array<{
|
||||
* YYYY-MM-DD
|
||||
*/
|
||||
date: string,
|
||||
/**
|
||||
* Value of the custom label
|
||||
*/
|
||||
custom_label: string,
|
||||
}>
|
||||
|
||||
export type Register = {
|
||||
|
@ -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<CustomLabel>) => {
|
||||
@ -16,4 +15,7 @@ export const [customLabelsMap, setCustomLabelsMap] = createSignal<{[k: number]:
|
||||
}
|
||||
setCustomLabelsMap(map);
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
loadCustomLabels();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user