fix(workorders): lock Site dialog contacts until the site record loads

This commit is contained in:
Alexandre Brandizzi 2026-09-25 12:36:16 -03:00
parent cccdeceb10
commit ad500753e1
3 changed files with 44 additions and 13 deletions

View file

@ -125,19 +125,26 @@ export function SiteDialog({
/>
)}
<SiteDialogPocSection
pocName={s.pn}
pocPhone={s.pp}
pocNotes={s.notes}
additionalContacts={s.extraContacts}
showPrimaryErrors={s.requiresPoc && s.showErrors}
primaryRequired={s.requiresPoc}
editsSiteRecord={s.editsSiteRecord}
onPocNameChange={s.setPn}
onPocPhoneChange={s.setPp}
onPocNotesChange={s.setNotes}
onAdditionalContactsChange={s.setExtraContacts}
/>
{/* Locked until the site record loads, so its values never replace typed input. */}
<fieldset
disabled={s.siteRecordLoading}
aria-busy={s.siteRecordLoading || undefined}
className="m-0 border-0 p-0"
>
<SiteDialogPocSection
pocName={s.pn}
pocPhone={s.pp}
pocNotes={s.notes}
additionalContacts={s.extraContacts}
showPrimaryErrors={s.requiresPoc && s.showErrors}
primaryRequired={s.requiresPoc}
editsSiteRecord={s.editsSiteRecord}
onPocNameChange={s.setPn}
onPocPhoneChange={s.setPp}
onPocNotesChange={s.setNotes}
onAdditionalContactsChange={s.setExtraContacts}
/>
</fieldset>
</fieldset>
<SiteDialogFooter

View file

@ -164,6 +164,7 @@ export function useSiteDialogState({
attemptSave,
saveDisabled,
saving: updateSite.isPending,
siteRecordLoading: siteRecord.loading,
editsSiteRecord,
requiresPoc,
setPn: fields.setPnDirty,

View file

@ -88,6 +88,29 @@ describe("Work order Site dialog edits the site record", () => {
expect(screen.getByText("dal1@acme.test")).toBeInTheDocument();
});
it("locks the contact fields until the site loads, so typed input is never replaced", async () => {
let resolveSite: (site: Location) => void = () => {};
getById.mockReturnValue(
new Promise<Location>((resolve) => {
resolveSite = resolve;
}),
);
renderDialog();
await waitFor(() => expect(getById).toHaveBeenCalled());
expect(primaryField("POC name")).toBeDisabled();
expect(primaryField("POC phone")).toBeDisabled();
expect(primaryField("Notes…")).toBeDisabled();
expect(saveButton()).toBeDisabled();
resolveSite(dallas);
expect(await screen.findByDisplayValue("Jane")).toBeEnabled();
fireEvent.change(primaryField("POC phone"), { target: { value: "(421) 433-9999" } });
expect(primaryField("POC phone")).toHaveValue("(421) 433-9999");
expect(saveButton()).toBeEnabled();
});
it("keeps Save disabled until something changes", async () => {
renderDialog();
await screen.findByDisplayValue("Jane");