@@ -1,5 +1,5 @@
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
import { Head, Link, useForm, useRemember } from '@inertiajs/react';
|
||||
import { useEffect, useRef, type RefObject } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
ActionBar,
|
||||
@@ -226,24 +226,6 @@ type DraftComponent = {
|
||||
values: string[];
|
||||
};
|
||||
|
||||
function useGuard(ref: RefObject<HTMLFormElement | null>, dirty: boolean) {
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: element, dirty },
|
||||
}),
|
||||
);
|
||||
return () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form: element, dirty: false },
|
||||
}),
|
||||
);
|
||||
};
|
||||
}, [ref, dirty]);
|
||||
}
|
||||
|
||||
function Pagination({
|
||||
page,
|
||||
}: {
|
||||
@@ -295,8 +277,7 @@ function DocumentForm({
|
||||
reason: '',
|
||||
file: null as File | null,
|
||||
}).dontRemember('file');
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useGuard(ref, form.isDirty);
|
||||
const ref = usePreparationDirty(form.isDirty);
|
||||
return (
|
||||
<Panel title="Registar documento adicional">
|
||||
<p className="mb-4">
|
||||
@@ -548,8 +529,7 @@ function CostPreparation(props: Props & { url: string; historyKey: string }) {
|
||||
})) ?? ([] as DraftComponent[]),
|
||||
reason: '',
|
||||
});
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useGuard(ref, form.isDirty);
|
||||
const ref = usePreparationDirty(form.isDirty);
|
||||
const selection = () => ({
|
||||
budget_id: form.data.budget_id,
|
||||
item_references: form.data.components
|
||||
@@ -1048,8 +1028,7 @@ function FinancialStage({
|
||||
reason: '',
|
||||
sources: [] as string[],
|
||||
});
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useGuard(ref, form.isDirty);
|
||||
const ref = usePreparationDirty(form.isDirty);
|
||||
if (!financialReady || !latest) return null;
|
||||
const current = latest.state === 'approved';
|
||||
const changed =
|
||||
@@ -1322,8 +1301,7 @@ export default function ImportCosts(props: Props) {
|
||||
operation_key: crypto.randomUUID(),
|
||||
reason: '',
|
||||
});
|
||||
const decisionRef = useRef<HTMLFormElement>(null);
|
||||
useGuard(decisionRef, decision.isDirty);
|
||||
const decisionRef = usePreparationDirty(decision.isDirty);
|
||||
return (
|
||||
<>
|
||||
<Head title="Custo de aterragem" />
|
||||
|
||||
Reference in New Issue
Block a user