mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): sync draft WO# ref in effect for duplicate guard [SH-189]
This commit is contained in:
parent
f31a301dbf
commit
3cd8298c62
1 changed files with 10 additions and 2 deletions
|
|
@ -47,7 +47,10 @@ export function useNewWoWizardState({
|
|||
const [duplicateRow, setDuplicateRow] = useState<WorkOrderTableRow | null>(null);
|
||||
const [isCheckingDuplicate, setIsCheckingDuplicate] = useState(false);
|
||||
const draftWoNumberRef = useRef(draft.woNumber);
|
||||
draftWoNumberRef.current = draft.woNumber;
|
||||
|
||||
useEffect(() => {
|
||||
draftWoNumberRef.current = draft.woNumber;
|
||||
}, [draft.woNumber]);
|
||||
|
||||
const { data: apiLocations = [] } = useWorkOrderLocations();
|
||||
const { data: apiProblems = [] } = useDropdownOptionsByCategory("Problem");
|
||||
|
|
@ -135,10 +138,15 @@ export function useNewWoWizardState({
|
|||
};
|
||||
|
||||
const handleCreate = () => {
|
||||
const woNumberAtSubmit = draft.woNumber;
|
||||
void (async () => {
|
||||
setIsCheckingDuplicate(true);
|
||||
try {
|
||||
const duplicate = await resolveDuplicate(draft.woNumber);
|
||||
const duplicate = await resolveDuplicate(woNumberAtSubmit);
|
||||
// Ignore stale lookups if the WO# changed while the request was in flight.
|
||||
if (woNumberAtSubmit !== draftWoNumberRef.current) {
|
||||
return;
|
||||
}
|
||||
if (duplicate) {
|
||||
setDuplicateRow(duplicate);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue