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

This commit is contained in:
2026-11-28 07:11:35 +02:00
parent d58b75c87a
commit eb32c74c56
202 changed files with 17463 additions and 1526 deletions
+76 -61
View File
@@ -1,5 +1,8 @@
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { hasPreparationChanges } from '@/lib/requisition-history';
import type { GeographyDescription } from '@/components/administrative-location';
import { Head, Link, useForm } from '@inertiajs/react';
import { Head, Link, router, useForm } from '@inertiajs/react';
import { Download, FileLock2, Pencil, Upload } from 'lucide-react';
import { useRef } from 'react';
import {
@@ -48,7 +51,6 @@ export default function SupplierShow({
file: null,
document_type: 'license',
});
const review = useForm({ status: 'active', comment: '' });
const fileInput = useRef<HTMLInputElement>(null);
return (
<>
@@ -268,65 +270,7 @@ export default function SupplierShow({
title="Validação independente por Finanças"
description="Confira os dados e os documentos actuais antes de decidir."
>
<form
className="space-y-4"
onSubmit={(e) => {
e.preventDefault();
review.transform((data) => ({
...data,
version: supplier.version,
}));
review.post(
`/fornecedores/${supplier.id}/validar`,
{
preserveScroll: true,
onSuccess: () => review.reset(),
},
);
}}
>
<FormErrors errors={review.errors} />
<div className="space-y-2">
<Label htmlFor="review-result">Resultado</Label>
<select
id="review-result"
className={controlClass}
value={review.data.status}
onChange={(e) =>
review.setData('status', e.target.value)
}
>
<option value="active">
Activar fornecedor
</option>
<option value="suspended">
Suspender fornecedor
</option>
</select>
</div>
<div className="space-y-2">
<Label htmlFor="review-reason">
Fundamento da decisão
</Label>
<textarea
id="review-reason"
className={`${controlClass} h-24 py-2`}
required
minLength={10}
maxLength={2000}
value={review.data.comment}
onChange={(e) =>
review.setData(
'comment',
e.target.value,
)
}
/>
</div>
<Button disabled={review.processing}>
Registar decisão
</Button>
</form>
<SupplierReview supplier={supplier} />
</Panel>
)}
</div>
@@ -339,3 +283,74 @@ SupplierShow.layout = {
{ title: 'Ficha e documentos', href: '#' },
],
};
function SupplierReview({ supplier }: { supplier: Supplier }) {
const identity = useProcurementPreparationIdentity(
`supplier-review:${supplier.id}:${supplier.version}`,
);
return (
<ReviewFields key={identity} supplier={supplier} identity={identity} />
);
}
function ReviewFields({
supplier,
identity,
}: {
supplier: Supplier;
identity: string;
}) {
const initial = { status: 'active', comment: '' };
const review = useForm(identity, initial);
const dirty = hasPreparationChanges(initial, review.data);
const ref = usePreparationDirty(dirty);
return (
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="space-y-4"
onSubmit={(e) => {
e.preventDefault();
review.transform((data) => ({
...data,
version: supplier.version,
}));
review.post(`/fornecedores/${supplier.id}/validar`, {
preserveScroll: true,
onSuccess: () => {
review.setData(initial);
review.clearErrors();
router.remember(initial, `${identity}:data`);
router.remember({}, `${identity}:errors`);
},
});
}}
>
<FormErrors errors={review.errors} />
<div className="space-y-2">
<Label htmlFor="review-result">Resultado</Label>
<select
id="review-result"
className={controlClass}
value={review.data.status}
onChange={(e) => review.setData('status', e.target.value)}
>
<option value="active">Activar fornecedor</option>
<option value="suspended">Suspender fornecedor</option>
</select>
</div>
<div className="space-y-2">
<Label htmlFor="review-reason">Fundamento da decisão</Label>
<textarea
id="review-reason"
className={`${controlClass} h-24 py-2`}
required
minLength={10}
maxLength={2000}
value={review.data.comment}
onChange={(e) => review.setData('comment', e.target.value)}
/>
</div>
<Button disabled={review.processing}>Registar decisão</Button>
</form>
);
}