diff --git a/frontend/src/certs/NewRegister/RegisterPresets.tsx b/frontend/src/certs/NewRegister/RegisterPresets.tsx new file mode 100644 index 0000000..0b27273 --- /dev/null +++ b/frontend/src/certs/NewRegister/RegisterPresets.tsx @@ -0,0 +1,18 @@ +import { Chip } from "../../components/Chip"; + +export function RegisterPresets() { + return ( +
+

Las fechas se colocan automáticamente según la duración del curso.

+
+
+ + + + + + +
+
+ ); +} diff --git a/frontend/src/certs/NewRegister/RegisterPreview.tsx b/frontend/src/certs/NewRegister/RegisterPreview.tsx index 39ec07a..7212af5 100644 --- a/frontend/src/certs/NewRegister/RegisterPreview.tsx +++ b/frontend/src/certs/NewRegister/RegisterPreview.tsx @@ -1,10 +1,8 @@ import { FilledCard } from "../../components/FilledCard"; import { For } from "solid-js"; -// import { subjects } from "src/views/subjects"; import { XIcon } from "../../icons/XIcon"; +import { allCourses } from "../../utils/allCourses"; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const subjects: () => Array = () => []; function isoDateToLocalDate(date: string): string { const [,month, day] = /\d{4}-(\d{2})-(\d{2})/.exec(date) ?? ""; @@ -15,6 +13,7 @@ export function RegisterPreview(props: {selections: Array<[number, string]>, per 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, @@ -56,8 +55,8 @@ export function RegisterPreview(props: {selections: Array<[number, string]>, per function Register(props: {courseId: number, date: string, onDelete: (v: number) => void}) { const courseName = () => { - const courses = subjects(); - return courses.find((c) => c.id === props.courseId)?.nombre ?? "!"; + const courses = allCourses(); + return courses.find((course) => course.course_id === props.courseId)?.course_name ?? "!"; }; return ( diff --git a/frontend/src/certs/NewRegister/SearchableSelect.tsx b/frontend/src/certs/NewRegister/SearchableSelect.tsx index c0218e5..935026e 100644 --- a/frontend/src/certs/NewRegister/SearchableSelect.tsx +++ b/frontend/src/certs/NewRegister/SearchableSelect.tsx @@ -1,9 +1,9 @@ import { createEffect, createSignal, For } from "solid-js"; -import type {CursoGIE} from "../../../model/CursoGIE/cursoGIE.entity"; +// import type {CursoGIE} from "../../../model/CursoGIE/cursoGIE.entity"; import { isServer } from "solid-js/web"; +import { allCourses } from "../../utils/allCourses"; export function SearchableSelect(props: { - subjects: Array, onChange: (id: number | null) => void, count: number }) { @@ -68,22 +68,22 @@ export function SearchableSelect(props: { const filteredOptions = () => { const filterText = filter(); - return props.subjects.filter((subject) => { - let subjectText = subject.nombre.toLowerCase(); - subjectText = subjectText.replace("á", "a"); - subjectText = subjectText.replace("é", "e"); - subjectText = subjectText.replace("í", "i"); - subjectText = subjectText.replace("ó", "o"); - subjectText = subjectText.replace("ú", "u"); + return allCourses().filter((course) => { + let courseText = course.course_name.toLowerCase(); + courseText = courseText.replace("á", "a"); + courseText = courseText.replace("é", "e"); + courseText = courseText.replace("í", "i"); + courseText = courseText.replace("ó", "o"); + courseText = courseText.replace("ú", "u"); - return selected() === null && subjectText.indexOf(filterText) !== -1; + return selected() === null && courseText.indexOf(filterText) !== -1; }); }; return ( <> {inputElement} -
+
@@ -95,11 +95,11 @@ export function SearchableSelect(props: { onclick={(ev) => { ev.preventDefault(); - setSelected(s.id); - setInputValue(s.nombre); + setSelected(s.course_id); + setInputValue(s.course_name); }} > - {s.nombre} + {s.course_name} )} diff --git a/frontend/src/certs/NewRegister/index.tsx b/frontend/src/certs/NewRegister/index.tsx index 65fa1e4..12702f1 100644 --- a/frontend/src/certs/NewRegister/index.tsx +++ b/frontend/src/certs/NewRegister/index.tsx @@ -1,12 +1,10 @@ import { createSignal, Show } from "solid-js"; import { SearchableSelect } from "./SearchableSelect"; import { JSX } from "solid-js/jsx-runtime"; -// import { subjects } from "../subjects"; import { FilledCard } from "../../components/FilledCard"; import { RegisterPreview } from "./RegisterPreview"; +import { RegisterPresets } from "./RegisterPresets"; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const subjects: () => Array = () => []; type HTMLEventFn = JSX.EventHandlerUnion -

Registrar certs

+

Agregar certs

-

Proximamente...

+
setSelections((x) => [...x, v])} /> @@ -82,21 +80,20 @@ function ManualCerts(props: {personId: number | null, onAdd: (v: [number, string const [count, setCount] = createSignal(0); const [error, setError] = createSignal(""); - const [selectedSubject, setSelectedSubject] = createSignal(null); + const [selectedCourseId, seSelectedCourseId] = createSignal(null); - const datePicker = ( - - ); + let datePicker: HTMLInputElement | undefined; const register: HTMLEventFn = async(ev) => { ev.preventDefault(); - const subject = selectedSubject(); - const date = (datePicker as HTMLInputElement).value; + const subject = selectedCourseId(); + + if (datePicker === undefined) { + return; + } + + const date = datePicker.value; if (subject === null) { setError("Selecciona un curso"); @@ -123,15 +120,34 @@ function ManualCerts(props: {personId: number | null, onAdd: (v: [number, string
-
- {datePicker} - +
+
+ + +
+
+ + +
void}) { }); } else { setQrBase64(null); + setPerson(null); } }); @@ -44,8 +45,9 @@ export function Search(props: {setPerson: (p: Person | null) => void}) { setError(""); try { - const response = await fetch(`/api/person/${dni()}`); + const response = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/person/${dni()}`); const body = await response.json(); + if (response.ok) { setPerson(body); props.setPerson(body); diff --git a/frontend/src/components/Chip.tsx b/frontend/src/components/Chip.tsx new file mode 100644 index 0000000..3aa48d5 --- /dev/null +++ b/frontend/src/components/Chip.tsx @@ -0,0 +1,9 @@ +export function Chip(props: {text: string}) { + return ( +
+ {props.text} +
+ ); +} diff --git a/frontend/src/types/Course.ts b/frontend/src/types/Course.ts new file mode 100644 index 0000000..f209d09 --- /dev/null +++ b/frontend/src/types/Course.ts @@ -0,0 +1,8 @@ +export type Course = { + course_id: number, + course_code: number, + course_name: string, + course_display_name: string, + course_days_amount: number, + course_has_custom_label: boolean, +} diff --git a/frontend/src/types/Person.tsx b/frontend/src/types/Person.ts similarity index 100% rename from frontend/src/types/Person.tsx rename to frontend/src/types/Person.ts diff --git a/frontend/src/utils/allCourses.ts b/frontend/src/utils/allCourses.ts new file mode 100644 index 0000000..6d4ab41 --- /dev/null +++ b/frontend/src/utils/allCourses.ts @@ -0,0 +1,12 @@ +import { createSignal } from "solid-js"; +import { Course } from "../types/Course"; + +export const [allCourses, setAllCourses] = createSignal>([]); + +(() => { + // Get all courses from the API + fetch(`${import.meta.env.VITE_BACKEND_URL}/api/course`) + .then((res) => res.json()) + .then((data) => setAllCourses(data)); +})(); +