import { createEffect, createSignal, Show } from "solid-js"; import { JSX } from "solid-js/jsx-runtime"; // import { Person } from "../../types/Person"; // import { RegisterPerson } from "./Search/RegisterPerson"; import QR from "qrcode"; import { CopyIcon } from "../icons/CopyIcon"; import { MagnifyingGlassIcon } from "../icons/MagnifyingGlassIcon"; import { XIcon } from "../icons/XIcon"; type HTMLEventFn = JSX.EventHandlerUnion; type HTMLButtonEvent = JSX.EventHandlerUnion; // eslint-disable-next-line @typescript-eslint/no-explicit-any type Person = any; /* Form that retrieves a user from the DB given an ID */ export function Search(props: {setPerson: (p: Person | null) => void}) { const [dni, setDni] = createSignal(""); const [loading, setLoading] = createSignal(false); const [error, setError] = createSignal(""); const [warning, setWarning] = createSignal(""); const [qrBase64, setQrBase64] = createSignal(null); const [persona, setPersona] = createSignal(null); // Update QR createEffect(() => { if (dni() !== "") { // Old URL: https://www.eegsac.com/alumnoscertificados.php?DNI=${dni()} // New URL: https://eegsac.com/certificado/${dni()} QR.toDataURL(`https://eegsac.com/certificado/${dni()}`, {margin: 1}, (err, res) => { if (err) { console.error("Error creating QR code"); return; } setQrBase64(res); }); } }); /* Get the user data from the DB */ const searchDNI: HTMLEventFn = (ev) => { ev.preventDefault(); search(); }; const search = async() => { setLoading(true); setError(""); setWarning(""); try { const response = await fetch(`/person/${dni()}`); const body = await response.json(); if (response.ok) { setPersona(body); props.setPerson(body); } else if (response.status === 404) { console.error(body); setWarning("Persona no encontrada. Se debe insertar manualmente sus datos."); props.setPerson(null); } else { setError(body); } } catch (e) { setError(JSON.stringify(e)); } setLoading(false); }; const nombresYApellidos = () => { const p = persona(); if (p === null) { return ""; } return `${p.nombres} ${p.apellidoPaterno} ${p.apellidoMaterno}`; }; const apellidosYNombres = () => { const p = persona(); if (p === null) { return ""; } return `${p.apellidoPaterno} ${p.apellidoMaterno} ${p.nombres}`; }; const apellidos = () => { const p = persona(); if (p === null) { return ""; } return `${p.apellidoPaterno} ${p.apellidoMaterno}`; }; const nombres = () => { const p = persona(); if (p === null) { return ""; } return p.nombres; }; return (

Error:
{error()}


  Nombres y Apellidos   Apellidos y Nombres
  Apellidos   Nombres
{/* */}
); } function InputBox(props: { loading: boolean, dni: string, setDni: (v: string) => void, }) { const inputElement = ( props.setDni(e.target.value)} disabled={props.loading} /> ); const copyToClipboard: HTMLButtonEvent = (ev) => { ev.preventDefault(); if (props.dni.length === 8) { navigator.clipboard.writeText(props.dni); } }; const clearDni: HTMLButtonEvent = (ev) => { ev.preventDefault(); props.setDni(""); (inputElement as HTMLInputElement).focus(); }; return (
{inputElement}
); } function MaterialLabel(props: {text: string | null, resource: string}) { const copyToClipboard: HTMLButtonEvent = (ev) => { ev.preventDefault(); if (props.text !== null) { navigator.clipboard.writeText(props.text); } }; return (
{props.text ?? ""}  
); } function CopyButton(props: {copyText: string, children: Array | JSX.Element}) { const [successAnimation, setSuccessAnimation] = createSignal(false); const onclick = () => { if (props.copyText !== "") { navigator.clipboard.writeText(props.copyText); setSuccessAnimation(true); setTimeout(() => setSuccessAnimation(false), 500); } }; return ( ); }