From 5c28c2ad4617b59ccb56c975793b772806193e3c Mon Sep 17 00:00:00 2001 From: "arthur.bassi" Date: Thu, 6 Aug 2026 09:51:14 -0300 Subject: [PATCH] fix(work-orders): re-seed wizard POC on same-site reselect [SH-110] --- .../wizard/use-wizard-poc-autofill.ts | 10 +++++---- .../use-wizard-poc-autofill.test.tsx | 22 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/app/(protected)/workorders/_components/wizard/use-wizard-poc-autofill.ts b/src/app/(protected)/workorders/_components/wizard/use-wizard-poc-autofill.ts index 5efd24e6..0b515cac 100644 --- a/src/app/(protected)/workorders/_components/wizard/use-wizard-poc-autofill.ts +++ b/src/app/(protected)/workorders/_components/wizard/use-wizard-poc-autofill.ts @@ -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 }; diff --git a/src/test/app/(protected)/workorders/use-wizard-poc-autofill.test.tsx b/src/test/app/(protected)/workorders/use-wizard-poc-autofill.test.tsx index 3f97b935..5f9113b8 100644 --- a/src/test/app/(protected)/workorders/use-wizard-poc-autofill.test.tsx +++ b/src/test/app/(protected)/workorders/use-wizard-poc-autofill.test.tsx @@ -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({ ...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"); + }); });