@@ -1,7 +1,7 @@
|
||||
import { Link, router, useForm, usePage, useRemember } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { FormErrors, Panel, controlClass } from '@/components/procurement';
|
||||
import { usePreparationDirty } from '@/hooks/use-preparation-dirty';
|
||||
|
||||
type SavedSearch = {
|
||||
id: number;
|
||||
@@ -21,24 +21,6 @@ export type SavedSearches = {
|
||||
};
|
||||
};
|
||||
|
||||
function usePrivatePreparation(dirty: boolean) {
|
||||
const ref = useRef<HTMLFormElement>(null);
|
||||
useEffect(() => {
|
||||
const form = ref.current;
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', { detail: { form, dirty } }),
|
||||
);
|
||||
return () => {
|
||||
window.dispatchEvent(
|
||||
new CustomEvent('sgc:context-dirty', {
|
||||
detail: { form, dirty: false },
|
||||
}),
|
||||
);
|
||||
};
|
||||
}, [dirty]);
|
||||
return ref;
|
||||
}
|
||||
|
||||
function SavedSearchRow({
|
||||
row,
|
||||
term,
|
||||
@@ -58,7 +40,7 @@ function SavedSearchRow({
|
||||
q: term,
|
||||
});
|
||||
const action = useForm({ version: row.version, q: term });
|
||||
const ref = usePrivatePreparation(editing && edit.isDirty);
|
||||
const ref = usePreparationDirty(editing && edit.isDirty);
|
||||
const endpoint = `/compras/pesquisas-guardadas/${row.id}`;
|
||||
return (
|
||||
<li className="grid min-w-0 grid-cols-1 gap-3 border-b py-4 last:border-0">
|
||||
@@ -185,7 +167,7 @@ export function SavedProcurementSearches({
|
||||
`saved-search:${actor?.tenant_id ?? 'none'}:${actor?.id ?? 'none'}:${term}`,
|
||||
{ name: '', term, q: term },
|
||||
);
|
||||
const ref = usePrivatePreparation(create.data.name !== '');
|
||||
const ref = usePreparationDirty(create.data.name !== '');
|
||||
return (
|
||||
<Panel title="As minhas pesquisas guardadas">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
|
||||
Reference in New Issue
Block a user