mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 06:53:12 +00:00
fix(workorders): Site dialog clears the previous site's contact on a site switch
Picking another site on an existing work order kept the old site's POC name, phone and notes in the fields. When the new site's record failed to load, the dialog never synced it, Save stayed enabled, and the work order pointing at the new site was saved with the previous site's contact and notes as its override. A site switch now empties the POC name and phone for every work order, and the notes for existing ones, so the fields hold either the new site's record or what the dispatcher types for it.
This commit is contained in:
parent
b55938104a
commit
f36a07c99c
2 changed files with 40 additions and 3 deletions
|
|
@ -97,9 +97,11 @@ export function useSiteDialogFormFields({
|
|||
setContactsDirty(true);
|
||||
setUserEdited(false);
|
||||
setDirty(true);
|
||||
if (createMode) {
|
||||
// The previous site's contact never carries over, even when the new site fails to load.
|
||||
setPn("");
|
||||
setPp("");
|
||||
if (!createMode) {
|
||||
setNotes("");
|
||||
}
|
||||
setPocFilledFor("");
|
||||
} else if (id !== pocFilledFor) {
|
||||
|
|
|
|||
|
|
@ -133,6 +133,41 @@ describe("Work order Site dialog keeps the site record in sync", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("does not carry the previous site's contact onto a site whose record failed to load", async () => {
|
||||
// The legacy contact fields too, so nothing can refill the cleared fields from DAL1.
|
||||
const dallasWithContact: Location = { ...dallas, contact: "Jane", phone: "(421) 433-0032" };
|
||||
getById.mockImplementation((id: string) =>
|
||||
String(id) === "1"
|
||||
? Promise.resolve(dallasWithContact)
|
||||
: Promise.reject(new Error("Network error")),
|
||||
);
|
||||
const { onSave } = renderDialog();
|
||||
expect(await screen.findByDisplayValue("Jane")).toBeInTheDocument();
|
||||
|
||||
pickSite("CHI2");
|
||||
expect(await screen.findByText(SITE_UNAVAILABLE_COPY)).toBeInTheDocument();
|
||||
expect(primaryField("POC name")).toHaveValue("");
|
||||
expect(primaryField("POC phone")).toHaveValue("");
|
||||
expect(primaryField("Notes…")).toHaveValue("");
|
||||
fireEvent.click(screen.getByRole("button", { name: /^save$/i }));
|
||||
expect(await screen.findByText(/name is required/i)).toBeInTheDocument();
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
|
||||
fireEvent.change(primaryField("POC name"), { target: { value: "Carl" } });
|
||||
fireEvent.change(primaryField("POC phone"), { target: { value: "(312) 555-0101" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: /^save$/i }));
|
||||
|
||||
await waitFor(() => expect(onSave).toHaveBeenCalledTimes(1));
|
||||
expect(onSave.mock.calls[0][0]).toMatchObject({
|
||||
locationId: "2",
|
||||
pocName: "Carl",
|
||||
pocPhone: "(312) 555-0101",
|
||||
pocNotes: "",
|
||||
additionalContacts: [],
|
||||
});
|
||||
expect(updateContactInfo).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("waits for the refetch instead of syncing a cached site record, so a save never reverts it", async () => {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false }, mutations: { retry: false } },
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue