@@ -0,0 +1,92 @@
|
||||
import { router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { controlClass } from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import type { RegistryPerson } from '@/pages/people/registry';
|
||||
|
||||
export type RegistryChoice = {
|
||||
ready: boolean;
|
||||
canCreate: boolean;
|
||||
search: string;
|
||||
items: RegistryPerson[];
|
||||
};
|
||||
|
||||
export function PeopleRegistryChoice({
|
||||
processId,
|
||||
data,
|
||||
selected,
|
||||
choose,
|
||||
}: {
|
||||
processId: number;
|
||||
data: RegistryChoice;
|
||||
selected: string;
|
||||
choose: (person: RegistryPerson | null) => void;
|
||||
}) {
|
||||
const [search, setSearch] = useState(data.search);
|
||||
function lookup() {
|
||||
router.get(
|
||||
`/pessoas/${processId}`,
|
||||
{ cadastro: search },
|
||||
{ only: ['registry'], preserveState: true, preserveScroll: true },
|
||||
);
|
||||
}
|
||||
return (
|
||||
<fieldset className="space-y-3 rounded-lg border p-4">
|
||||
<legend>Reutilizar pessoa do cadastro</legend>
|
||||
<p className="text-sm">
|
||||
Pesquise pelo menos dois caracteres. A candidatura conserva a
|
||||
versão seleccionada, mesmo que o cadastro mude depois.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-2">
|
||||
<input
|
||||
className={controlClass}
|
||||
aria-label="Pesquisar pessoa no cadastro"
|
||||
value={search}
|
||||
maxLength={100}
|
||||
onChange={(event) => setSearch(event.target.value)}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
lookup();
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button type="button" variant="outline" onClick={lookup}>
|
||||
Pesquisar cadastro
|
||||
</Button>
|
||||
</div>
|
||||
<select
|
||||
className={controlClass}
|
||||
aria-label="Pessoa do cadastro"
|
||||
value={selected}
|
||||
onChange={(event) =>
|
||||
choose(
|
||||
data.items.find(
|
||||
(item) => String(item.id) === event.target.value,
|
||||
) ?? null,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Registar pessoa nova</option>
|
||||
{selected &&
|
||||
!data.items.some(
|
||||
(item) => String(item.id) === selected,
|
||||
) && (
|
||||
<option value={selected}>
|
||||
Pessoa seleccionada anteriormente
|
||||
</option>
|
||||
)}
|
||||
{data.items.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name} · {item.reference} · v{item.version}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{data.search.length >= 2 && !data.items.length && (
|
||||
<p className="text-sm">
|
||||
Sem registos disponíveis neste âmbito.
|
||||
</p>
|
||||
)}
|
||||
</fieldset>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user