From 3ac8f1321cbfda05a6ba600794cb1b804cdd085e Mon Sep 17 00:00:00 2001 From: Araozu Date: Tue, 13 Jun 2023 21:25:00 -0500 Subject: [PATCH] [FE] Improve batch mode's group UI. --- src/views/AulaVirtual/DniEntry.tsx | 98 +++++++++++++---- .../AulaVirtual/DniEntry/DniRegister.tsx | 104 ++++++++++++++++++ src/views/AulaVirtual/DniGroup.tsx | 33 ++++-- src/views/AulaVirtual/DniTable.tsx | 2 +- src/views/AulaVirtual/Dnis.tsx | 2 +- 5 files changed, 206 insertions(+), 33 deletions(-) create mode 100644 src/views/AulaVirtual/DniEntry/DniRegister.tsx diff --git a/src/views/AulaVirtual/DniEntry.tsx b/src/views/AulaVirtual/DniEntry.tsx index ca46a76..c70c588 100644 --- a/src/views/AulaVirtual/DniEntry.tsx +++ b/src/views/AulaVirtual/DniEntry.tsx @@ -1,43 +1,103 @@ -import { createSignal, onMount } from "solid-js"; +import { createSignal, Match, onMount, Show, Switch } from "solid-js"; import { Person } from "src/types/Person"; +import { DniRegister } from "./DniEntry/DniRegister"; + +/** + * Sample data +01188994 +47695703 +46736668 +21551382 +41178747 +41876027 +04827012 +45912508 +45349984 +41362975 +70861152 +72404776 +46421911 +43502556 + */ + +enum Status { + Empty, + Loading, + Ok, + Error, +} export function DniEntry(props: {dni: string}) { const [person, setPerson] = createSignal(null); + const [status, setStatus] = createSignal(Status.Empty); + + const loadPerson = async() => { + setStatus(Status.Loading); - onMount(async() => { try { const response = await fetch(`/person/${props.dni}`); const body = await response.json(); if (response.ok) { setPerson(body); + setStatus(Status.Ok); + } else if (response.status === 404) { console.error(body); + setStatus(Status.Error); // setWarning("Persona no encontrada. Se debe insertar manualmente sus datos."); setPerson(null); } else { - // setError(body); + setStatus(Status.Error); } } catch (e) { - // setError(JSON.stringify(e)); + setStatus(Status.Error); } - }); + }; + + onMount(loadPerson); return ( -
-
- {props.dni} -
-
- {person()?.apellidoPaterno ?? "..."} -
-
- {person()?.apellidoMaterno ?? "..."} -
-
- {person()?.nombres ?? "..."} -
-
+ <> + +
+
+ {props.dni} +
+ + + +
+
+
+
+ + +
...
+
...
+
...
+
+ + +
+ {person()?.apellidoPaterno ?? "!"} +
+
+ {person()?.apellidoMaterno ?? "!"} +
+
+ {person()?.nombres ?? "!"} +
+
+ +
+
+
+ + + + + ); } diff --git a/src/views/AulaVirtual/DniEntry/DniRegister.tsx b/src/views/AulaVirtual/DniEntry/DniRegister.tsx new file mode 100644 index 0000000..2e1e23c --- /dev/null +++ b/src/views/AulaVirtual/DniEntry/DniRegister.tsx @@ -0,0 +1,104 @@ +import { createSignal, JSX } from "solid-js"; + +type HTMLEventFn = JSX.EventHandlerUnion; + +export function DniRegister(props: {dni: string, onSuccess: () => void}) { + const [nombres, setNombres] = createSignal(""); + const [apellidoP, setApellidoP] = createSignal(""); + const [apellidoM, setApellidoM] = createSignal(""); + const [loading, setLoading] = createSignal(false); + const [error, setError] = createSignal(""); + + const register: HTMLEventFn = async(ev) => { + ev.preventDefault(); + setLoading(true); + setError(""); + + if (props.dni.length !== 8) { + setLoading(false); + setError("DNI es invalido"); + return; + } + + const response = await fetch("/person", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + dni: props.dni.toUpperCase(), + apellidoPaterno: apellidoP().toUpperCase(), + apellidoMaterno: apellidoM().toUpperCase(), + nombres: nombres().toUpperCase(), + }), + }); + + if (response.ok) { + props.onSuccess(); + } else { + const d = await response.json(); + setError(`Error creando persona en BD. ${d}`); + } + + setLoading(false); + }; + + return ( +
+
+ {props.dni} +
+ setApellidoP(e.target.value.toUpperCase())} + disabled={loading()} + /> + setApellidoM(e.target.value.toUpperCase())} + disabled={loading()} + /> + setNombres(e.target.value.toUpperCase())} + disabled={loading()} + /> + + +
+ ); +} diff --git a/src/views/AulaVirtual/DniGroup.tsx b/src/views/AulaVirtual/DniGroup.tsx index 4e29273..6626446 100644 --- a/src/views/AulaVirtual/DniGroup.tsx +++ b/src/views/AulaVirtual/DniGroup.tsx @@ -1,23 +1,32 @@ import { For } from "solid-js"; import { DniEntry } from "./DniEntry"; -export function DniGroup(props: {group: string}) { +export function DniGroup(props: {group: string, index: number}) { const dnis = () => [...props.group.matchAll(/\d+/g)]; - return ( -
-

DNI Group

+ console.log("Loading group..."); -
-
DNI
-
Apellido Paterno
-
Apellido Materno
-
Nombres
+ return ( +
+
+
+
DNI
+
Apellido Paterno
+
Apellido Materno
+
Nombres
+
+ + + {(dni) => } +
- - {(dni) => } - +
+

+ Grupo #{props.index + 1} - cursos y fechas +

+ +
); } diff --git a/src/views/AulaVirtual/DniTable.tsx b/src/views/AulaVirtual/DniTable.tsx index 0c32700..b6e2a70 100644 --- a/src/views/AulaVirtual/DniTable.tsx +++ b/src/views/AulaVirtual/DniTable.tsx @@ -7,7 +7,7 @@ export function DniTable(props: {dniGroups: Array}) {

2. Revisar grupos

- {(g) => } + {(g, index) => }
); diff --git a/src/views/AulaVirtual/Dnis.tsx b/src/views/AulaVirtual/Dnis.tsx index 3f1cdb9..d6c5acd 100644 --- a/src/views/AulaVirtual/Dnis.tsx +++ b/src/views/AulaVirtual/Dnis.tsx @@ -42,7 +42,7 @@ export function Dnis(props: {addDniGroup: (v: string) => void}) {