mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 12:49:00 +00:00
fix(work-orders): close wizard before saving vendor notes on create
The create mutation's onSuccess awaited saveCompanyNotes before calling onOpenChange(false). Because isCreating is createMutation.isPending || isCheckingDuplicate, and isPending drops to false the moment the work-order create resolves, the dialog stayed open with Create re-enabled and pointer events unlocked for the length of the roster GET plus notes PATCH. A second Create click ran handleCreate again; with a blank provisional WO number the duplicate lookup short-circuits without an API call, so createMutation.mutate fired a second time and created a duplicate work order. Close the dialog first, then fire saveCompanyNotes unawaited. The save does not need the dialog open: fetchCurrentBaseline reads the roster when the baseline is missing, and the failure toast is raised from the mutation's option-level onError, so it still surfaces after the dialog unmounts.
This commit is contained in:
parent
cd5d4ad1d8
commit
1fa9f6ec02
1 changed files with 7 additions and 3 deletions
|
|
@ -65,9 +65,13 @@ export function useNewWoWizardController({
|
||||||
};
|
};
|
||||||
|
|
||||||
const createMutation = useCreateWorkOrderFromWizard((createdDraft) => {
|
const createMutation = useCreateWorkOrderFromWizard((createdDraft) => {
|
||||||
// Close only after the company-notes save attempt settles; its failures are surfaced
|
// Close the dialog first: the work-order create's isPending has already dropped, so
|
||||||
// as note-save warnings and must never report the work-order creation as failed.
|
// holding the dialog open through the notes save would re-enable Create and unlock
|
||||||
void saveCompanyNotes(createdDraft).finally(() => onOpenChange(false));
|
// pointer events, and a second click would create a second work order. The save runs
|
||||||
|
// independently of the dialog — fetchCurrentBaseline covers a missing baseline and the
|
||||||
|
// note-save failure toast is surfaced from the mutation itself, not the dialog.
|
||||||
|
onOpenChange(false);
|
||||||
|
void saveCompanyNotes(createdDraft);
|
||||||
});
|
});
|
||||||
const { duplicateRow, setDuplicateRow, handleDuplicateFound, handleCreate, isCreating } =
|
const { duplicateRow, setDuplicateRow, handleDuplicateFound, handleCreate, isCreating } =
|
||||||
useWizardDuplicateActions({
|
useWizardDuplicateActions({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue