249 lines
9.5 KiB
TypeScript
249 lines
9.5 KiB
TypeScript
import { Head, Link, useForm } from '@inertiajs/react';
|
|
import {
|
|
PageTitle,
|
|
Panel,
|
|
FormErrors,
|
|
controlClass,
|
|
} from '@/components/procurement';
|
|
import { Button } from '@/components/ui/button';
|
|
|
|
export type RegistryPerson = {
|
|
id: number;
|
|
name: string;
|
|
reference: string;
|
|
profile_summary: string;
|
|
active: boolean;
|
|
version: number;
|
|
canEdit: boolean;
|
|
};
|
|
|
|
function PersonForm({ person }: { person?: RegistryPerson }) {
|
|
const form = useForm({
|
|
operation_key: crypto.randomUUID(),
|
|
version: person?.version ?? 1,
|
|
name: person?.name ?? '',
|
|
reference: person?.reference ?? '',
|
|
profile_summary: person?.profile_summary ?? '',
|
|
active: person?.active ?? true,
|
|
reason: '',
|
|
});
|
|
return (
|
|
<form
|
|
className="space-y-3"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
form.post(`/pessoas/cadastro${person ? `/${person.id}` : ''}`, {
|
|
preserveScroll: true,
|
|
onSuccess: () => {
|
|
if (!person) {
|
|
form.reset();
|
|
form.setData('operation_key', crypto.randomUUID());
|
|
}
|
|
},
|
|
});
|
|
}}
|
|
>
|
|
<FormErrors errors={form.errors} />
|
|
<label className="grid gap-1">
|
|
Nome
|
|
<input
|
|
className={controlClass}
|
|
required
|
|
minLength={3}
|
|
maxLength={200}
|
|
value={form.data.name}
|
|
onChange={(event) =>
|
|
form.setData('name', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="grid gap-1">
|
|
Referência do cadastro
|
|
{!person && ' (opcional; gerada se vazia)'}
|
|
<input
|
|
className={controlClass}
|
|
maxLength={120}
|
|
required={!!person}
|
|
value={form.data.reference}
|
|
onChange={(event) =>
|
|
form.setData('reference', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="grid gap-1">
|
|
Resumo do perfil reutilizável
|
|
<textarea
|
|
className={controlClass}
|
|
required
|
|
minLength={10}
|
|
maxLength={5000}
|
|
value={form.data.profile_summary}
|
|
onChange={(event) =>
|
|
form.setData('profile_summary', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
{person && (
|
|
<label className="flex items-center gap-2">
|
|
<input
|
|
type="checkbox"
|
|
checked={form.data.active}
|
|
onChange={(event) =>
|
|
form.setData('active', event.target.checked)
|
|
}
|
|
/>
|
|
Disponível para novas candidaturas
|
|
</label>
|
|
)}
|
|
<label className="grid gap-1">
|
|
Motivo
|
|
<textarea
|
|
className={controlClass}
|
|
required
|
|
minLength={10}
|
|
maxLength={4000}
|
|
value={form.data.reason}
|
|
onChange={(event) =>
|
|
form.setData('reason', event.target.value)
|
|
}
|
|
/>
|
|
</label>
|
|
<Button disabled={form.processing}>
|
|
{person ? 'Guardar nova versão' : 'Registar pessoa'}
|
|
</Button>
|
|
</form>
|
|
);
|
|
}
|
|
|
|
export default function PeopleRegistry({
|
|
ready,
|
|
canCreate,
|
|
records,
|
|
filters,
|
|
}: {
|
|
ready: boolean;
|
|
canCreate: boolean;
|
|
records: {
|
|
data: RegistryPerson[];
|
|
total: number;
|
|
prev_page_url: string | null;
|
|
next_page_url: string | null;
|
|
} | null;
|
|
filters: { search?: string; status?: string };
|
|
}) {
|
|
const search = useForm({
|
|
search: filters.search ?? '',
|
|
status: filters.status ?? 'active',
|
|
});
|
|
return (
|
|
<>
|
|
<Head title="Cadastro de pessoas" />
|
|
<div className="mx-auto max-w-5xl space-y-6 p-5 lg:p-8">
|
|
<PageTitle
|
|
eyebrow="Pessoas e contratações"
|
|
title="Cadastro reutilizável de pessoas"
|
|
description="Registe o perfil uma vez e seleccione-o nas candidaturas seguintes. Cada processo conserva a versão utilizada."
|
|
/>
|
|
<p className="text-sm">
|
|
São apresentados os seus registos e o cadastro partilhado
|
|
que a empresa o autorizou a consultar. Actualizar ou
|
|
arquivar não altera candidaturas e decisões anteriores.
|
|
Nomes iguais não são fundidos automaticamente.
|
|
</p>
|
|
{!ready ? (
|
|
<Panel title="Instalação pendente">
|
|
<p>
|
|
O cadastro ainda não foi instalado neste ambiente.
|
|
</p>
|
|
</Panel>
|
|
) : (
|
|
<>
|
|
<Panel title="Pesquisar cadastro">
|
|
<form
|
|
className="flex flex-wrap gap-3"
|
|
onSubmit={(event) => {
|
|
event.preventDefault();
|
|
search.get('/pessoas/cadastro', {
|
|
preserveState: true,
|
|
});
|
|
}}
|
|
>
|
|
<input
|
|
aria-label="Nome ou referência"
|
|
className={controlClass}
|
|
maxLength={100}
|
|
value={search.data.search}
|
|
onChange={(event) =>
|
|
search.setData(
|
|
'search',
|
|
event.target.value,
|
|
)
|
|
}
|
|
/>
|
|
<select
|
|
aria-label="Estado"
|
|
className={controlClass}
|
|
value={search.data.status}
|
|
onChange={(event) =>
|
|
search.setData(
|
|
'status',
|
|
event.target.value,
|
|
)
|
|
}
|
|
>
|
|
<option value="active">Disponíveis</option>
|
|
<option value="archived">Arquivados</option>
|
|
<option value="all">Todos</option>
|
|
</select>
|
|
<Button>Pesquisar</Button>
|
|
</form>
|
|
</Panel>
|
|
{records?.data.map((person) => (
|
|
<Panel
|
|
key={`${person.id}-${person.version}`}
|
|
title={`${person.name} · versão ${person.version}`}
|
|
>
|
|
<p className="mb-4 text-sm break-all">
|
|
{person.reference} ·{' '}
|
|
{person.active ? 'Disponível' : 'Arquivado'}
|
|
</p>
|
|
{person.canEdit ? (
|
|
<PersonForm person={person} />
|
|
) : (
|
|
<p className="whitespace-pre-wrap">
|
|
{person.profile_summary}
|
|
</p>
|
|
)}
|
|
</Panel>
|
|
))}
|
|
{!records?.total && <p>Sem pessoas neste âmbito.</p>}
|
|
<div className="flex gap-4">
|
|
{records?.prev_page_url && (
|
|
<Link
|
|
className="underline"
|
|
href={records.prev_page_url}
|
|
>
|
|
Anterior
|
|
</Link>
|
|
)}
|
|
{records?.next_page_url && (
|
|
<Link
|
|
className="underline"
|
|
href={records.next_page_url}
|
|
>
|
|
Seguinte
|
|
</Link>
|
|
)}
|
|
</div>
|
|
{canCreate && (
|
|
<Panel title="Nova pessoa">
|
|
<PersonForm />
|
|
</Panel>
|
|
)}
|
|
</>
|
|
)}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|