refactor: reorder imports and enhance event handling in product and raw material draft hooks
This commit is contained in:
parent
3039396192
commit
75f821957d
@ -1,10 +1,10 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { router } from '@inertiajs/react';
|
||||
import {
|
||||
saveProductDraft,
|
||||
clearProductDraft,
|
||||
saveProductDraft,
|
||||
type ProductDraftData,
|
||||
} from '@/lib/product-draft';
|
||||
import { router } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
type DraftType = 'create' | 'edit';
|
||||
|
||||
@ -21,9 +21,19 @@ export function useProductDraftSave(
|
||||
const submittedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
return router.on('before', () => {
|
||||
submittedRef.current = true;
|
||||
const offBefore = router.on('before', (event) => {
|
||||
if (event.detail.visit.method !== 'get') {
|
||||
submittedRef.current = true;
|
||||
}
|
||||
});
|
||||
const offError = router.on('error', () => {
|
||||
submittedRef.current = false;
|
||||
});
|
||||
|
||||
return () => {
|
||||
offBefore();
|
||||
offError();
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import { router } from '@inertiajs/react';
|
||||
import {
|
||||
saveRawMaterialDraft,
|
||||
clearRawMaterialDraft,
|
||||
saveRawMaterialDraft,
|
||||
type RawMaterialDraftData,
|
||||
} from '@/lib/raw-material-draft';
|
||||
import { router } from '@inertiajs/react';
|
||||
import { useEffect, useRef } from 'react';
|
||||
|
||||
type DraftType = 'create' | 'edit';
|
||||
|
||||
@ -21,11 +21,20 @@ export function useRawMaterialDraftSave(
|
||||
const submittedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
return router.on('before', () => {
|
||||
submittedRef.current = true;
|
||||
const offBefore = router.on('before', (event) => {
|
||||
if (event.detail.visit.method !== 'get') {
|
||||
submittedRef.current = true;
|
||||
}
|
||||
});
|
||||
const offError = router.on('error', () => {
|
||||
submittedRef.current = false;
|
||||
});
|
||||
}, []);
|
||||
|
||||
return () => {
|
||||
offBefore();
|
||||
offError();
|
||||
};
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (timeoutRef.current) {
|
||||
clearTimeout(timeoutRef.current);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user