commit compras1 2911
tests / ci (push) Waiting to run

This commit is contained in:
2026-11-29 05:28:30 +02:00
parent 1ddabbbdcc
commit 448948a487
137 changed files with 9481 additions and 1926 deletions
+3 -1
View File
@@ -6,7 +6,9 @@ export function InventoryNotice() {
return (
<div className="rounded-xl border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-100">
Ambiente de desenvolvimento. Não autoriza compras reais.{' '}
<strong>O orçamento ainda não é validado.</strong>
<strong>
Esta operação física não certifica a validação orçamental.
</strong>
</div>
);
}
@@ -0,0 +1,60 @@
import { Link } from '@inertiajs/react';
export type RelatedProcess = { id: number; number: string; href: string };
/** Links supplied by the native page; the server retains authority over every destination. */
export function OrderDocumentLinks({
receiptsHref = null,
financialDocumentsHref = null,
relatedProcesses = [],
}: {
receiptsHref?: string | null;
financialDocumentsHref?: string | null;
relatedProcesses?: RelatedProcess[];
}) {
if (
!receiptsHref &&
!financialDocumentsHref &&
relatedProcesses.length === 0
)
return null;
return (
<nav
aria-label="Documentos relacionados da ordem"
className="rounded-xl border bg-card p-4"
>
<ul className="flex flex-wrap gap-x-6 gap-y-3 text-sm font-medium">
{relatedProcesses.map((process) => (
<li key={process.id}>
<Link
className="underline underline-offset-4"
href={process.href}
>
Processo {process.number}
</Link>
</li>
))}
{receiptsHref && (
<li>
<Link
className="underline underline-offset-4"
href={receiptsHref}
>
Recepções, qualidade e quantidades pendentes
</Link>
</li>
)}
{financialDocumentsHref && (
<li>
<Link
className="underline underline-offset-4"
href={financialDocumentsHref}
>
Facturas e pagamentos desta ordem
</Link>
</li>
)}
</ul>
</nav>
);
}
@@ -0,0 +1,88 @@
import { Link } from '@inertiajs/react';
import type { ProcurementGroup } from '@/lib/procurement-navigation';
export function ProcurementMenuResults({
groups,
dashboard,
onNavigate,
onEscape,
}: {
groups: ProcurementGroup[];
dashboard: boolean;
onNavigate: () => void;
onEscape: () => void;
}) {
const count = groups.reduce(
(total, group) => total + group.entries.length,
dashboard ? 1 : 0,
);
const linkClass =
'block rounded-md px-3 py-2 text-sm hover:bg-accent focus-visible:bg-accent focus-visible:outline-2 focus-visible:outline-ring';
return (
<section
id="sgc-menu-results"
aria-label="Resultados da pesquisa do menu"
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.preventDefault();
onEscape();
}
}}
className="absolute top-full left-0 z-50 mt-2 max-h-[min(65vh,32rem)] w-[min(36rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border bg-popover p-2 text-popover-foreground shadow-lg"
>
<p
role="status"
className="px-3 py-2 text-sm text-muted-foreground"
>
{count
? `${count} ${count === 1 ? 'opção disponível' : 'opções disponíveis'}.`
: 'Nenhuma opção encontrada. Tente outra palavra.'}
</p>
{dashboard && (
<Link
href="/dashboard"
className={linkClass}
onClick={onNavigate}
>
Painel inicial
</Link>
)}
{groups.map((group) => (
<div key={group.id}>
<h2 className="px-3 pt-3 pb-1 text-xs font-semibold text-muted-foreground">
{group.label}
</h2>
<ul>
{group.entries.map((entry) => (
<li key={entry.id}>
{entry.fullPage ? (
<a
href={entry.path}
className={linkClass}
onClick={onNavigate}
>
{entry.label}
<span className="block text-xs text-muted-foreground">
{entry.section ?? group.label}
</span>
</a>
) : (
<Link
href={entry.path}
className={linkClass}
onClick={onNavigate}
>
{entry.label}
<span className="block text-xs text-muted-foreground">
{entry.section ?? group.label}
</span>
</Link>
)}
</li>
))}
</ul>
</div>
))}
</section>
);
}
+10 -3
View File
@@ -124,8 +124,9 @@ export function Panel({
return (
<section
id={id}
tabIndex={id ? -1 : undefined}
aria-labelledby={headingId}
className="sgc-panel min-w-0 scroll-mt-24 rounded-xl border bg-card p-4 shadow-xs sm:p-5 print:rounded-none print:shadow-none"
className="sgc-panel min-w-0 scroll-mt-24 rounded-xl border bg-card p-4 shadow-xs sm:p-5 lg:scroll-mt-72 print:rounded-none print:shadow-none"
>
<h2
id={headingId}
@@ -160,14 +161,20 @@ export function Status({ value }: { value: string }) {
</Badge>
);
}
export function RequisitionTable({ rows }: { rows: Requisition[] }) {
export function RequisitionTable({
rows,
emptyDescription = 'Não existem pedidos disponíveis neste conjunto para o seu perfil.',
}: {
rows: Requisition[];
emptyDescription?: string;
}) {
if (!rows.length)
return (
<div className="py-12 text-center">
<ClipboardList className="mx-auto mb-3 size-9 text-muted-foreground/50" />
<p className="font-medium">Sem requisições para apresentar</p>
<p className="mt-1 text-sm text-muted-foreground">
Os pedidos de compra aparecem aqui depois de criados.
{emptyDescription}
</p>
</div>
);
@@ -1,7 +1,7 @@
import { Link, router, useForm, usePage, useRemember } from '@inertiajs/react';
import { useEffect, useRef } from 'react';
import { Button } from '@/components/ui/button';
import { FormErrors, Panel, controlClass } from '@/components/procurement';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
type SavedSearch = {
id: number;
@@ -21,24 +21,6 @@ export type SavedSearches = {
};
};
function usePrivatePreparation(dirty: boolean) {
const ref = useRef<HTMLFormElement>(null);
useEffect(() => {
const form = ref.current;
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', { detail: { form, dirty } }),
);
return () => {
window.dispatchEvent(
new CustomEvent('sgc:context-dirty', {
detail: { form, dirty: false },
}),
);
};
}, [dirty]);
return ref;
}
function SavedSearchRow({
row,
term,
@@ -58,7 +40,7 @@ function SavedSearchRow({
q: term,
});
const action = useForm({ version: row.version, q: term });
const ref = usePrivatePreparation(editing && edit.isDirty);
const ref = usePreparationDirty(editing && edit.isDirty);
const endpoint = `/compras/pesquisas-guardadas/${row.id}`;
return (
<li className="grid min-w-0 grid-cols-1 gap-3 border-b py-4 last:border-0">
@@ -185,7 +167,7 @@ export function SavedProcurementSearches({
`saved-search:${actor?.tenant_id ?? 'none'}:${actor?.id ?? 'none'}:${term}`,
{ name: '', term, q: term },
);
const ref = usePrivatePreparation(create.data.name !== '');
const ref = usePreparationDirty(create.data.name !== '');
return (
<Panel title="As minhas pesquisas guardadas">
<p className="text-sm text-muted-foreground">
+44 -41
View File
@@ -7,7 +7,7 @@ import {
Search,
X,
} from 'lucide-react';
import { Fragment, useEffect, useState } from 'react';
import { Fragment, useEffect, useRef, useState } from 'react';
import type { ReactNode } from 'react';
import { Button } from '@/components/ui/button';
import {
@@ -32,6 +32,12 @@ import {
import { roleLabels } from '@/types/procurement';
import type { WorkContextState } from '@/types/work-context';
import { WorkContextChange } from '@/components/work-context-change';
import { ProcurementMenuResults } from '@/components/procurement-menu-results';
import {
matchesMenuSearch,
normalizeMenuText,
searchProcurementMenu,
} from '@/lib/procurement-menu-search';
export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
const page = usePage();
@@ -41,6 +47,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
| undefined;
const [mobileOpen, setMobileOpen] = useState(false);
const [search, setSearch] = useState('');
const desktopSearch = useRef<HTMLInputElement>(null);
const [expanded, setExpanded] = useState<Record<string, boolean>>({});
const access = page.props.organizationAccess as {
active: boolean;
@@ -55,6 +62,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
page.props.orderCancellationAvailable === true,
page.props.operationalOrdersAvailable === true,
page.props.privateAuditAvailable === true,
page.props.capitalRegisterAvailable === true,
).flatMap((group) => group.entries.map((entry) => entry.id)),
);
const groups = procurementNavigation(
@@ -64,6 +72,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
page.props.orderCancellationAvailable === true,
page.props.operationalOrdersAvailable === true,
page.props.privateAuditAvailable === true,
page.props.capitalRegisterAvailable === true,
)
.map((group) => ({
...group,
@@ -91,28 +100,13 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
: { ...previous, [activeGroupId]: true },
);
}, [activeId, activeGroupId]);
const normalize = (text: string) =>
text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLocaleLowerCase('pt');
const normalize = normalizeMenuText;
const query = normalize(search.trim());
const visibleGroups = groups
.map((group) => ({
...group,
entries: group.entries.filter(
(entry) =>
!query ||
normalize(
group.label +
' ' +
(entry.section ?? '') +
' ' +
entry.label,
).includes(query),
),
}))
.filter((group) => group.entries.length);
const visibleGroups = searchProcurementMenu(groups, query);
const closeSearch = () => {
setSearch('');
desktopSearch.current?.focus();
};
const navigate = () => {
setMobileOpen(false);
setSearch('');
@@ -145,12 +139,22 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
aria-hidden="true"
/>
<input
ref={mobile ? undefined : desktopSearch}
type="search"
aria-label="Procurar no menu"
placeholder="Procurar no menu…"
value={search}
onChange={(event) => setSearch(event.target.value)}
className={`h-10 w-full rounded-lg border pr-9 pl-9 text-sm outline-none focus:border-red-400 focus:ring-2 focus:ring-red-400/20 ${mobile ? 'border-white/15 bg-white/5 text-white placeholder:text-slate-400' : 'border-border bg-background text-foreground'}`}
onKeyDown={(event) => {
if (event.key === 'Escape') {
event.preventDefault();
closeSearch();
}
}}
aria-controls={
!mobile && query ? 'sgc-menu-results' : undefined
}
className={`h-10 w-full rounded-lg border pr-9 pl-9 text-sm outline-none focus:border-red-400 focus:ring-2 focus:ring-red-400/20 [&::-webkit-search-cancel-button]:hidden ${mobile ? 'border-white/15 bg-white/5 text-white placeholder:text-slate-400' : 'border-border bg-background text-foreground'}`}
/>
{search && (
<button
@@ -162,6 +166,17 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
<X className="size-4" />
</button>
)}
{!mobile && query && (
<ProcurementMenuResults
groups={visibleGroups}
dashboard={matchesMenuSearch(
'Painel inicial Visão geral',
query,
)}
onNavigate={navigate}
onEscape={closeSearch}
/>
)}
</div>
);
const navigation = (
@@ -173,7 +188,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
ESPAÇO DE TRABALHO
</p>
{(!query ||
normalize('Painel inicial Visão geral').includes(query)) && (
matchesMenuSearch('Painel inicial Visão geral', query)) && (
<Link
href="/dashboard"
onClick={navigate}
@@ -273,12 +288,12 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
))}
{query &&
visibleGroups.length === 0 &&
!normalize('Painel inicial Visão geral').includes(query) && (
!matchesMenuSearch('Painel inicial Visão geral', query) && (
<p
role="status"
className="px-3 py-5 text-sm text-slate-400"
>
Nenhuma opção encontrada. Tenta outra palavra.
Nenhuma opção encontrada. Tente outra palavra.
</p>
)}
</nav>
@@ -359,10 +374,7 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
aria-label="Navegação principal horizontal"
className="flex min-w-0 flex-1 flex-wrap items-center gap-1 px-3 py-3"
>
{(!query ||
normalize(
'Painel inicial Visão geral',
).includes(query)) && (
{
<Link
href="/dashboard"
onClick={navigate}
@@ -379,8 +391,8 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
/>
Painel inicial
</Link>
)}
{visibleGroups.map((group) => (
}
{groups.map((group) => (
<DropdownMenu key={group.id}>
<DropdownMenuTrigger asChild>
<button
@@ -451,15 +463,6 @@ export function SgcWorkspaceShell({ children }: { children: ReactNode }) {
</DropdownMenuContent>
</DropdownMenu>
))}
{query &&
visibleGroups.length === 0 &&
!normalize(
'Painel inicial Visão geral',
).includes(query) && (
<p className="px-3 py-2 text-sm text-slate-400">
Nenhuma opção encontrada.
</p>
)}
</nav>
</div>
<div className="flex min-h-18 items-center justify-between gap-4 px-5 py-3 lg:px-8">
@@ -465,7 +465,10 @@ function ImprovementContent({
(m) => m.status !== 'closed' && m.due_on < data.today,
).length;
return (
<Panel title="Medidas de melhoria e acompanhamento">
<Panel
id="evaluation-improvements"
title="Medidas de melhoria e acompanhamento"
>
<div className="space-y-5">
<p className="text-sm text-muted-foreground">
Acompanhamento associado a esta revisão, consultado em{' '}
@@ -437,7 +437,7 @@ function ResponseContent({
};
const base = `/fornecedores/avaliacoes/${evaluationId}/contraditorios`;
return (
<Panel title="Contraditório do fornecedor">
<Panel id="evaluation-responses" title="Contraditório do fornecedor">
<div className="space-y-5">
<p className="text-sm text-muted-foreground">
Documentos e argumentos recebidos, registados pela equipa.
@@ -5,6 +5,7 @@ import { protectDepartures } from '@/lib/unsaved-navigation';
import {
connectedDirtyForms,
markPreparationDirty,
usesGenericPreparationTracking,
} from '@/lib/preparation-forms';
import {
Dialog,
@@ -31,7 +32,7 @@ export function WorkContextChange() {
!(event.detail.form instanceof HTMLFormElement)
)
return;
markPreparationDirty(event.detail.form, !!event.detail.dirty);
markPreparationDirty(event.detail.form, !!event.detail.dirty, true);
if (event.detail.dirty) dirty.current.add(event.detail.form);
else dirty.current.delete(event.detail.form);
};
@@ -42,7 +43,7 @@ export function WorkContextChange() {
input instanceof HTMLTextAreaElement ||
input instanceof HTMLSelectElement
) {
if (input.form) {
if (input.form && usesGenericPreparationTracking(input.form)) {
markPreparationDirty(input.form, true);
dirty.current.add(input.form);
}