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
@@ -1,4 +1,7 @@
import { useForm } from '@inertiajs/react';
import { router, useForm } from '@inertiajs/react';
import { useProcurementPreparationIdentity } from '@/hooks/use-procurement-preparation-identity';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { hasPreparationChanges } from '@/lib/requisition-history';
import { FormErrors, Panel, controlClass } from '@/components/procurement';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
@@ -30,22 +33,37 @@ export function ExchangeSummary({ basis }: { basis: ExchangeBasis }) {
);
}
export function QuotationExchangePanel({
type Props = {
requisitionId: number;
processVersion?: number;
rates: ExchangeBasis[];
canRecord: boolean;
};
export function QuotationExchangePanel(props: Props) {
const identity = useProcurementPreparationIdentity(
`quotation-exchange:${props.requisitionId}:${props.processVersion ?? 0}:${props.canRecord}`,
);
return <ExchangeFields key={identity} {...props} identity={identity} />;
}
function ExchangeFields({
requisitionId,
rates,
canRecord,
}: {
requisitionId: number;
rates: ExchangeBasis[];
canRecord: boolean;
}) {
const form = useForm({
identity,
}: Props & { identity: string }) {
const initial = {
operation_id: crypto.randomUUID(),
currency: '',
rate: '',
quoted_on: '',
source: '',
});
};
const form = useForm(identity, initial);
const dirty = hasPreparationChanges(
{ ...initial, operation_id: '' },
{ ...form.data, operation_id: '' },
);
const ref = usePreparationDirty(dirty, canRecord);
return (
<Panel
title="Taxas de câmbio do processo"
@@ -68,6 +86,8 @@ export function QuotationExchangePanel({
)}
{canRecord && (
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="mt-5 space-y-4"
onSubmit={(event) => {
event.preventDefault();
@@ -76,11 +96,14 @@ export function QuotationExchangePanel({
{
preserveScroll: true,
onSuccess: () => {
form.reset();
form.setData(
'operation_id',
crypto.randomUUID(),
);
const next = {
...initial,
operation_id: crypto.randomUUID(),
};
form.setData(next);
form.clearErrors();
router.remember(next, `${identity}:data`);
router.remember({}, `${identity}:errors`);
},
},
);