@@ -0,0 +1,140 @@
|
||||
import { Head, Link, useForm } from '@inertiajs/react';
|
||||
import {
|
||||
FormErrors,
|
||||
PageTitle,
|
||||
Panel,
|
||||
controlClass,
|
||||
} from '@/components/procurement';
|
||||
import { Button } from '@/components/ui/button';
|
||||
|
||||
type Group = {
|
||||
key: string;
|
||||
title: string;
|
||||
records: {
|
||||
total: number;
|
||||
current_page: number;
|
||||
last_page: number;
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
data: { id: number; title: string; detail: string; href: string }[];
|
||||
};
|
||||
};
|
||||
const statuses: Record<string, string> = {
|
||||
draft: 'Rascunho',
|
||||
pending: 'Pendente',
|
||||
approved: 'Aprovada',
|
||||
rejected: 'Rejeitada',
|
||||
cancelled: 'Cancelada',
|
||||
issued: 'Emitida',
|
||||
active: 'Activo',
|
||||
inactive: 'Inactivo',
|
||||
};
|
||||
export default function ProcurementSearch({
|
||||
term,
|
||||
groups,
|
||||
}: {
|
||||
term: string;
|
||||
groups: Group[];
|
||||
}) {
|
||||
const form = useForm({ q: term });
|
||||
return (
|
||||
<>
|
||||
<Head title="Pesquisar processos" />
|
||||
<div className="mx-auto grid w-full max-w-7xl min-w-0 gap-6 p-5 lg:p-8">
|
||||
<PageTitle
|
||||
eyebrow="Compras"
|
||||
title="Pesquisar processos"
|
||||
description="Procure processos e cadastros de Compras a partir de um único local, dentro do seu acesso actual."
|
||||
/>
|
||||
<Panel
|
||||
title="Pesquisa transversal de Compras"
|
||||
description="Pesquise requisições, ordens, fornecedores, recepções, equipamentos, artigos e armazéns por referência, necessidade, nome, código ou NUIT. Esta entrega ainda não pesquisa Pessoas, facturas, conteúdo de anexos ou arquivos externos."
|
||||
>
|
||||
<form
|
||||
className="flex flex-wrap items-end gap-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.get('/compras/pesquisa', {
|
||||
preserveState: true,
|
||||
});
|
||||
}}
|
||||
>
|
||||
<label
|
||||
className="grid min-w-0 flex-1 gap-2"
|
||||
htmlFor="procurement-search"
|
||||
>
|
||||
Texto a procurar
|
||||
<input
|
||||
className={controlClass}
|
||||
id="procurement-search"
|
||||
type="search"
|
||||
minLength={2}
|
||||
maxLength={100}
|
||||
value={form.data.q}
|
||||
onChange={(e) =>
|
||||
form.setData('q', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<Button disabled={form.processing}>Pesquisar</Button>
|
||||
</form>
|
||||
<FormErrors errors={form.errors} />
|
||||
</Panel>
|
||||
{term.trim().length < 2 && (
|
||||
<p role="status">
|
||||
Introduza pelo menos dois caracteres para pesquisar.
|
||||
</p>
|
||||
)}
|
||||
{groups.map((group) => (
|
||||
<Panel
|
||||
key={group.key}
|
||||
title={`${group.title} (${group.records.total})`}
|
||||
>
|
||||
{group.records.data.length === 0 ? (
|
||||
<p>Nenhum resultado no seu âmbito de acesso.</p>
|
||||
) : (
|
||||
<ul className="divide-y">
|
||||
{group.records.data.map((record) => (
|
||||
<li
|
||||
key={record.id}
|
||||
className="flex min-w-0 flex-wrap justify-between gap-3 py-3"
|
||||
>
|
||||
<Link
|
||||
className="min-w-0 font-medium break-words underline"
|
||||
href={record.href}
|
||||
>
|
||||
{record.title}
|
||||
</Link>
|
||||
<span>
|
||||
{statuses[record.detail] ??
|
||||
record.detail}
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<nav
|
||||
aria-label={`Páginas de ${group.title}`}
|
||||
className="mt-4 flex flex-wrap items-center gap-4"
|
||||
>
|
||||
<span>
|
||||
Página {group.records.current_page} de{' '}
|
||||
{group.records.last_page}
|
||||
</span>
|
||||
{group.records.prev_page_url && (
|
||||
<Link href={group.records.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{group.records.next_page_url && (
|
||||
<Link href={group.records.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Panel>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user