@@ -1,5 +1,5 @@
|
||||
import { Head, Link, useForm, usePage } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { hasPreparationChanges } from '@/lib/requisition-history';
|
||||
import BudgetDistributionFields, {
|
||||
type BudgetDistributionOption,
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { money } from '@/types/procurement';
|
||||
|
||||
export default function Amendment({
|
||||
function AmendmentContent({
|
||||
order,
|
||||
options,
|
||||
planHash,
|
||||
@@ -58,15 +58,8 @@ export default function Amendment({
|
||||
`distribution-amendment:${actor?.tenant_id}:${actor?.id}:${order.id}:${planHash}`,
|
||||
initial,
|
||||
);
|
||||
const formElement = useRef<HTMLFormElement>(null);
|
||||
const dirty = hasPreparationChanges(initial, form.data);
|
||||
useEffect(() => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: formElement.current, dirty },
|
||||
}),
|
||||
);
|
||||
}, [dirty]);
|
||||
const formElement = usePreparationDirty(dirty);
|
||||
return (
|
||||
<>
|
||||
<Head title={`Reafectação · ${order.number}`} />
|
||||
@@ -85,6 +78,7 @@ export default function Amendment({
|
||||
<FormErrors errors={form.errors} />
|
||||
<form
|
||||
ref={formElement}
|
||||
data-preparation-dirty={dirty ? 'true' : 'false'}
|
||||
className="space-y-5"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
@@ -142,3 +136,15 @@ export default function Amendment({
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Amendment(
|
||||
props: Parameters<typeof AmendmentContent>[0],
|
||||
) {
|
||||
const actor = usePage().props.auth?.user;
|
||||
return (
|
||||
<AmendmentContent
|
||||
key={`distribution-amendment:${actor?.tenant_id}:${actor?.id}:${props.order.id}:${props.planHash}`}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user