mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 08:03:13 +00:00
fix(workorders): lock Site dialog contacts until the site record loads
This commit is contained in:
parent
cccdeceb10
commit
ad500753e1
3 changed files with 44 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -164,6 +164,7 @@ export function useSiteDialogState({
|
|||
attemptSave,
|
||||
saveDisabled,
|
||||
saving: updateSite.isPending,
|
||||
siteRecordLoading: siteRecord.loading,
|
||||
editsSiteRecord,
|
||||
requiresPoc,
|
||||
setPn: fields.setPnDirty,
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue