Merge remote-tracking branch 'origin/feat/ab/sh-331-sites-panel' into feat/ab/sh-334-site-delete

This commit is contained in:
Alexandre Brandizzi 2026-09-25 12:23:27 -03:00
commit 3ab9c9a65b
2 changed files with 17 additions and 1 deletions

View file

@ -236,7 +236,8 @@ export function mapLocationToBackend(location: unknown): Record<string, unknown>
state: item.state ?? "",
zipCode: item.zipCode ?? "",
phone: typeof item.sitePhone === "string" ? item.sitePhone.trim() : "",
contact: mainContact ? mainContact.name : "",
// A caller without a contacts list (e.g. address-only sync) keeps the stored legacy name.
contact: mainContact ? mainContact.name : readString(item, "contact").trim(),
contactEmail: typeof item.contactEmail === "string" ? item.contactEmail.trim() : "",
accountId: item.accountId ?? "",
contacts,

View file

@ -108,6 +108,21 @@ describe("mapLocationToBackend site payload", () => {
expect(bare).not.toHaveProperty("notes");
expect(full).toMatchObject({ status: "Active", title: "Dallas DC", notes: "Gate code 1234" });
});
it("keeps the legacy contact name when the caller sends no contacts list", () => {
const addressOnly = mapLocationToBackend({
name: "DAL1",
address: "3811 Distribution Dr",
contact: "Jane Doe",
});
const withContacts = mapLocationToBackend({
contact: "Jane Doe",
contacts: [{ name: "Bob", phone: "(421) 433-0033" }],
});
expect(addressOnly.contact).toBe("Jane Doe");
expect(withContacts.contact).toBe("Bob");
});
});
describe("mapLocation site fields", () => {