Create registers in UI

This commit is contained in:
Araozu 2023-05-08 23:21:19 -05:00
parent f7b18b05f1
commit 44819da59d
4 changed files with 50 additions and 15 deletions

View File

@ -6,6 +6,8 @@ import { NewRegister } from "./components/NewRegister";
export function Certs() { export function Certs() {
const [person, setPerson] = createSignal<Person | null>(null); const [person, setPerson] = createSignal<Person | null>(null);
const [lastUpdate, setLastUpdate] = createSignal(0);
return ( return (
<div> <div>
<h1 <h1
@ -14,8 +16,11 @@ export function Certs() {
Registrar certificado Registrar certificado
</h1> </h1>
<Search setPerson={setPerson}/> <Search setPerson={setPerson}/>
<Registers person={person()} /> <Registers person={person()} lastUpdate={lastUpdate()} />
<NewRegister personId={person()?.id ?? -1} /> <NewRegister
personId={person()?.id ?? -1}
onSuccess={() => setLastUpdate((x) => x + 1)}
/>
</div> </div>
); );
} }

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,11 @@ import { createEffect, createMemo, createSignal, For, JSX, Show } 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 { isServer } from "solid-js/web";
export function SearchableSelect(props: {subjects: Array<CursoGIE>, onChange: (id: number | null) => void}) { export function SearchableSelect(props: {
subjects: Array<CursoGIE>,
onChange: (id: number | null) => void,
count: number
}) {
const [filter, setFilter] = createSignal(""); const [filter, setFilter] = createSignal("");
const [selected, setSelected] = createSignal<number | null>(null); const [selected, setSelected] = createSignal<number | null>(null);
const [inputValue, setInputValue] = createSignal(""); const [inputValue, setInputValue] = createSignal("");
@ -18,6 +22,15 @@ export function SearchableSelect(props: {subjects: Array<CursoGIE>, onChange: (i
props.onChange(selected()); props.onChange(selected());
}); });
createEffect(() => {
// Makes reactivity happen
console.log(props.count);
setFilter("");
setSelected(null);
setInputValue("");
});
const inputElement = ( const inputElement = (
<input <input
id="create-subject" id="create-subject"

View File

@ -2,13 +2,16 @@ import { Show, createEffect, createSignal, For } from "solid-js";
import { Person } from "../../types/Person"; import { Person } from "../../types/Person";
import { RegisterReturn } from "../../types/RegisterReturn"; import { RegisterReturn } from "../../types/RegisterReturn";
export function Registers(props: { person: Person | null }) { export function Registers(props: { person: Person | null, lastUpdate: number }) {
const [loading, setLoading] = createSignal(false); const [loading, setLoading] = createSignal(false);
const [registers, setRegisters] = createSignal<Array<RegisterReturn>>([]); const [registers, setRegisters] = createSignal<Array<RegisterReturn>>([]);
createEffect(() => { createEffect(() => {
const person = props.person; const person = props.person;
console.log(`Loading registers for ${person?.nombres}`); const lastUpdate = props.lastUpdate;
// This comment is important, it retrieves
// certificates from DB on any change
console.log(`Loading registers for ${person?.nombres} (update ${lastUpdate})`);
// Load certificates from DB // Load certificates from DB
loadCertificates(); loadCertificates();