[FE][Certs] Get registers from BE
This commit is contained in:
parent
81157d53de
commit
58c7d069f9
@ -1,30 +1,63 @@
|
|||||||
|
import { For, createEffect, createSignal } from "solid-js";
|
||||||
import { DownloadIcon } from "../../icons/DownloadIcon";
|
import { DownloadIcon } from "../../icons/DownloadIcon";
|
||||||
|
import { Person } from "../../types/Person";
|
||||||
import { Register } from "../../types/Register";
|
import { Register } from "../../types/Register";
|
||||||
|
|
||||||
export function Registers() {
|
export function Registers(props: {person: Person | null}) {
|
||||||
|
const [registers, setRegisters] = createSignal<Array<Register>>([]);
|
||||||
|
|
||||||
|
createEffect(async() => {
|
||||||
|
if (props.person === null) {
|
||||||
|
setRegisters([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const person = props.person;
|
||||||
|
|
||||||
|
const res = await fetch(`${import.meta.env.VITE_BACKEND_URL}/api/register/${person.person_dni}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setRegisters(data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="m-4 p-4 rounded-md">
|
<div class="m-4 p-4 rounded-md">
|
||||||
<h3 class="text-xl font-medium py-2">
|
<h3 class="text-xl font-medium py-2">
|
||||||
SUMA BERNAL, MAIKOL
|
{props.person?.person_names}
|
||||||
|
{props.person?.person_paternal_surname}
|
||||||
|
{props.person?.person_maternal_surname}
|
||||||
</h3>
|
</h3>
|
||||||
<div class="flex flex-wrap justify-start gap-2">
|
<div class="flex flex-wrap justify-start gap-2">
|
||||||
<RegisterEl />
|
<For each={registers()}>
|
||||||
<RegisterEl />
|
{(register) => <RegisterEl register={register} />}
|
||||||
<RegisterEl />
|
</For>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RegisterEl(props: {register: Register}) {
|
function RegisterEl(props: {register: Register}) {
|
||||||
|
|
||||||
|
const displayDate = () => {
|
||||||
|
const [, year, month, day] = /(\d{4})-(\d{2})-(\d{2})/.exec(props.register.register_display_date) ?? [];
|
||||||
|
return `${day}/${month}/${year}`;
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="inline-block w-[12rem] p-1 border border-c-outline rounded-md">
|
<div class="inline-block w-[12rem] p-1 border border-c-outline rounded-md">
|
||||||
<button class="rounded-full bg-c-primary-container hover:bg-c-primary transition-colors h-12 w-12">
|
<button class="rounded-full bg-c-primary-container hover:bg-c-primary transition-colors h-12 w-12">
|
||||||
<DownloadIcon fill="var(--c-on-primary-container)" />
|
<DownloadIcon fill="var(--c-on-primary-container)" />
|
||||||
</button>
|
</button>
|
||||||
<div class="inline-block h-12 w-32 pl-2 align-middle">
|
<div class="inline-block h-12 w-32 pl-2 align-middle">
|
||||||
<p class="font-bold">Matpel 2</p>
|
<p class="font-bold">
|
||||||
<p class="font-mono text-sm">12/08/2023 - 6486</p>
|
course_id: {props.register.register_course_id}
|
||||||
|
</p>
|
||||||
|
<p class="font-mono text-sm">
|
||||||
|
{displayDate()}
|
||||||
|
-
|
||||||
|
{props.register.register_code}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -34,6 +34,7 @@ export function Search(props: {setPerson: (p: Person | null) => void}) {
|
|||||||
} else {
|
} else {
|
||||||
setQrBase64(null);
|
setQrBase64(null);
|
||||||
setPerson(null);
|
setPerson(null);
|
||||||
|
props.setPerson(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
|
import { createSignal } from "solid-js";
|
||||||
import { NewRegister } from "./NewRegister";
|
import { NewRegister } from "./NewRegister";
|
||||||
import { Registers } from "./Registers";
|
import { Registers } from "./Registers";
|
||||||
import { Search } from "./Search";
|
import { Search } from "./Search";
|
||||||
|
import { Person } from "../types/Person";
|
||||||
|
|
||||||
export function Certs() {
|
export function Certs() {
|
||||||
|
const [person, setPerson] = createSignal<Person | null>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div class="grid grid-cols-[16rem_25rem_1fr]">
|
<div class="grid grid-cols-[16rem_25rem_1fr]">
|
||||||
<Search setPerson={() => {}} />
|
<Search setPerson={setPerson} />
|
||||||
<NewRegister personId={0} onSuccess={() => {}} />
|
<NewRegister personId={0} onSuccess={() => {}} />
|
||||||
<Registers />
|
<Registers person={person()} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user