import { FilledCard } from "../../components/FilledCard"; import { For } from "solid-js"; import { XIcon } from "../../icons/XIcon"; import { allCourses } from "../../utils/allCourses"; function isoDateToLocalDate(date: string): string { const [,month, day] = /\d{4}-(\d{2})-(\d{2})/.exec(date) ?? ""; return `${day}/${month}`; } export function RegisterPreview(props: {selections: Array<[number, string]>, personId: number | null, onDelete: (v: number) => void, onRegister: () => void}) { const submit = async() => { console.log("Submit..."); // TODO: Send all register requests at once for (const [courseId, date] of props.selections) { const result = await defaultNewRegisterFn( props.personId ?? -1, courseId, date, ); if (result === null) { console.log("Success"); } else { console.log(`error. ${result}`); } } props.onRegister(); }; return (

Confirmar registro

{([courseId, date]) => }
); } function Register(props: {courseId: number, date: string, onDelete: (v: number) => void}) { const courseName = () => { const courses = allCourses(); return courses.find((course) => course.course_id === props.courseId)?.course_name ?? "!"; }; return (
{courseName()} {isoDateToLocalDate(props.date)}
); } async function defaultNewRegisterFn(personId: number, subjectId: number, date: string): Promise { const response = await fetch("/certificate", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ personId, subjectId, date, }), }); if (response.ok) { return null; } else { const data = await response.json(); return JSON.stringify(data); } }