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,21 +1,50 @@
import { useForm } from '@inertiajs/react';
import { router, useForm } from '@inertiajs/react';
import { useBudgetPreparationIdentity } from '@/hooks/use-budget-preparation-identity';
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
import { hasPreparationChanges } from '@/lib/requisition-history';
import { FormErrors, controlClass } from '@/components/procurement';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
export function ReinforcementProposal({ budgetId }: { budgetId: number }) {
const form = useForm({ reference: '', amount: '', reason: '' });
const identity = `${useBudgetPreparationIdentity()}:reinforcement:${budgetId}`;
return (
<ProposalFields
key={identity}
budgetId={budgetId}
identity={identity}
/>
);
}
function ProposalFields({
budgetId,
identity,
}: {
budgetId: number;
identity: string;
}) {
const initial = { reference: '', amount: '', reason: '' };
const form = useForm(identity, initial);
const dirty = hasPreparationChanges(initial, form.data);
const ref = usePreparationDirty(dirty);
return (
<details className="mt-4 rounded-lg border p-4">
<summary className="cursor-pointer font-semibold">
Propor reforço desta dotação
</summary>
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="mt-4 grid gap-3"
onSubmit={(e) => {
e.preventDefault();
form.post(`/orcamentos/${budgetId}/reforcos`, {
onSuccess: () => form.reset(),
onSuccess: () => {
form.setData(initial);
form.clearErrors();
router.remember(initial, `${identity}:data`);
router.remember({}, `${identity}:errors`);
},
});
}}
>
@@ -61,13 +90,29 @@ export function ReinforcementProposal({ budgetId }: { budgetId: number }) {
);
}
export function ReinforcementReview({ id }: { id: number }) {
const form = useForm({ decision: 'approved', reason: '' });
const identity = `${useBudgetPreparationIdentity()}:reinforcement-review:${id}`;
return <ReviewFields key={identity} id={id} identity={identity} />;
}
function ReviewFields({ id, identity }: { id: number; identity: string }) {
const initial = { decision: 'approved', reason: '' };
const form = useForm(identity, initial);
const dirty = hasPreparationChanges(initial, form.data);
const ref = usePreparationDirty(dirty);
return (
<form
ref={ref}
data-preparation-dirty={dirty ? 'true' : 'false'}
className="mt-4 grid gap-3"
onSubmit={(e) => {
e.preventDefault();
form.post(`/reforcos/${id}/decidir`);
form.post(`/reforcos/${id}/decidir`, {
onSuccess: () => {
form.setData(initial);
form.clearErrors();
router.remember(initial, `${identity}:data`);
router.remember({}, `${identity}:errors`);
},
});
}}
>
<FormErrors errors={form.errors} />