fix(work-orders): re-seed wizard POC on same-site reselect [SH-110]

This commit is contained in:
arthur.bassi 2026-08-06 09:51:14 -03:00
parent b3d8be571e
commit 5c28c2ad46
2 changed files with 28 additions and 4 deletions

View file

@ -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 };

View file

@ -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");
});
});