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 {
|
import {
|
||||||
saveProductDraft,
|
|
||||||
clearProductDraft,
|
clearProductDraft,
|
||||||
|
saveProductDraft,
|
||||||
type ProductDraftData,
|
type ProductDraftData,
|
||||||
} from '@/lib/product-draft';
|
} from '@/lib/product-draft';
|
||||||
|
import { router } from '@inertiajs/react';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
type DraftType = 'create' | 'edit';
|
type DraftType = 'create' | 'edit';
|
||||||
|
|
||||||
@ -21,9 +21,19 @@ export function useProductDraftSave(
|
|||||||
const submittedRef = useRef(false);
|
const submittedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return router.on('before', () => {
|
const offBefore = router.on('before', (event) => {
|
||||||
submittedRef.current = true;
|
if (event.detail.visit.method !== 'get') {
|
||||||
|
submittedRef.current = true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
const offError = router.on('error', () => {
|
||||||
|
submittedRef.current = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
offBefore();
|
||||||
|
offError();
|
||||||
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
|
||||||
import { router } from '@inertiajs/react';
|
|
||||||
import {
|
import {
|
||||||
saveRawMaterialDraft,
|
|
||||||
clearRawMaterialDraft,
|
clearRawMaterialDraft,
|
||||||
|
saveRawMaterialDraft,
|
||||||
type RawMaterialDraftData,
|
type RawMaterialDraftData,
|
||||||
} from '@/lib/raw-material-draft';
|
} from '@/lib/raw-material-draft';
|
||||||
|
import { router } from '@inertiajs/react';
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
type DraftType = 'create' | 'edit';
|
type DraftType = 'create' | 'edit';
|
||||||
|
|
||||||
@ -21,11 +21,20 @@ export function useRawMaterialDraftSave(
|
|||||||
const submittedRef = useRef(false);
|
const submittedRef = useRef(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return router.on('before', () => {
|
const offBefore = router.on('before', (event) => {
|
||||||
submittedRef.current = true;
|
if (event.detail.visit.method !== 'get') {
|
||||||
|
submittedRef.current = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const offError = router.on('error', () => {
|
||||||
|
submittedRef.current = false;
|
||||||
});
|
});
|
||||||
}, []);
|
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
offBefore();
|
||||||
|
offError();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (timeoutRef.current) {
|
if (timeoutRef.current) {
|
||||||
clearTimeout(timeoutRef.current);
|
clearTimeout(timeoutRef.current);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user