[FE] Batch mode: Show recent certificates (1y)
This commit is contained in:
parent
7f163db1cd
commit
89bdc1499a
@ -3,7 +3,7 @@ import { renderToString } from "solid-js/web";
|
|||||||
import { CertsBatch } from "src/views/BatchCerts";
|
import { CertsBatch } from "src/views/BatchCerts";
|
||||||
import { template } from "./BatchCerts.template";
|
import { template } from "./BatchCerts.template";
|
||||||
|
|
||||||
@Controller("batch-certs")
|
@Controller("batch-mode")
|
||||||
export class BatchCertController {
|
export class BatchCertController {
|
||||||
@Get()
|
@Get()
|
||||||
entry(): string {
|
entry(): string {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { createSignal, Match, onMount, Show, Switch } from "solid-js";
|
import { createMemo, createSignal, For, Match, onMount, Show, Switch } from "solid-js";
|
||||||
import { Person } from "src/types/Person";
|
import { Person } from "src/types/Person";
|
||||||
import { DniRegister } from "./DniEntry/DniRegister";
|
import { DniRegister } from "./DniEntry/DniRegister";
|
||||||
|
import { RegisterReturn } from "src/types/RegisterReturn";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sample data
|
* Sample data
|
||||||
@ -27,9 +28,11 @@ enum Status {
|
|||||||
Error,
|
Error,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DniEntry(props: {dni: string}) {
|
export function DniEntry(props: {dni: string, remove: (_: string) => void}) {
|
||||||
const [person, setPerson] = createSignal<Person | null>(null);
|
const [person, setPerson] = createSignal<Person | null>(null);
|
||||||
const [status, setStatus] = createSignal<Status>(Status.Empty);
|
const [status, setStatus] = createSignal<Status>(Status.Empty);
|
||||||
|
const [certificates, setCertificates] = createSignal<Array<RegisterReturn>>([]);
|
||||||
|
const [certStatus, setCertStatus] = createSignal<Status>(Status.Empty);
|
||||||
|
|
||||||
const loadPerson = async() => {
|
const loadPerson = async() => {
|
||||||
setStatus(Status.Loading);
|
setStatus(Status.Loading);
|
||||||
@ -40,7 +43,7 @@ export function DniEntry(props: {dni: string}) {
|
|||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
setPerson(body);
|
setPerson(body);
|
||||||
setStatus(Status.Ok);
|
setStatus(Status.Ok);
|
||||||
|
loadCertificates();
|
||||||
} else if (response.status === 404) {
|
} else if (response.status === 404) {
|
||||||
console.error(body);
|
console.error(body);
|
||||||
setStatus(Status.Error);
|
setStatus(Status.Error);
|
||||||
@ -58,6 +61,23 @@ export function DniEntry(props: {dni: string}) {
|
|||||||
|
|
||||||
onMount(loadPerson);
|
onMount(loadPerson);
|
||||||
|
|
||||||
|
const loadCertificates = async() => {
|
||||||
|
setCertStatus(Status.Loading);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/certificate/${props.dni}`);
|
||||||
|
if (response.ok) {
|
||||||
|
const body = await response.json();
|
||||||
|
setCertificates(body);
|
||||||
|
setCertStatus(Status.Ok);
|
||||||
|
} else {
|
||||||
|
setCertStatus(Status.Error);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
setCertStatus(Status.Error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Show when={status() !== Status.Error}>
|
<Show when={status() !== Status.Error}>
|
||||||
@ -96,11 +116,24 @@ export function DniEntry(props: {dni: string}) {
|
|||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<button
|
<button
|
||||||
class={"rounded-full px-2 hover:bg-c-error first:text-c-error first:hover:text-c-on-error"}
|
class={"rounded-full px-2 hover:bg-c-error first:text-c-error first:hover:text-c-on-error"}
|
||||||
|
onclick={() => props.remove(props.dni)}
|
||||||
>
|
>
|
||||||
<i class="ph ph-x"></i>
|
<i class="ph ph-x"></i>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="border-l"></div>
|
<div class="border-l font-mono">
|
||||||
|
<Switch>
|
||||||
|
<Match when={certStatus() === Status.Loading}>
|
||||||
|
<p>Loading...</p>
|
||||||
|
</Match>
|
||||||
|
<Match when={certStatus() === Status.Ok}>
|
||||||
|
<CertArray array={certificates()} />
|
||||||
|
</Match>
|
||||||
|
<Match when={certStatus() === Status.Error}>
|
||||||
|
<p class="text-c-error">Error loading certificates.</p>
|
||||||
|
</Match>
|
||||||
|
</Switch>
|
||||||
|
</div>
|
||||||
</Match>
|
</Match>
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
@ -113,3 +146,31 @@ export function DniEntry(props: {dni: string}) {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function CertArray(props: {array: Array<RegisterReturn>}) {
|
||||||
|
const filtered = createMemo(() => {
|
||||||
|
const nowMs = Date.now();
|
||||||
|
return props.array.filter((cert) => {
|
||||||
|
const date = new Date(cert.fecha_inscripcion);
|
||||||
|
const ms = date.getTime();
|
||||||
|
|
||||||
|
const difference = nowMs - ms;
|
||||||
|
|
||||||
|
return difference < (1000 * 60 * 60 * 24 * 366);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class="font-mono">
|
||||||
|
[
|
||||||
|
<For each={filtered()}>
|
||||||
|
{(cert) => (
|
||||||
|
<span class="mr-4">
|
||||||
|
{cert.curso_nombre} {cert.fecha_inscripcion}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</For>
|
||||||
|
]
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,10 +1,16 @@
|
|||||||
import { For } from "solid-js";
|
import { For, createSignal, onMount } from "solid-js";
|
||||||
import { DniEntry } from "./DniEntry";
|
import { DniEntry } from "./DniEntry";
|
||||||
|
|
||||||
export function DniGroup(props: {group: string, index: number}) {
|
export function DniGroup(props: {group: string, index: number}) {
|
||||||
const dnis = () => [...props.group.matchAll(/\d+/g)];
|
const [dnis, setDnis] = createSignal<Array<string>>([]);
|
||||||
|
|
||||||
console.log("Loading group...");
|
onMount(() => {
|
||||||
|
setDnis([...props.group.matchAll(/\d+/g)].map((x) => x.toString()));
|
||||||
|
});
|
||||||
|
|
||||||
|
const removeDni = (dni: string) => {
|
||||||
|
setDnis((prev) => prev.filter((x) => x !== dni));
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class=" grid-cols-[53rem_auto] gap-2 my-8">
|
<div class=" grid-cols-[53rem_auto] gap-2 my-8">
|
||||||
@ -19,7 +25,7 @@ export function DniGroup(props: {group: string, index: number}) {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<For each={dnis()}>
|
<For each={dnis()}>
|
||||||
{(dni) => <DniEntry dni={dni.toString()} />}
|
{(dni) => <DniEntry dni={dni} remove={removeDni} />}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user