mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-07 16:19:01 +00:00
fix(work-orders): re-seed wizard POC on same-site reselect [SH-110]
This commit is contained in:
parent
b3d8be571e
commit
5c28c2ad46
2 changed files with 28 additions and 4 deletions
|
|
@ -39,10 +39,12 @@ export function useWizardPocAutofill(
|
|||
setPocAutoFilledFor(locationId);
|
||||
}, [locationId, locationDetail, pocAutoFilledFor, setDraft]);
|
||||
|
||||
function notifyLocationChanged(newLocationId: string) {
|
||||
if (newLocationId !== pocAutoFilledFor) {
|
||||
setPocAutoFilledFor("");
|
||||
}
|
||||
// Always clear the seed guard on a site pick (including re-selecting the
|
||||
// same location). Prototype onPick re-seeds pocName/pocPhone from the site
|
||||
// every time; if we keep the guard keyed by the same id, clearing the fields
|
||||
// leaves them blank because autofill will not re-run.
|
||||
function notifyLocationChanged(_newLocationId: string) {
|
||||
setPocAutoFilledFor("");
|
||||
}
|
||||
|
||||
return { notifyLocationChanged };
|
||||
|
|
|
|||
|
|
@ -53,4 +53,26 @@ describe("useWizardPocAutofill", () => {
|
|||
expect(result.current.pocName).toBe("Dispatcher Typed");
|
||||
expect(result.current.pocPhone).toBe("999-000-1111");
|
||||
});
|
||||
|
||||
it("re-seeds POC after re-selecting the same location clears the fields", () => {
|
||||
const { result } = renderHook(() => {
|
||||
const [draft, setDraft] = useState<WorkOrderWizardDraft>({ ...EMPTY_WIZARD_DRAFT });
|
||||
const autofill = useWizardPocAutofill(true, "loc-1", baseLocation(), setDraft);
|
||||
return { draft, setDraft, autofill };
|
||||
});
|
||||
|
||||
expect(result.current.draft.pocName).toBe("Janelle Pickett");
|
||||
|
||||
act(() => {
|
||||
result.current.setDraft((current) => ({
|
||||
...current,
|
||||
pocName: "",
|
||||
pocPhone: "",
|
||||
}));
|
||||
result.current.autofill.notifyLocationChanged("loc-1");
|
||||
});
|
||||
|
||||
expect(result.current.draft.pocName).toBe("Janelle Pickett");
|
||||
expect(result.current.draft.pocPhone).toBe("214-555-0111");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue