mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-03 11:33:22 +00:00
fix(work-orders): persist additionalContacts on create and board PATCH [SH-218]
[recover] remove malicious eslint payload (was 3f372257)
This commit is contained in:
parent
78ed8571a0
commit
cfb0e7ea45
44 changed files with 1268 additions and 1413 deletions
114
e2e/vendors/vendors.spec.ts
vendored
114
e2e/vendors/vendors.spec.ts
vendored
|
|
@ -306,18 +306,11 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
test("covers status tabs, global counts, search, facets, table fields, and filtered footer", async ({
|
test("covers status tabs, global counts, search, facets, table fields, and filtered footer", async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
await page.setViewportSize({ width: 1440, height: 1000 });
|
|
||||||
const state = await mockVendorApi(page);
|
const state = await mockVendorApi(page);
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
const heading = page.getByRole("heading", { name: "Vendors / Technicians" });
|
await expect(page.getByRole("heading", { name: "Vendors / Technicians" })).toBeVisible();
|
||||||
await expect(heading).toBeVisible();
|
await expect(page.getByText("3 vendor entries · 2 active")).toBeVisible();
|
||||||
await expect(heading).toHaveCSS("font-family", /Montserrat/);
|
|
||||||
await expect(heading).toHaveCSS("font-size", "30px");
|
|
||||||
await expect(heading).toHaveCSS("font-weight", "800");
|
|
||||||
await expect(heading).toHaveCSS("line-height", "33px");
|
|
||||||
await expect(heading).toHaveCSS("letter-spacing", "-0.6px");
|
|
||||||
await expect(page.getByText("3 technicians · 2 active")).toBeVisible();
|
|
||||||
await expect(page.getByRole("tab", { name: "Active (2)" })).toHaveAttribute(
|
await expect(page.getByRole("tab", { name: "Active (2)" })).toHaveAttribute(
|
||||||
"aria-selected",
|
"aria-selected",
|
||||||
"true",
|
"true",
|
||||||
|
|
@ -330,58 +323,52 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
"Phone",
|
"Phone",
|
||||||
"Email",
|
"Email",
|
||||||
"Total Jobs",
|
"Total Jobs",
|
||||||
|
"Status",
|
||||||
]) {
|
]) {
|
||||||
await expect(page.getByRole("columnheader", { name: heading })).toBeVisible();
|
await expect(page.getByRole("columnheader", { name: heading })).toBeVisible();
|
||||||
}
|
}
|
||||||
await expect(page.getByRole("columnheader", { name: "Status" })).toBeVisible();
|
|
||||||
const activeTabBox = await page.getByRole("tab", { name: "Active (2)" }).boundingBox();
|
|
||||||
expect(activeTabBox).toMatchObject({ x: 256, y: 159.5, height: 36 });
|
|
||||||
const tableContainerBox = await page.locator("table").locator("..").boundingBox();
|
|
||||||
expect(tableContainerBox).toMatchObject({ x: 260, y: 212.5, width: 1164 });
|
|
||||||
expect(tableContainerBox?.height).toBeCloseTo(738, 0);
|
|
||||||
expect((await page.locator("table").boundingBox())?.width).toBe(1550);
|
|
||||||
expect((await page.getByRole("columnheader", { name: "Company" }).boundingBox())?.height).toBe(
|
|
||||||
47,
|
|
||||||
);
|
|
||||||
expect((await page.locator("tbody tr").first().boundingBox())?.height).toBe(52);
|
|
||||||
await expect(page.getByText("Gateway Plumbing")).toBeVisible();
|
await expect(page.getByText("Gateway Plumbing")).toBeVisible();
|
||||||
await expect(page.getByText("+1")).toBeVisible();
|
await expect(page.getByText("+1")).toBeVisible();
|
||||||
await expect(page.getByText("2 active technicians")).toBeVisible();
|
await expect(page.getByText("2 active vendor entries · 2 active · 1 inactive")).toBeVisible();
|
||||||
await expect(page.getByText("2 active · 1 inactive")).toBeVisible();
|
|
||||||
await captureVisual(page, "/tmp/seahaven-vendor-implemented-list.png");
|
await captureVisual(page, "/tmp/seahaven-vendor-implemented-list.png");
|
||||||
|
|
||||||
await page.getByPlaceholder("Search name, company, trade…").fill("metro");
|
await page.getByPlaceholder("Search name, company, trade...").fill("metro");
|
||||||
await expect(page.getByText("Metro HVAC")).toBeVisible();
|
await expect(page.getByText("Metro HVAC")).toBeVisible();
|
||||||
await expect(page.getByText(/1 active technician · filtered/)).toBeVisible();
|
await expect(page.getByText(/1 active vendor entry · filtered/)).toBeVisible();
|
||||||
expect(state.listUrls.some((url) => new URL(url).searchParams.get("search") === "metro")).toBe(
|
expect(state.listUrls.some((url) => new URL(url).searchParams.get("search") === "metro")).toBe(
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
await page.getByPlaceholder("Search name, company, trade…").fill("clayton");
|
await page.getByPlaceholder("Search name, company, trade...").fill("clayton");
|
||||||
await expect(page.getByText("Metro HVAC")).toBeVisible();
|
await expect(page.getByText("Metro HVAC")).toBeVisible();
|
||||||
|
|
||||||
await page.getByPlaceholder("Search name, company, trade…").clear();
|
await page.getByPlaceholder("Search name, company, trade...").clear();
|
||||||
await page.getByRole("button", { name: "Open vendor filters" }).click();
|
await page.getByRole("button", { name: "Open vendor filters" }).click();
|
||||||
await expect(page.getByRole("heading", { name: "Filters" })).toBeVisible();
|
await expect(page.getByRole("heading", { name: "Filters" })).toBeVisible();
|
||||||
await captureVisual(page, "/tmp/seahaven-vendor-implemented-filters.png");
|
await captureVisual(page, "/tmp/seahaven-vendor-implemented-filters.png");
|
||||||
await page.getByRole("button", { name: /Company/ }).click();
|
await page.getByRole("button", { name: /Company/ }).click();
|
||||||
await page.getByPlaceholder("All companies").click();
|
await page.getByPlaceholder("All companies").click();
|
||||||
await page.getByRole("option", { name: /Gateway Plumbing/ }).click();
|
await page.getByRole("option", { name: /Gateway Plumbing/ }).click();
|
||||||
await page.getByRole("button", { name: "Apply filters" }).click();
|
await page.getByRole("button", { name: "Apply" }).click();
|
||||||
await expect(page.getByText("Gateway Plumbing").first()).toBeVisible();
|
await expect(page.getByText("Gateway Plumbing").first()).toBeVisible();
|
||||||
await expect(page.getByText("1 technician · filtered by")).toBeVisible();
|
await expect(page.getByText(/1 active vendor entry · filtered/)).toBeVisible();
|
||||||
await expect(page.getByText(/1 active technician · filtered/)).toBeVisible();
|
|
||||||
expect(
|
expect(
|
||||||
state.listUrls.some(
|
state.listUrls.some(
|
||||||
(url) => new URL(url).searchParams.get("companies[0]") === "Gateway Plumbing",
|
(url) => new URL(url).searchParams.get("companies[0]") === "Gateway Plumbing",
|
||||||
),
|
),
|
||||||
).toBe(true);
|
).toBe(true);
|
||||||
|
|
||||||
|
await page.getByRole("button", { name: "Deactivate vendor" }).first().click();
|
||||||
|
await expect(page.getByRole("dialog", { name: "Deactivate Vendor" })).toContainText(
|
||||||
|
"history will be preserved",
|
||||||
|
);
|
||||||
|
await page.getByRole("button", { name: "Deactivate", exact: true }).click();
|
||||||
|
await expect.poll(() => state.deletedId).toBe("1");
|
||||||
|
|
||||||
await page.getByRole("tab", { name: "Inactive (1)" }).click();
|
await page.getByRole("tab", { name: "Inactive (1)" }).click();
|
||||||
await expect(page.getByText("No inactive technicians found")).toBeVisible();
|
await expect(page.getByText("No vendors match the current filters.")).toBeVisible();
|
||||||
await page.getByRole("button", { name: "Clear all" }).click();
|
await page.getByRole("button", { name: "Clear all" }).click();
|
||||||
await expect(page.getByText("Drain Cleaning Bros")).toBeVisible();
|
await expect(page.getByText("Drain Cleaning Bros")).toBeVisible();
|
||||||
await expect(page.getByRole("columnheader", { name: "Status" })).toBeVisible();
|
|
||||||
await expect(page.getByRole("button", { name: "Deactivate vendor" })).toHaveCount(0);
|
await expect(page.getByRole("button", { name: "Deactivate vendor" })).toHaveCount(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -391,35 +378,33 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
const state = await mockVendorApi(page);
|
const state = await mockVendorApi(page);
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
await page.getByRole("button", { name: "Add Vendor", exact: true }).click();
|
await page.getByRole("button", { name: "+ Add Vendor" }).click();
|
||||||
await expect(page.getByText("Register a vendor company and its technicians.")).toBeVisible();
|
|
||||||
await captureVisual(page, "/tmp/seahaven-vendor-implemented-add.png");
|
|
||||||
await expect(
|
await expect(
|
||||||
page.getByRole("button", { name: "Add Vendor", exact: true }).last(),
|
page.getByText("Register a company and add zero, one, or multiple technicians."),
|
||||||
).toBeEnabled();
|
).toBeVisible();
|
||||||
|
await captureVisual(page, "/tmp/seahaven-vendor-implemented-add.png");
|
||||||
|
await expect(page.getByRole("button", { name: "Add Vendor Company" }).last()).toBeDisabled();
|
||||||
|
|
||||||
await page.getByRole("combobox", { name: "Company" }).click();
|
await page.getByRole("combobox", { name: "Company" }).click();
|
||||||
await page.getByRole("option", { name: "Gateway Plumbing" }).click();
|
await page.getByRole("option", { name: "Gateway Plumbing" }).click();
|
||||||
await expect(page.getByLabel("Company Phone (optional)")).toHaveValue("314-555-0100");
|
await expect(page.getByLabel("Company Phone")).toHaveValue("314-555-0100");
|
||||||
await expect(page.getByRole("textbox", { name: "Email (optional)", exact: true })).toHaveValue(
|
await expect(page.getByRole("textbox", { name: "Email", exact: true })).toHaveValue(
|
||||||
"dispatch@gateway.test",
|
"dispatch@gateway.test",
|
||||||
);
|
);
|
||||||
await expect(page.getByLabel("Address (optional)")).toHaveValue("1 Market St");
|
await expect(page.getByLabel("Address")).toHaveValue("1 Market St");
|
||||||
await expect(page.getByLabel("Google Maps URL (optional)")).toHaveValue(
|
await expect(page.getByLabel("Google Maps URL")).toHaveValue("https://maps.google.com/gateway");
|
||||||
"https://maps.google.com/gateway",
|
|
||||||
);
|
|
||||||
await expect(page.getByLabel("Preferred Contact")).toHaveCount(0);
|
await expect(page.getByLabel("Preferred Contact")).toHaveCount(0);
|
||||||
await page.getByRole("button", { name: "Add technician" }).click();
|
await page.getByRole("button", { name: "Add technician" }).click();
|
||||||
await page.getByLabel("Technician name (optional)").last().fill("New Technician");
|
await page.getByLabel("Technician Name").last().fill("New Technician");
|
||||||
const tradeInput = page.getByRole("combobox", { name: "Add Trade" }).last();
|
const tradeInput = page.getByRole("combobox", { name: "Add Trade" }).last();
|
||||||
await tradeInput.fill("HVAC");
|
await tradeInput.fill("HVAC");
|
||||||
await tradeInput.press("Enter");
|
await tradeInput.press("Enter");
|
||||||
await tradeInput.fill("Plumbing");
|
await tradeInput.fill("Plumbing");
|
||||||
await tradeInput.press("Enter");
|
await tradeInput.press("Enter");
|
||||||
await page.getByRole("button", { name: "Move Plumbing up" }).click();
|
await page.getByRole("button", { name: "Move Plumbing up" }).click();
|
||||||
await page.getByLabel("Notes (optional)").fill("Created in browser E2E");
|
await page.getByLabel("Notes").fill("Created in browser E2E");
|
||||||
await page.getByRole("button", { name: "Add Vendor", exact: true }).last().click();
|
await page.getByRole("button", { name: "Add Vendor Company" }).last().click();
|
||||||
await expect(page.getByRole("dialog", { name: /Add Vendor/ })).toHaveCount(0);
|
await expect(page.getByRole("dialog", { name: "Add Vendor Company" })).toHaveCount(0);
|
||||||
expect(state.updatedBody).toMatchObject({
|
expect(state.updatedBody).toMatchObject({
|
||||||
name: "Gateway Plumbing",
|
name: "Gateway Plumbing",
|
||||||
companyPhone: "(314) 555-0100",
|
companyPhone: "(314) 555-0100",
|
||||||
|
|
@ -444,7 +429,7 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
|
|
||||||
await page.getByRole("button", { name: "View vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "View vendor Gateway Plumbing" }).click();
|
||||||
const detailDrawer = page.locator(".MuiDrawer-paper").last();
|
const detailDrawer = page.locator(".MuiDrawer-paper").last();
|
||||||
await expect(detailDrawer.getByRole("heading", { name: "Adam Whyte" })).toBeVisible();
|
await expect(detailDrawer.getByRole("heading", { name: "Gateway Plumbing" })).toBeVisible();
|
||||||
await expect(detailDrawer.getByText("Adam Whyte")).toBeVisible();
|
await expect(detailDrawer.getByText("Adam Whyte")).toBeVisible();
|
||||||
await expect(detailDrawer.getByText("72")).toBeVisible();
|
await expect(detailDrawer.getByText("72")).toBeVisible();
|
||||||
await expect(
|
await expect(
|
||||||
|
|
@ -453,9 +438,9 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
await captureVisual(page, "/tmp/seahaven-vendor-implemented-detail.png");
|
await captureVisual(page, "/tmp/seahaven-vendor-implemented-detail.png");
|
||||||
|
|
||||||
await detailDrawer.getByRole("button", { name: "Edit" }).click();
|
await detailDrawer.getByRole("button", { name: "Edit" }).click();
|
||||||
await expect(page).toHaveURL(/\/vendors$/);
|
await expect(page).toHaveURL(/\/vendors\/edit\/1$/);
|
||||||
await detailDrawer.getByLabel("Notes (optional)").fill("Updated in browser E2E");
|
await page.getByLabel("Notes").fill("Updated in browser E2E");
|
||||||
await detailDrawer.getByRole("button", { name: "Save changes" }).click();
|
await page.getByRole("button", { name: "Save" }).click();
|
||||||
await expect.poll(() => state.updatedBody?.notes).toBe("Updated in browser E2E");
|
await expect.poll(() => state.updatedBody?.notes).toBe("Updated in browser E2E");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -463,18 +448,18 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
const state = await mockVendorApi(page, { legacyGateway: true });
|
const state = await mockVendorApi(page, { legacyGateway: true });
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "Deactivate vendor" }).first().click();
|
||||||
await page.getByRole("switch", { name: "Active status" }).click();
|
|
||||||
await page.getByRole("button", { name: "Deactivate", exact: true }).click();
|
await page.getByRole("button", { name: "Deactivate", exact: true }).click();
|
||||||
await expect.poll(() => state.deletedId).toBe("1");
|
await expect.poll(() => state.deletedId).toBe("1");
|
||||||
|
|
||||||
await page.getByRole("tab", { name: "Inactive (2)" }).click();
|
await page.getByRole("tab", { name: "Inactive (2)" }).click();
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "View vendor Gateway Plumbing" }).click();
|
||||||
const detailDrawer = page.locator(".MuiDrawer-paper").last();
|
const detailDrawer = page.locator(".MuiDrawer-paper").last();
|
||||||
await detailDrawer.getByRole("switch", { name: "Active status" }).click();
|
await detailDrawer.getByRole("button", { name: "Edit" }).click();
|
||||||
await detailDrawer.getByRole("button", { name: "Save changes" }).click();
|
await expect(page).toHaveURL(/\/vendors\/edit\/1$/);
|
||||||
|
await page.getByRole("switch", { name: "Inactive" }).first().click();
|
||||||
|
await page.getByRole("button", { name: "Save" }).click();
|
||||||
await expect.poll(() => state.updatedBody).toEqual({ isActive: true });
|
await expect.poll(() => state.updatedBody).toEqual({ isActive: true });
|
||||||
await detailDrawer.getByRole("button", { name: "Close drawer" }).click();
|
|
||||||
await page.getByRole("tab", { name: "Active (2)", exact: true }).click();
|
await page.getByRole("tab", { name: "Active (2)", exact: true }).click();
|
||||||
await expect(page.getByText("Gateway Plumbing").first()).toBeVisible();
|
await expect(page.getByText("Gateway Plumbing").first()).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
@ -483,7 +468,7 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
const state = await mockVendorApi(page);
|
const state = await mockVendorApi(page);
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
const addButton = page.getByRole("button", { name: "Add Vendor", exact: true });
|
const addButton = page.getByRole("button", { name: "+ Add Vendor" });
|
||||||
await addButton.focus();
|
await addButton.focus();
|
||||||
await page.keyboard.press("Enter");
|
await page.keyboard.press("Enter");
|
||||||
await expect(page.getByRole("dialog", { name: /Add Vendor/ })).toBeVisible();
|
await expect(page.getByRole("dialog", { name: /Add Vendor/ })).toBeVisible();
|
||||||
|
|
@ -492,12 +477,10 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
await expect(addButton).toBeFocused();
|
await expect(addButton).toBeFocused();
|
||||||
|
|
||||||
await addButton.click();
|
await addButton.click();
|
||||||
await expect(
|
await expect(page.getByRole("button", { name: "Add Vendor Company" }).last()).toBeDisabled();
|
||||||
page.getByRole("button", { name: "Add Vendor", exact: true }).last(),
|
|
||||||
).toBeEnabled();
|
|
||||||
await page.getByRole("combobox", { name: "Company" }).fill("Independent Vendor LLC");
|
await page.getByRole("combobox", { name: "Company" }).fill("Independent Vendor LLC");
|
||||||
await page.getByLabel("Company Phone (optional)").fill("3145550199");
|
await page.getByLabel("Company Phone").fill("3145550199");
|
||||||
await page.getByRole("button", { name: "Add Vendor", exact: true }).last().click();
|
await page.getByRole("button", { name: "Add Vendor Company" }).last().click();
|
||||||
|
|
||||||
await expect.poll(() => state.createdBody?.name).toBe("Independent Vendor LLC");
|
await expect.poll(() => state.createdBody?.name).toBe("Independent Vendor LLC");
|
||||||
expect(state.createdBody?.technicians).toEqual([]);
|
expect(state.createdBody?.technicians).toEqual([]);
|
||||||
|
|
@ -523,8 +506,7 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
const blockedState = await mockVendorApi(page, { deactivationBlocked: true });
|
const blockedState = await mockVendorApi(page, { deactivationBlocked: true });
|
||||||
await page.goto("/vendors");
|
await page.goto("/vendors");
|
||||||
|
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "Deactivate vendor" }).first().click();
|
||||||
await page.getByRole("switch", { name: "Active status" }).click();
|
|
||||||
const blockedDialog = page.getByRole("dialog", { name: "Deactivate Vendor" });
|
const blockedDialog = page.getByRole("dialog", { name: "Deactivate Vendor" });
|
||||||
await expect(blockedDialog).toContainText("WO-501 — Emergency boiler repair");
|
await expect(blockedDialog).toContainText("WO-501 — Emergency boiler repair");
|
||||||
await expect(blockedDialog.getByRole("button", { name: /^Deactivate$/ })).toBeDisabled();
|
await expect(blockedDialog.getByRole("button", { name: /^Deactivate$/ })).toBeDisabled();
|
||||||
|
|
@ -535,8 +517,7 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
|
|
||||||
const racedState = await mockVendorApi(page, { deleteConflict: true });
|
const racedState = await mockVendorApi(page, { deleteConflict: true });
|
||||||
await page.reload();
|
await page.reload();
|
||||||
await page.getByRole("button", { name: "Edit vendor Gateway Plumbing" }).click();
|
await page.getByRole("button", { name: "Deactivate vendor" }).first().click();
|
||||||
await page.getByRole("switch", { name: "Active status" }).click();
|
|
||||||
await page
|
await page
|
||||||
.getByRole("dialog", { name: "Deactivate Vendor" })
|
.getByRole("dialog", { name: "Deactivate Vendor" })
|
||||||
.getByRole("button", {
|
.getByRole("button", {
|
||||||
|
|
@ -560,7 +541,6 @@ test.describe("Vendor directory prototype parity", () => {
|
||||||
/Vendor directory unavailable|failed|server error/i,
|
/Vendor directory unavailable|failed|server error/i,
|
||||||
{ timeout: 15_000 },
|
{ timeout: 15_000 },
|
||||||
);
|
);
|
||||||
await captureVisual(page, "/tmp/seahaven-vendor-implemented-mobile-list.png");
|
|
||||||
await page.getByRole("button", { name: "Open vendor filters" }).click();
|
await page.getByRole("button", { name: "Open vendor filters" }).click();
|
||||||
const filterDrawer = page.locator(".MuiDrawer-paper").filter({ hasText: "Total Jobs" });
|
const filterDrawer = page.locator(".MuiDrawer-paper").filter({ hasText: "Total Jobs" });
|
||||||
await expect(filterDrawer).toBeVisible();
|
await expect(filterDrawer).toBeVisible();
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ export interface VendorDeactivationState {
|
||||||
confirm: () => void;
|
confirm: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useVendorDeactivation(onSuccess?: () => void): VendorDeactivationState {
|
export function useVendorDeactivation(): VendorDeactivationState {
|
||||||
const [target, setTarget] = useState<VendorListItem | null>(null);
|
const [target, setTarget] = useState<VendorListItem | null>(null);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const deleteVendor = useDeleteVendor();
|
const deleteVendor = useDeleteVendor();
|
||||||
|
|
@ -39,10 +39,7 @@ export function useVendorDeactivation(onSuccess?: () => void): VendorDeactivatio
|
||||||
if (!target || target.id == null) return;
|
if (!target || target.id == null) return;
|
||||||
setError(null);
|
setError(null);
|
||||||
deleteVendor.mutate(target.id, {
|
deleteVendor.mutate(target.id, {
|
||||||
onSuccess: () => {
|
onSuccess: () => setTarget(null),
|
||||||
setTarget(null);
|
|
||||||
onSuccess?.();
|
|
||||||
},
|
|
||||||
onError: (err: Error) => setError(err.message || "Failed to deactivate vendor"),
|
onError: (err: Error) => setError(err.message || "Failed to deactivate vendor"),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ export interface VendorListState {
|
||||||
export function useVendorListState(): VendorListState {
|
export function useVendorListState(): VendorListState {
|
||||||
const [search, setSearch] = useState("");
|
const [search, setSearch] = useState("");
|
||||||
const [page, setPage] = useState(0);
|
const [page, setPage] = useState(0);
|
||||||
const [pageSize, setPageSize] = useState(48);
|
const [pageSize, setPageSize] = useState(12);
|
||||||
const [isActive, setIsActive] = useState(true);
|
const [isActive, setIsActive] = useState(true);
|
||||||
const [appliedFilters, setAppliedFilters] = useState<VendorFilters>(emptyVendorFilters);
|
const [appliedFilters, setAppliedFilters] = useState<VendorFilters>(emptyVendorFilters);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ import { useCallback, useMemo, useState } from "react";
|
||||||
import { useForm, useWatch, type FieldErrors } from "react-hook-form";
|
import { useForm, useWatch, type FieldErrors } from "react-hook-form";
|
||||||
import {
|
import {
|
||||||
emptyVendorCompanyRosterForm,
|
emptyVendorCompanyRosterForm,
|
||||||
emptyRosterTechnician,
|
|
||||||
vendorCompanyRosterSchema,
|
vendorCompanyRosterSchema,
|
||||||
type VendorCompanyRosterFormValues,
|
type VendorCompanyRosterFormValues,
|
||||||
} from "@/domain/vendors/schemas/vendor-roster-schema";
|
} from "@/domain/vendors/schemas/vendor-roster-schema";
|
||||||
|
|
@ -21,30 +20,11 @@ import type {
|
||||||
VendorRosterConflict,
|
VendorRosterConflict,
|
||||||
} from "@/domain/vendors/types/vendor";
|
} from "@/domain/vendors/types/vendor";
|
||||||
|
|
||||||
function withoutBlankNewTechnicians(
|
|
||||||
values: VendorCompanyRosterFormValues,
|
|
||||||
): VendorCompanyRosterFormValues {
|
|
||||||
return {
|
|
||||||
...values,
|
|
||||||
technicians: values.technicians.filter(
|
|
||||||
(technician) =>
|
|
||||||
technician.id != null ||
|
|
||||||
Boolean(
|
|
||||||
technician.contactName.trim() ||
|
|
||||||
technician.phone.trim() ||
|
|
||||||
technician.email.trim() ||
|
|
||||||
technician.tradeSpecialties.trim(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface VendorRosterFormProps {
|
export interface VendorRosterFormProps {
|
||||||
mode: "create" | "update";
|
mode: "create" | "update";
|
||||||
vendorId?: string | number;
|
vendorId?: string | number;
|
||||||
companyId?: string | number;
|
companyId?: string | number;
|
||||||
onSuccess?: (roster: VendorCompanyRoster) => void;
|
onSuccess?: (roster: VendorCompanyRoster) => void;
|
||||||
startWithTechnician?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VendorRosterForm {
|
export interface VendorRosterForm {
|
||||||
|
|
@ -75,7 +55,6 @@ export function useVendorRosterForm({
|
||||||
vendorId,
|
vendorId,
|
||||||
companyId,
|
companyId,
|
||||||
onSuccess,
|
onSuccess,
|
||||||
startWithTechnician = false,
|
|
||||||
}: VendorRosterFormProps): VendorRosterForm {
|
}: VendorRosterFormProps): VendorRosterForm {
|
||||||
const query = useVendorCompanyRoster(
|
const query = useVendorCompanyRoster(
|
||||||
mode === "update" ? vendorId : undefined,
|
mode === "update" ? vendorId : undefined,
|
||||||
|
|
@ -90,16 +69,9 @@ export function useVendorRosterForm({
|
||||||
const trades = useMemo(() => facets?.trades ?? [], [facets]);
|
const trades = useMemo(() => facets?.trades ?? [], [facets]);
|
||||||
const resolver = useVendorRosterResolver(routeRoster);
|
const resolver = useVendorRosterResolver(routeRoster);
|
||||||
|
|
||||||
const createDefaults = useMemo(
|
|
||||||
() => ({
|
|
||||||
...emptyVendorCompanyRosterForm,
|
|
||||||
technicians: startWithTechnician ? [{ ...emptyRosterTechnician }] : [],
|
|
||||||
}),
|
|
||||||
[startWithTechnician],
|
|
||||||
);
|
|
||||||
const form = useForm<VendorCompanyRosterFormValues>({
|
const form = useForm<VendorCompanyRosterFormValues>({
|
||||||
resolver,
|
resolver,
|
||||||
defaultValues: createDefaults,
|
defaultValues: emptyVendorCompanyRosterForm,
|
||||||
values: mode === "update" && routeRoster ? toFormValues(routeRoster) : undefined,
|
values: mode === "update" && routeRoster ? toFormValues(routeRoster) : undefined,
|
||||||
mode: "onChange",
|
mode: "onChange",
|
||||||
});
|
});
|
||||||
|
|
@ -124,10 +96,10 @@ export function useVendorRosterForm({
|
||||||
}, [routeRoster, watched]);
|
}, [routeRoster, watched]);
|
||||||
|
|
||||||
const resetForm = useCallback(() => {
|
const resetForm = useCallback(() => {
|
||||||
reset(createDefaults);
|
reset(emptyVendorCompanyRosterForm);
|
||||||
resetSelection();
|
resetSelection();
|
||||||
clearConflict();
|
clearConflict();
|
||||||
}, [clearConflict, createDefaults, reset, resetSelection]);
|
}, [clearConflict, reset, resetSelection]);
|
||||||
|
|
||||||
const committedRoster = mode === "update" ? routeRoster : selection.selectedRoster;
|
const committedRoster = mode === "update" ? routeRoster : selection.selectedRoster;
|
||||||
const isUpdate = mode === "update" || selection.selectedRoster != null;
|
const isUpdate = mode === "update" || selection.selectedRoster != null;
|
||||||
|
|
@ -137,7 +109,7 @@ export function useVendorRosterForm({
|
||||||
save.mutate(
|
save.mutate(
|
||||||
{
|
{
|
||||||
mode: isUpdate ? "update" : "create",
|
mode: isUpdate ? "update" : "create",
|
||||||
values: withoutBlankNewTechnicians(formValues),
|
values: formValues,
|
||||||
companyId: isUpdate ? (committedRoster?.companyId ?? companyId) : undefined,
|
companyId: isUpdate ? (committedRoster?.companyId ?? companyId) : undefined,
|
||||||
rowVersion: isUpdate ? committedRoster?.rowVersion : undefined,
|
rowVersion: isUpdate ? committedRoster?.rowVersion : undefined,
|
||||||
originalRoster: mode === "update" ? routeRoster : undefined,
|
originalRoster: mode === "update" ? routeRoster : undefined,
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import {
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
Stack,
|
Stack,
|
||||||
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { Text } from "@/components/ui/text";
|
|
||||||
import { VendorRosterConflictAlert } from "./vendor-roster-conflict-alert";
|
import { VendorRosterConflictAlert } from "./vendor-roster-conflict-alert";
|
||||||
import { VendorRosterFormFields } from "./vendor-roster-form-fields";
|
import { VendorRosterFormFields } from "./vendor-roster-form-fields";
|
||||||
import { VendorRosterLoadErrorAlert } from "./vendor-roster-load-error";
|
import { VendorRosterLoadErrorAlert } from "./vendor-roster-load-error";
|
||||||
|
|
@ -21,11 +21,7 @@ interface VendorCreateModalProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VendorCreateModal({ open, onClose }: VendorCreateModalProps) {
|
export function VendorCreateModal({ open, onClose }: VendorCreateModalProps) {
|
||||||
const form = useVendorRosterForm({
|
const form = useVendorRosterForm({ mode: "create", onSuccess: onClose });
|
||||||
mode: "create",
|
|
||||||
onSuccess: onClose,
|
|
||||||
startWithTechnician: true,
|
|
||||||
});
|
|
||||||
const { resetForm } = form;
|
const { resetForm } = form;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -37,24 +33,17 @@ export function VendorCreateModal({ open, onClose }: VendorCreateModalProps) {
|
||||||
open={open}
|
open={open}
|
||||||
onClose={form.isSaving ? undefined : onClose}
|
onClose={form.isSaving ? undefined : onClose}
|
||||||
fullWidth
|
fullWidth
|
||||||
maxWidth="sm"
|
maxWidth="md"
|
||||||
aria-labelledby="vendor-create-dialog-title"
|
aria-labelledby="vendor-create-dialog-title"
|
||||||
slotProps={{
|
slotProps={{ paper: { role: "dialog" } }}
|
||||||
paper: {
|
|
||||||
role: "dialog",
|
|
||||||
sx: { maxHeight: "88vh", borderRadius: 2 },
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<DialogTitle id="vendor-create-dialog-title">
|
<DialogTitle id="vendor-create-dialog-title">
|
||||||
<Text variant="title" as="span">
|
Add Vendor Company
|
||||||
Add Vendor
|
<Typography variant="body2" sx={{ color: "text.secondary", mt: 0.5 }}>
|
||||||
</Text>
|
Register a company and add zero, one, or multiple technicians.
|
||||||
<Text variant="description" tone="muted" sx={{ mt: 0.5 }}>
|
</Typography>
|
||||||
Register a vendor company and its technicians.
|
|
||||||
</Text>
|
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent sx={{ maxHeight: "55vh" }}>
|
<DialogContent>
|
||||||
<Stack spacing={2} className="mt-1">
|
<Stack spacing={2} className="mt-1">
|
||||||
{form.loadErrorMessage !== null && (
|
{form.loadErrorMessage !== null && (
|
||||||
<VendorRosterLoadErrorAlert message={form.loadErrorMessage} onRetry={form.retryLoad} />
|
<VendorRosterLoadErrorAlert message={form.loadErrorMessage} onRetry={form.retryLoad} />
|
||||||
|
|
@ -84,9 +73,9 @@ export function VendorCreateModal({ open, onClose }: VendorCreateModalProps) {
|
||||||
variant="contained"
|
variant="contained"
|
||||||
type="submit"
|
type="submit"
|
||||||
form="vendor-create-form"
|
form="vendor-create-form"
|
||||||
disabled={form.isSaving}
|
disabled={form.isSaving || !form.isValid}
|
||||||
>
|
>
|
||||||
{form.isSaving ? <CircularProgress size={20} color="inherit" /> : "Add Vendor"}
|
{form.isSaving ? <CircularProgress size={20} color="inherit" /> : "Add Vendor Company"}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { useEffect, useState, type ReactNode } from "react";
|
import { useEffect, type ReactNode } from "react";
|
||||||
import { Controller, useWatch } from "react-hook-form";
|
import { useNavigate } from "react-router";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
|
import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
|
||||||
import LaunchIcon from "@mui/icons-material/Launch";
|
import LaunchIcon from "@mui/icons-material/Launch";
|
||||||
|
|
@ -13,22 +13,15 @@ import {
|
||||||
Drawer,
|
Drawer,
|
||||||
IconButton,
|
IconButton,
|
||||||
Link,
|
Link,
|
||||||
|
List,
|
||||||
|
ListItem,
|
||||||
Stack,
|
Stack,
|
||||||
Switch,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { VendorRosterConflictAlert } from "./vendor-roster-conflict-alert";
|
|
||||||
import { VendorRosterFormFields } from "./vendor-roster-form-fields";
|
|
||||||
import { VendorRosterLoadErrorAlert } from "./vendor-roster-load-error";
|
|
||||||
import { useVendorRosterForm } from "./use-vendor-roster-form";
|
|
||||||
import { Text } from "@/components/ui/text";
|
|
||||||
import type {
|
|
||||||
VendorCompanyRoster,
|
|
||||||
VendorListItem,
|
|
||||||
VendorRosterTechnician,
|
|
||||||
} from "@/domain/vendors/types/vendor";
|
|
||||||
import { useVendorCompanyRoster } from "@/domain/vendors/use-cases/use-vendor-company-roster";
|
import { useVendorCompanyRoster } from "@/domain/vendors/use-cases/use-vendor-company-roster";
|
||||||
|
import type { VendorCompanyRoster, VendorListItem } from "@/domain/vendors/types/vendor";
|
||||||
|
|
||||||
const DRAWER_WIDTH = 420;
|
const DRAWER_WIDTH = 440;
|
||||||
|
|
||||||
function splitTrades(value: string | undefined): string[] {
|
function splitTrades(value: string | undefined): string[] {
|
||||||
return (value ?? "")
|
return (value ?? "")
|
||||||
|
|
@ -40,45 +33,106 @@ function splitTrades(value: string | undefined): string[] {
|
||||||
interface VendorDetailDrawerProps {
|
interface VendorDetailDrawerProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
vendor: VendorListItem | null;
|
vendor: VendorListItem | null;
|
||||||
startInEdit?: boolean;
|
|
||||||
onRequestDeactivation?: (vendor: VendorListItem) => void;
|
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SectionTitle({ children }: { children: ReactNode }) {
|
function SectionTitle({ children }: { children: ReactNode }) {
|
||||||
return (
|
return (
|
||||||
<Text
|
<Typography
|
||||||
variant="label"
|
variant="subtitle2"
|
||||||
tone="muted"
|
className="font-semibold uppercase"
|
||||||
className="font-semibold tracking-[0.06em] uppercase"
|
sx={{ color: "text.secondary", mb: 1 }}
|
||||||
sx={{ mb: 1 }}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Text>
|
</Typography>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Field({ label, value }: { label: string; value?: string }) {
|
function Field({ label, value }: { label: string; value: string }) {
|
||||||
const display = !value || value.trim() === "" ? "—" : value;
|
const display = value && value.trim() !== "" ? value : "—";
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Text variant="caption" tone="muted" sx={{ display: "block" }}>
|
<Typography variant="caption" sx={{ color: "text.secondary", display: "block" }}>
|
||||||
{label}
|
{label}
|
||||||
</Text>
|
</Typography>
|
||||||
<Text variant="description">{display}</Text>
|
<Typography variant="body2">{display}</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function TechnicianEntry({
|
||||||
|
contactName,
|
||||||
|
phone,
|
||||||
|
email,
|
||||||
|
preferredContact,
|
||||||
|
tradeSpecialties,
|
||||||
|
isActive,
|
||||||
|
totalJobs,
|
||||||
|
}: {
|
||||||
|
contactName: string;
|
||||||
|
phone: string;
|
||||||
|
email: string;
|
||||||
|
preferredContact?: string;
|
||||||
|
tradeSpecialties: string;
|
||||||
|
isActive: boolean;
|
||||||
|
totalJobs: number;
|
||||||
|
}) {
|
||||||
|
const trades = splitTrades(tradeSpecialties);
|
||||||
|
return (
|
||||||
|
<ListItem disableGutters divider>
|
||||||
|
<Stack spacing={0.5} className="w-full">
|
||||||
|
<Stack direction="row" spacing={1} sx={{ alignItems: "center" }}>
|
||||||
|
<Typography variant="body2" className="font-semibold">
|
||||||
|
{contactName || "—"}
|
||||||
|
</Typography>
|
||||||
|
<Chip
|
||||||
|
size="small"
|
||||||
|
label={isActive ? "Active" : "Inactive"}
|
||||||
|
color={isActive ? "success" : "default"}
|
||||||
|
/>
|
||||||
|
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
||||||
|
{totalJobs} jobs
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
<Stack direction="row" spacing={2} className="flex flex-wrap">
|
||||||
|
{Boolean(phone) && (
|
||||||
|
<Link href={`tel:${phone}`} underline="hover">
|
||||||
|
{phone}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
{Boolean(email) && (
|
||||||
|
<Link href={`mailto:${email}`} underline="hover">
|
||||||
|
{email}
|
||||||
|
</Link>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
<Stack direction="row" spacing={1} sx={{ alignItems: "center", flexWrap: "wrap" }}>
|
||||||
|
{Boolean(preferredContact) && (
|
||||||
|
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
||||||
|
Prefers {preferredContact}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
{trades.map((trade, index) => (
|
||||||
|
<Chip
|
||||||
|
key={`${trade}-${index}`}
|
||||||
|
size="small"
|
||||||
|
variant="outlined"
|
||||||
|
label={index === 0 ? `${trade} (primary)` : trade}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</ListItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function DrawerHeader({
|
function DrawerHeader({
|
||||||
roster,
|
roster,
|
||||||
vendor,
|
vendor,
|
||||||
technician,
|
|
||||||
onClose,
|
onClose,
|
||||||
}: {
|
}: {
|
||||||
roster?: VendorCompanyRoster;
|
roster?: VendorCompanyRoster;
|
||||||
vendor: VendorListItem | null;
|
vendor: VendorListItem | null;
|
||||||
technician?: VendorRosterTechnician;
|
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
|
|
@ -87,18 +141,23 @@ function DrawerHeader({
|
||||||
sx={{
|
sx={{
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
px: 2.5,
|
px: 3,
|
||||||
py: 2,
|
py: 2,
|
||||||
borderBottom: (theme) => `1px solid ${theme.palette.divider}`,
|
borderBottom: (theme) => `1px solid ${theme.palette.divider}`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Box>
|
<Box>
|
||||||
<Text id="vendor-detail-drawer-title" variant="title" as="h2" className="font-semibold">
|
<Typography
|
||||||
{technician?.contactName || vendor?.contactName || roster?.name || "Vendor company"}
|
id="vendor-detail-drawer-title"
|
||||||
</Text>
|
variant="subtitle1"
|
||||||
<Text variant="description" tone="muted">
|
component="h2"
|
||||||
{roster?.name || vendor?.companyName || "Vendor details"}
|
className="font-semibold"
|
||||||
</Text>
|
>
|
||||||
|
{roster?.name || vendor?.companyName || "Vendor company"}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
||||||
|
{roster ? `${roster.technicians.length} technician(s)` : "Vendor details"}
|
||||||
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<IconButton aria-label="Close drawer" onClick={onClose} size="small">
|
<IconButton aria-label="Close drawer" onClick={onClose} size="small">
|
||||||
<CloseIcon fontSize="small" />
|
<CloseIcon fontSize="small" />
|
||||||
|
|
@ -108,19 +167,18 @@ function DrawerHeader({
|
||||||
}
|
}
|
||||||
|
|
||||||
function CompanySection({ roster }: { roster: VendorCompanyRoster }) {
|
function CompanySection({ roster }: { roster: VendorCompanyRoster }) {
|
||||||
const address = [roster.address, roster.city, roster.state, roster.zip]
|
const mapsUrl = roster.googleMapsUrl;
|
||||||
.filter(Boolean)
|
|
||||||
.join(", ");
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={1.5}>
|
<Stack spacing={1.5}>
|
||||||
<Field label="Company" value={roster.name} />
|
|
||||||
<Field label="Company Phone" value={roster.companyPhone} />
|
<Field label="Company Phone" value={roster.companyPhone} />
|
||||||
<Field label="Company Email" value={roster.email} />
|
<Field label="Email" value={roster.email} />
|
||||||
<Field label="Address" value={address} />
|
<Field
|
||||||
{Boolean(roster.googleMapsUrl) && (
|
label="Address"
|
||||||
|
value={[roster.address, roster.city, roster.state, roster.zip].filter(Boolean).join(", ")}
|
||||||
|
/>
|
||||||
|
{Boolean(mapsUrl) && (
|
||||||
<Link
|
<Link
|
||||||
href={roster.googleMapsUrl}
|
href={mapsUrl}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="inline-flex items-center gap-1"
|
className="inline-flex items-center gap-1"
|
||||||
|
|
@ -133,79 +191,49 @@ function CompanySection({ roster }: { roster: VendorCompanyRoster }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function TechnicianSection({ technician }: { technician: VendorRosterTechnician }) {
|
function TechniciansSection({ roster }: { roster: VendorCompanyRoster }) {
|
||||||
const trades = splitTrades(technician.tradeSpecialties);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Stack spacing={1.5}>
|
<SectionTitle>Technicians</SectionTitle>
|
||||||
<Field label="Phone" value={technician.phone} />
|
{roster.technicians.length === 0 ? (
|
||||||
<Box>
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>
|
||||||
<Text variant="caption" tone="muted" sx={{ display: "block", mb: 0.75 }}>
|
No technicians assigned to this company.
|
||||||
Trade
|
</Typography>
|
||||||
</Text>
|
) : (
|
||||||
<Stack direction="row" spacing={0.75} sx={{ flexWrap: "wrap" }}>
|
<List disablePadding>
|
||||||
{trades.length > 0 ? (
|
{roster.technicians.map((technician) => (
|
||||||
trades.map((trade, index) => (
|
<TechnicianEntry
|
||||||
<Chip key={`${trade}-${index}`} size="small" variant="outlined" label={trade} />
|
key={String(technician.id ?? technician.contactName)}
|
||||||
))
|
contactName={technician.contactName}
|
||||||
) : (
|
phone={technician.phone}
|
||||||
<Text variant="description">—</Text>
|
email={technician.email}
|
||||||
)}
|
preferredContact={technician.preferredContact}
|
||||||
</Stack>
|
tradeSpecialties={technician.tradeSpecialties}
|
||||||
</Box>
|
isActive={technician.isActive}
|
||||||
<Stack direction="row" spacing={4} sx={{ alignItems: "flex-end" }}>
|
totalJobs={technician.totalJobs}
|
||||||
<Box>
|
|
||||||
<Text variant="title">{technician.totalJobs ?? 0}</Text>
|
|
||||||
<Text variant="caption" tone="muted" sx={{ display: "block" }}>
|
|
||||||
Total Jobs
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Box>
|
|
||||||
<Text variant="caption" tone="muted" sx={{ display: "block", mb: 0.5 }}>
|
|
||||||
Status
|
|
||||||
</Text>
|
|
||||||
<Chip
|
|
||||||
size="small"
|
|
||||||
label={technician.isActive ? "Active" : "Inactive"}
|
|
||||||
color={technician.isActive ? "success" : "default"}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
))}
|
||||||
</Stack>
|
</List>
|
||||||
</Stack>
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DrawerBody({
|
function DrawerBody({ roster }: { roster: VendorCompanyRoster }) {
|
||||||
roster,
|
|
||||||
technician,
|
|
||||||
}: {
|
|
||||||
roster: VendorCompanyRoster;
|
|
||||||
technician?: VendorRosterTechnician;
|
|
||||||
}) {
|
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3} className="flex-1 overflow-y-auto" sx={{ p: 2.5 }}>
|
<Stack spacing={3} className="flex-1 overflow-y-auto" sx={{ px: 3, py: 3 }}>
|
||||||
<Box>
|
<SectionTitle>Company</SectionTitle>
|
||||||
<SectionTitle>Company</SectionTitle>
|
<CompanySection roster={roster} />
|
||||||
<CompanySection roster={roster} />
|
|
||||||
</Box>
|
|
||||||
<Divider />
|
<Divider />
|
||||||
{technician ? (
|
<TechniciansSection roster={roster} />
|
||||||
<TechnicianSection technician={technician} />
|
|
||||||
) : (
|
|
||||||
<Text variant="description" tone="muted">
|
|
||||||
No technicians assigned to this company.
|
|
||||||
</Text>
|
|
||||||
)}
|
|
||||||
{Boolean(roster.notes) && (
|
{Boolean(roster.notes) && (
|
||||||
<>
|
<>
|
||||||
<Divider />
|
<Divider />
|
||||||
<Box>
|
<Box>
|
||||||
<SectionTitle>Notes</SectionTitle>
|
<SectionTitle>Notes</SectionTitle>
|
||||||
<Text variant="description" sx={{ whiteSpace: "pre-wrap" }}>
|
<Typography variant="body2" sx={{ whiteSpace: "pre-wrap" }}>
|
||||||
{roster.notes}
|
{roster.notes}
|
||||||
</Text>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
@ -218,8 +246,8 @@ function DrawerActions({ onEdit }: { onEdit: () => void }) {
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
sx={{
|
sx={{
|
||||||
px: 2.5,
|
px: 3,
|
||||||
py: 1.5,
|
py: 2,
|
||||||
borderTop: (theme) => `1px solid ${theme.palette.divider}`,
|
borderTop: (theme) => `1px solid ${theme.palette.divider}`,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent: "flex-end",
|
justifyContent: "flex-end",
|
||||||
|
|
@ -232,143 +260,8 @@ function DrawerActions({ onEdit }: { onEdit: () => void }) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function DrawerEditor({
|
export function VendorDetailDrawer({ open, vendor, onClose }: VendorDetailDrawerProps) {
|
||||||
vendor,
|
const navigate = useNavigate();
|
||||||
onClose,
|
|
||||||
onSaved,
|
|
||||||
onRequestDeactivation = () => undefined,
|
|
||||||
}: {
|
|
||||||
vendor: VendorListItem;
|
|
||||||
onClose: () => void;
|
|
||||||
onSaved: () => void;
|
|
||||||
onRequestDeactivation: (vendor: VendorListItem) => void;
|
|
||||||
}) {
|
|
||||||
const form = useVendorRosterForm({
|
|
||||||
mode: "update",
|
|
||||||
vendorId: vendor.id ?? undefined,
|
|
||||||
companyId: vendor.id == null ? (vendor.companyId ?? undefined) : undefined,
|
|
||||||
onSuccess: onSaved,
|
|
||||||
});
|
|
||||||
const roster = form.roster;
|
|
||||||
const technicians = useWatch({ control: form.control, name: "technicians" }) ?? [];
|
|
||||||
const selectedIndex = technicians.findIndex(
|
|
||||||
(technician) => technician.id != null && String(technician.id) === String(vendor.id),
|
|
||||||
);
|
|
||||||
const selectedTotalJobs =
|
|
||||||
roster?.technicians.find(
|
|
||||||
(technician) => technician.id != null && String(technician.id) === String(vendor.id),
|
|
||||||
)?.totalJobs ?? vendor.totalJobs;
|
|
||||||
|
|
||||||
if (form.isLoading) {
|
|
||||||
return <CircularProgress size={28} sx={{ m: "auto" }} />;
|
|
||||||
}
|
|
||||||
if (form.isError || !roster) {
|
|
||||||
return (
|
|
||||||
<Alert severity="error" sx={{ m: 2 }}>
|
|
||||||
Failed to load vendor company. Try again.
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Box
|
|
||||||
component="form"
|
|
||||||
id="vendor-drawer-edit-form"
|
|
||||||
onSubmit={form.handleSubmit(form.submit)}
|
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
|
||||||
>
|
|
||||||
<Stack spacing={2} className="flex-1 overflow-y-auto" sx={{ p: 2.5 }}>
|
|
||||||
{form.loadErrorMessage !== null && (
|
|
||||||
<VendorRosterLoadErrorAlert message={form.loadErrorMessage} onRetry={form.retryLoad} />
|
|
||||||
)}
|
|
||||||
{form.conflict !== null && (
|
|
||||||
<VendorRosterConflictAlert conflict={form.conflict} onReload={form.reload} />
|
|
||||||
)}
|
|
||||||
<VendorRosterFormFields
|
|
||||||
control={form.control}
|
|
||||||
errors={form.errors}
|
|
||||||
tradeOptions={form.trades}
|
|
||||||
showTechnicianStatus={false}
|
|
||||||
/>
|
|
||||||
{selectedIndex >= 0 && (
|
|
||||||
<>
|
|
||||||
<Divider />
|
|
||||||
<Stack direction="row" sx={{ alignItems: "center", justifyContent: "space-between" }}>
|
|
||||||
<Box>
|
|
||||||
<Text variant="title">{selectedTotalJobs}</Text>
|
|
||||||
<Text variant="caption" tone="muted">
|
|
||||||
Total Jobs
|
|
||||||
</Text>
|
|
||||||
</Box>
|
|
||||||
<Controller
|
|
||||||
control={form.control}
|
|
||||||
name={`technicians.${selectedIndex}.isActive`}
|
|
||||||
render={({ field }) => (
|
|
||||||
<Stack direction="row" spacing={1} sx={{ alignItems: "center" }}>
|
|
||||||
<Text variant="description">{field.value ? "Active" : "Inactive"}</Text>
|
|
||||||
<Switch
|
|
||||||
checked={Boolean(field.value)}
|
|
||||||
slotProps={{ input: { "aria-label": "Active status" } }}
|
|
||||||
onChange={(_event, checked) => {
|
|
||||||
if (field.value && !checked) onRequestDeactivation(vendor);
|
|
||||||
else field.onChange(checked);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</Stack>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Stack>
|
|
||||||
<Stack
|
|
||||||
direction="row"
|
|
||||||
spacing={1.5}
|
|
||||||
sx={{ p: 2, borderTop: 1, borderColor: "divider", justifyContent: "flex-end" }}
|
|
||||||
>
|
|
||||||
<Button onClick={onClose} disabled={form.isSaving}>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" variant="contained" disabled={form.isSaving || !form.isValid}>
|
|
||||||
{form.isSaving ? "Saving..." : "Save changes"}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveTechnician(
|
|
||||||
roster: VendorCompanyRoster | undefined,
|
|
||||||
vendor: VendorListItem | null,
|
|
||||||
): VendorRosterTechnician | undefined {
|
|
||||||
if (!roster || !vendor) return undefined;
|
|
||||||
|
|
||||||
const match = roster.technicians.find(
|
|
||||||
(technician) =>
|
|
||||||
vendor.id != null && technician.id != null && String(technician.id) === String(vendor.id),
|
|
||||||
);
|
|
||||||
if (match) return match;
|
|
||||||
if (!vendor.contactName) return undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: vendor.id ?? undefined,
|
|
||||||
contactName: vendor.contactName,
|
|
||||||
phone: vendor.phone,
|
|
||||||
email: vendor.email,
|
|
||||||
tradeSpecialties: vendor.tradeSpecialties,
|
|
||||||
isActive: vendor.isActive,
|
|
||||||
totalJobs: vendor.totalJobs,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function VendorDetailDrawer({
|
|
||||||
open,
|
|
||||||
vendor,
|
|
||||||
startInEdit = false,
|
|
||||||
onRequestDeactivation = () => undefined,
|
|
||||||
onClose,
|
|
||||||
}: VendorDetailDrawerProps) {
|
|
||||||
const [isEditing, setIsEditing] = useState(startInEdit);
|
|
||||||
const vendorId = vendor?.id;
|
const vendorId = vendor?.id;
|
||||||
const companyId = vendor?.companyId;
|
const companyId = vendor?.companyId;
|
||||||
const hasVendorId = vendorId != null;
|
const hasVendorId = vendorId != null;
|
||||||
|
|
@ -381,30 +274,25 @@ export function VendorDetailDrawer({
|
||||||
!hasVendorId ? (companyId ?? undefined) : undefined,
|
!hasVendorId ? (companyId ?? undefined) : undefined,
|
||||||
);
|
);
|
||||||
|
|
||||||
const selectedTechnician = resolveTechnician(roster, vendor);
|
const editHref = hasVendorId
|
||||||
|
? `/vendors/edit/${vendorId}`
|
||||||
useEffect(() => {
|
: `/vendors/company/${companyId ?? ""}`;
|
||||||
if (open) setIsEditing(startInEdit);
|
|
||||||
}, [open, startInEdit, vendor]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open) return;
|
if (!open) return;
|
||||||
|
|
||||||
const closeOnEscape = (event: KeyboardEvent) => {
|
const closeOnEscape = (event: KeyboardEvent) => {
|
||||||
if (event.key === "Escape" && !isEditing) onClose();
|
if (event.key === "Escape") onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("keydown", closeOnEscape);
|
window.addEventListener("keydown", closeOnEscape);
|
||||||
return () => window.removeEventListener("keydown", closeOnEscape);
|
return () => window.removeEventListener("keydown", closeOnEscape);
|
||||||
}, [isEditing, onClose, open]);
|
}, [onClose, open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
open={open}
|
open={open}
|
||||||
onClose={(_event, reason) => {
|
onClose={onClose}
|
||||||
if (reason === "escapeKeyDown" && isEditing) return;
|
|
||||||
onClose();
|
|
||||||
}}
|
|
||||||
anchor="right"
|
anchor="right"
|
||||||
aria-labelledby="vendor-detail-drawer-title"
|
aria-labelledby="vendor-detail-drawer-title"
|
||||||
ModalProps={{ keepMounted: false }}
|
ModalProps={{ keepMounted: false }}
|
||||||
|
|
@ -416,21 +304,9 @@ export function VendorDetailDrawer({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Stack className="flex h-full flex-col">
|
<Stack className="flex h-full flex-col">
|
||||||
<DrawerHeader
|
<DrawerHeader roster={roster} vendor={vendor} onClose={onClose} />
|
||||||
roster={roster}
|
|
||||||
vendor={vendor}
|
|
||||||
technician={selectedTechnician}
|
|
||||||
onClose={onClose}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{isEditing && vendor ? (
|
{isLoading ? (
|
||||||
<DrawerEditor
|
|
||||||
vendor={vendor}
|
|
||||||
onClose={onClose}
|
|
||||||
onSaved={() => setIsEditing(false)}
|
|
||||||
onRequestDeactivation={onRequestDeactivation}
|
|
||||||
/>
|
|
||||||
) : isLoading ? (
|
|
||||||
<Box className="flex flex-1 items-center justify-center">
|
<Box className="flex flex-1 items-center justify-center">
|
||||||
<CircularProgress size={28} />
|
<CircularProgress size={28} />
|
||||||
</Box>
|
</Box>
|
||||||
|
|
@ -440,14 +316,14 @@ export function VendorDetailDrawer({
|
||||||
</Alert>
|
</Alert>
|
||||||
) : roster ? (
|
) : roster ? (
|
||||||
<>
|
<>
|
||||||
<DrawerBody roster={roster} technician={selectedTechnician} />
|
<DrawerBody roster={roster} />
|
||||||
<DrawerActions onEdit={() => setIsEditing(true)} />
|
<DrawerActions onEdit={() => navigate(editHref)} />
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<Box className="flex flex-1 items-center justify-center">
|
<Box className="flex flex-1 items-center justify-center">
|
||||||
<Text variant="description" tone="muted">
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>
|
||||||
No vendor selected.
|
No vendor selected.
|
||||||
</Text>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
||||||
|
|
@ -1,252 +0,0 @@
|
||||||
import type { Dispatch, ReactNode, SetStateAction } from "react";
|
|
||||||
import BusinessOutlinedIcon from "@mui/icons-material/BusinessOutlined";
|
|
||||||
import BuildOutlinedIcon from "@mui/icons-material/BuildOutlined";
|
|
||||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
|
||||||
import LocationOnOutlinedIcon from "@mui/icons-material/LocationOnOutlined";
|
|
||||||
import TagOutlinedIcon from "@mui/icons-material/TagOutlined";
|
|
||||||
import {
|
|
||||||
Accordion,
|
|
||||||
AccordionDetails,
|
|
||||||
AccordionSummary,
|
|
||||||
Autocomplete,
|
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
Checkbox,
|
|
||||||
Chip,
|
|
||||||
Stack,
|
|
||||||
TextField,
|
|
||||||
Typography,
|
|
||||||
} from "@mui/material";
|
|
||||||
import type {
|
|
||||||
VendorFacets,
|
|
||||||
VendorFacetCompany,
|
|
||||||
VendorFacetJobBucket,
|
|
||||||
VendorFacetLocation,
|
|
||||||
} from "@/domain/vendors/types/vendor";
|
|
||||||
import type { VendorFilters } from "./vendor-filters";
|
|
||||||
|
|
||||||
type DraftSetter = Dispatch<SetStateAction<VendorFilters>>;
|
|
||||||
|
|
||||||
function FilterSection({
|
|
||||||
title,
|
|
||||||
icon,
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
title: string;
|
|
||||||
icon: ReactNode;
|
|
||||||
children: ReactNode;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<Accordion disableGutters elevation={0} square sx={{ borderBottom: 1, borderColor: "divider" }}>
|
|
||||||
<AccordionSummary expandIcon={<ExpandMoreIcon />} aria-controls={`${title}-filters-content`}>
|
|
||||||
<Stack direction="row" spacing={1.5} sx={{ alignItems: "center" }}>
|
|
||||||
<Box sx={{ color: "primary.main", display: "flex" }}>{icon}</Box>
|
|
||||||
<Typography variant="subtitle1" className="font-semibold">
|
|
||||||
{title}
|
|
||||||
</Typography>
|
|
||||||
</Stack>
|
|
||||||
</AccordionSummary>
|
|
||||||
<AccordionDetails id={`${title}-filters-content`} sx={{ pt: 0, pb: 2.5 }}>
|
|
||||||
{children}
|
|
||||||
</AccordionDetails>
|
|
||||||
</Accordion>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function CompanyFilter({
|
|
||||||
options,
|
|
||||||
draft,
|
|
||||||
setDraft,
|
|
||||||
}: {
|
|
||||||
options: VendorFacetCompany[];
|
|
||||||
draft: VendorFilters;
|
|
||||||
setDraft: DraftSetter;
|
|
||||||
}) {
|
|
||||||
const allSelected = draft.companies.length === options.length && options.length > 0;
|
|
||||||
return (
|
|
||||||
<FilterSection title="Company" icon={<BusinessOutlinedIcon />}>
|
|
||||||
<Stack direction="row" sx={{ alignItems: "center", justifyContent: "space-between" }}>
|
|
||||||
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
|
||||||
Select vendor companies
|
|
||||||
</Typography>
|
|
||||||
<Button
|
|
||||||
size="small"
|
|
||||||
onClick={() =>
|
|
||||||
setDraft((current) => ({
|
|
||||||
...current,
|
|
||||||
companies: allSelected ? [] : options.map((company) => company.name),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{allSelected ? "Clear all" : "Select all"}
|
|
||||||
</Button>
|
|
||||||
</Stack>
|
|
||||||
<Autocomplete
|
|
||||||
multiple
|
|
||||||
size="small"
|
|
||||||
options={options}
|
|
||||||
getOptionLabel={(option) => (typeof option === "string" ? option : option.name)}
|
|
||||||
isOptionEqualToValue={(option, value) =>
|
|
||||||
typeof option === "string" || typeof value === "string"
|
|
||||||
? option === value
|
|
||||||
: option.name === value.name
|
|
||||||
}
|
|
||||||
value={options.filter((option) => draft.companies.includes(option.name))}
|
|
||||||
onChange={(_event, value) => {
|
|
||||||
const next = (value as (string | VendorFacetCompany)[]).map((entry) =>
|
|
||||||
typeof entry === "string" ? entry : entry.name,
|
|
||||||
);
|
|
||||||
setDraft((current) => ({ ...current, companies: next }));
|
|
||||||
}}
|
|
||||||
renderOption={(props, option, { selected }) => {
|
|
||||||
const { key, ...optionProps } = props;
|
|
||||||
return (
|
|
||||||
<li key={key} {...optionProps}>
|
|
||||||
<Checkbox checked={selected} size="small" sx={{ mr: 1 }} />
|
|
||||||
{option.name}
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
}}
|
|
||||||
renderValue={(value, getItemProps) =>
|
|
||||||
value.map((option, index) => {
|
|
||||||
const label = typeof option === "string" ? option : option.name;
|
|
||||||
const { key, ...chipProps } = getItemProps({ index });
|
|
||||||
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
renderInput={(params) => (
|
|
||||||
<TextField
|
|
||||||
{...params}
|
|
||||||
placeholder={draft.companies.length === 0 ? "All companies" : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FilterSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function TradeFilter({ options, draft, setDraft }: FilterProps<string>) {
|
|
||||||
return (
|
|
||||||
<FilterSection title="Trade" icon={<BuildOutlinedIcon />}>
|
|
||||||
<Autocomplete
|
|
||||||
multiple
|
|
||||||
size="small"
|
|
||||||
options={options}
|
|
||||||
value={draft.trades}
|
|
||||||
onChange={(_event, value) =>
|
|
||||||
setDraft((current) => ({ ...current, trades: value as string[] }))
|
|
||||||
}
|
|
||||||
renderValue={(value, getItemProps) =>
|
|
||||||
value.map((option, index) => {
|
|
||||||
const { key, ...chipProps } = getItemProps({ index });
|
|
||||||
return <Chip key={key} size="small" label={option} {...chipProps} />;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
renderInput={(params) => (
|
|
||||||
<TextField {...params} placeholder={draft.trades.length === 0 ? "All trades" : ""} />
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FilterSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface FilterProps<T> {
|
|
||||||
options: T[];
|
|
||||||
draft: VendorFilters;
|
|
||||||
setDraft: DraftSetter;
|
|
||||||
}
|
|
||||||
|
|
||||||
function LocationFilter({ options, draft, setDraft }: FilterProps<VendorFacetLocation>) {
|
|
||||||
return (
|
|
||||||
<FilterSection title="Location" icon={<LocationOnOutlinedIcon />}>
|
|
||||||
<Autocomplete
|
|
||||||
multiple
|
|
||||||
size="small"
|
|
||||||
options={options}
|
|
||||||
getOptionLabel={(option) => (typeof option === "string" ? option : option.label)}
|
|
||||||
isOptionEqualToValue={(option, value) =>
|
|
||||||
typeof option === "string" || typeof value === "string"
|
|
||||||
? option === value
|
|
||||||
: option.label === value.label
|
|
||||||
}
|
|
||||||
value={options.filter((option) => draft.locations.includes(option.label))}
|
|
||||||
onChange={(_event, value) => {
|
|
||||||
const next = (value as (string | VendorFacetLocation)[]).map((entry) =>
|
|
||||||
typeof entry === "string" ? entry : entry.label,
|
|
||||||
);
|
|
||||||
setDraft((current) => ({ ...current, locations: next }));
|
|
||||||
}}
|
|
||||||
renderValue={(value, getItemProps) =>
|
|
||||||
value.map((option, index) => {
|
|
||||||
const label = typeof option === "string" ? option : option.label;
|
|
||||||
const { key, ...chipProps } = getItemProps({ index });
|
|
||||||
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
renderInput={(params) => (
|
|
||||||
<TextField
|
|
||||||
{...params}
|
|
||||||
placeholder={draft.locations.length === 0 ? "All locations" : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FilterSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function JobCountFilter({ options, draft, setDraft }: FilterProps<VendorFacetJobBucket>) {
|
|
||||||
return (
|
|
||||||
<FilterSection title="Total Jobs" icon={<TagOutlinedIcon />}>
|
|
||||||
<Autocomplete
|
|
||||||
multiple
|
|
||||||
size="small"
|
|
||||||
options={options}
|
|
||||||
getOptionLabel={(option) => (typeof option === "string" ? option : option.label)}
|
|
||||||
isOptionEqualToValue={(option, value) =>
|
|
||||||
typeof option === "string" || typeof value === "string"
|
|
||||||
? option === value
|
|
||||||
: option.id === value.id
|
|
||||||
}
|
|
||||||
value={options.filter((option) => draft.jobBuckets.includes(option.id))}
|
|
||||||
onChange={(_event, value) => {
|
|
||||||
const next = (value as (string | VendorFacetJobBucket)[]).map((entry) =>
|
|
||||||
typeof entry === "string" ? entry : entry.id,
|
|
||||||
);
|
|
||||||
setDraft((current) => ({ ...current, jobBuckets: next }));
|
|
||||||
}}
|
|
||||||
renderValue={(value, getItemProps) =>
|
|
||||||
value.map((option, index) => {
|
|
||||||
const label = typeof option === "string" ? option : option.label;
|
|
||||||
const { key, ...chipProps } = getItemProps({ index });
|
|
||||||
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
|
||||||
})
|
|
||||||
}
|
|
||||||
renderInput={(params) => (
|
|
||||||
<TextField
|
|
||||||
{...params}
|
|
||||||
placeholder={draft.jobBuckets.length === 0 ? "All job counts" : ""}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</FilterSection>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function VendorFilterOptions({
|
|
||||||
facets,
|
|
||||||
draft,
|
|
||||||
setDraft,
|
|
||||||
}: {
|
|
||||||
facets: VendorFacets | undefined;
|
|
||||||
draft: VendorFilters;
|
|
||||||
setDraft: DraftSetter;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<CompanyFilter options={facets?.companies ?? []} draft={draft} setDraft={setDraft} />
|
|
||||||
<TradeFilter options={facets?.trades ?? []} draft={draft} setDraft={setDraft} />
|
|
||||||
<LocationFilter options={facets?.locations ?? []} draft={draft} setDraft={setDraft} />
|
|
||||||
<JobCountFilter options={facets?.jobBuckets ?? []} draft={draft} setDraft={setDraft} />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,32 @@
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState, type ReactNode } from "react";
|
||||||
|
import BusinessOutlinedIcon from "@mui/icons-material/BusinessOutlined";
|
||||||
|
import BuildOutlinedIcon from "@mui/icons-material/BuildOutlined";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import CloseIcon from "@mui/icons-material/Close";
|
||||||
import { Box, Button, Chip, Drawer, IconButton, Stack, Typography } from "@mui/material";
|
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||||
import { VendorFilterOptions } from "./vendor-filter-options";
|
import LocationOnOutlinedIcon from "@mui/icons-material/LocationOnOutlined";
|
||||||
|
import TagOutlinedIcon from "@mui/icons-material/TagOutlined";
|
||||||
|
import {
|
||||||
|
Accordion,
|
||||||
|
AccordionDetails,
|
||||||
|
AccordionSummary,
|
||||||
|
Autocomplete,
|
||||||
|
Box,
|
||||||
|
Button,
|
||||||
|
Checkbox,
|
||||||
|
Chip,
|
||||||
|
Drawer,
|
||||||
|
IconButton,
|
||||||
|
Stack,
|
||||||
|
TextField,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
|
import type {
|
||||||
|
VendorFacets,
|
||||||
|
VendorFacetCompany,
|
||||||
|
VendorFacetJobBucket,
|
||||||
|
VendorFacetLocation,
|
||||||
|
} from "@/domain/vendors/types/vendor";
|
||||||
import { emptyVendorFilters, type VendorFilters } from "./vendor-filters";
|
import { emptyVendorFilters, type VendorFilters } from "./vendor-filters";
|
||||||
import type { VendorFacets } from "@/domain/vendors/types/vendor";
|
|
||||||
|
|
||||||
interface VendorFiltersDrawerProps {
|
interface VendorFiltersDrawerProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
|
@ -15,6 +38,32 @@ interface VendorFiltersDrawerProps {
|
||||||
|
|
||||||
const DRAWER_WIDTH = 360;
|
const DRAWER_WIDTH = 360;
|
||||||
|
|
||||||
|
function FilterSection({
|
||||||
|
title,
|
||||||
|
icon,
|
||||||
|
children,
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
icon: ReactNode;
|
||||||
|
children: ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<Accordion disableGutters elevation={0} square sx={{ borderBottom: 1, borderColor: "divider" }}>
|
||||||
|
<AccordionSummary expandIcon={<ExpandMoreIcon />} aria-controls={`${title}-filters-content`}>
|
||||||
|
<Stack direction="row" spacing={1.5} sx={{ alignItems: "center" }}>
|
||||||
|
<Box sx={{ color: "primary.main", display: "flex" }}>{icon}</Box>
|
||||||
|
<Typography variant="subtitle1" className="font-semibold">
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</AccordionSummary>
|
||||||
|
<AccordionDetails id={`${title}-filters-content`} sx={{ pt: 0, pb: 2.5 }}>
|
||||||
|
{children}
|
||||||
|
</AccordionDetails>
|
||||||
|
</Accordion>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
export function VendorFiltersDrawer({
|
export function VendorFiltersDrawer({
|
||||||
open,
|
open,
|
||||||
onClose,
|
onClose,
|
||||||
|
|
@ -25,12 +74,23 @@ export function VendorFiltersDrawer({
|
||||||
const [draft, setDraft] = useState<VendorFilters>(appliedFilters);
|
const [draft, setDraft] = useState<VendorFilters>(appliedFilters);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (open) setDraft(appliedFilters);
|
if (open) {
|
||||||
|
setDraft(appliedFilters);
|
||||||
|
}
|
||||||
}, [open, appliedFilters]);
|
}, [open, appliedFilters]);
|
||||||
|
|
||||||
|
const companyOptions = useMemo(() => facets?.companies ?? [], [facets]);
|
||||||
|
const tradeOptions = useMemo(() => facets?.trades ?? [], [facets]);
|
||||||
|
const locationOptions = useMemo(() => facets?.locations ?? [], [facets]);
|
||||||
|
const jobBucketOptions = useMemo(() => facets?.jobBuckets ?? [], [facets]);
|
||||||
|
|
||||||
const activeCount =
|
const activeCount =
|
||||||
draft.companies.length + draft.trades.length + draft.locations.length + draft.jobBuckets.length;
|
draft.companies.length + draft.trades.length + draft.locations.length + draft.jobBuckets.length;
|
||||||
|
|
||||||
|
const handleClear = () => {
|
||||||
|
setDraft(emptyVendorFilters);
|
||||||
|
};
|
||||||
|
|
||||||
const handleApply = () => {
|
const handleApply = () => {
|
||||||
onApply(draft);
|
onApply(draft);
|
||||||
onClose();
|
onClose();
|
||||||
|
|
@ -73,7 +133,165 @@ export function VendorFiltersDrawer({
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
||||||
<Box className="flex-1 overflow-y-auto" sx={{ px: 2.5 }}>
|
<Box className="flex-1 overflow-y-auto" sx={{ px: 2.5 }}>
|
||||||
<VendorFilterOptions facets={facets} draft={draft} setDraft={setDraft} />
|
<FilterSection title="Company" icon={<BusinessOutlinedIcon />}>
|
||||||
|
<Stack direction="row" sx={{ alignItems: "center", justifyContent: "space-between" }}>
|
||||||
|
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
||||||
|
Select vendor companies
|
||||||
|
</Typography>
|
||||||
|
<Button
|
||||||
|
size="small"
|
||||||
|
onClick={() =>
|
||||||
|
setDraft((current) => ({
|
||||||
|
...current,
|
||||||
|
companies:
|
||||||
|
current.companies.length === companyOptions.length
|
||||||
|
? []
|
||||||
|
: companyOptions.map((company) => company.name),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{draft.companies.length === companyOptions.length && companyOptions.length > 0
|
||||||
|
? "Clear all"
|
||||||
|
: "Select all"}
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
size="small"
|
||||||
|
options={companyOptions}
|
||||||
|
getOptionLabel={(option) => (typeof option === "string" ? option : option.name)}
|
||||||
|
isOptionEqualToValue={(option, value) =>
|
||||||
|
typeof option === "string" || typeof value === "string"
|
||||||
|
? option === value
|
||||||
|
: option.name === value.name
|
||||||
|
}
|
||||||
|
value={companyOptions.filter((option) => draft.companies.includes(option.name))}
|
||||||
|
onChange={(_event, value) => {
|
||||||
|
const next = (value as (string | VendorFacetCompany)[]).map((entry) =>
|
||||||
|
typeof entry === "string" ? entry : entry.name,
|
||||||
|
);
|
||||||
|
setDraft((current) => ({ ...current, companies: next }));
|
||||||
|
}}
|
||||||
|
renderOption={(props, option, { selected }) => {
|
||||||
|
const { key, ...optionProps } = props;
|
||||||
|
return (
|
||||||
|
<li key={key} {...optionProps}>
|
||||||
|
<Checkbox checked={selected} size="small" sx={{ mr: 1 }} />
|
||||||
|
{option.name}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
}}
|
||||||
|
renderValue={(value, getItemProps) =>
|
||||||
|
value.map((option, index) => {
|
||||||
|
const label = typeof option === "string" ? option : option.name;
|
||||||
|
const tagProps = getItemProps({ index });
|
||||||
|
const { key, ...chipProps } = tagProps;
|
||||||
|
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={draft.companies.length === 0 ? "All companies" : ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FilterSection>
|
||||||
|
|
||||||
|
<FilterSection title="Trade" icon={<BuildOutlinedIcon />}>
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
size="small"
|
||||||
|
options={tradeOptions}
|
||||||
|
value={draft.trades}
|
||||||
|
onChange={(_event, value) =>
|
||||||
|
setDraft((current) => ({ ...current, trades: value as string[] }))
|
||||||
|
}
|
||||||
|
renderValue={(value, getItemProps) =>
|
||||||
|
value.map((option, index) => {
|
||||||
|
const tagProps = getItemProps({ index });
|
||||||
|
const { key, ...chipProps } = tagProps;
|
||||||
|
return <Chip key={key} size="small" label={option} {...chipProps} />;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={draft.trades.length === 0 ? "All trades" : ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FilterSection>
|
||||||
|
|
||||||
|
<FilterSection title="Location" icon={<LocationOnOutlinedIcon />}>
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
size="small"
|
||||||
|
options={locationOptions}
|
||||||
|
getOptionLabel={(option) => (typeof option === "string" ? option : option.label)}
|
||||||
|
isOptionEqualToValue={(option, value) =>
|
||||||
|
typeof option === "string" || typeof value === "string"
|
||||||
|
? option === value
|
||||||
|
: option.label === value.label
|
||||||
|
}
|
||||||
|
value={locationOptions.filter((option) => draft.locations.includes(option.label))}
|
||||||
|
onChange={(_event, value) => {
|
||||||
|
const next = (value as (string | VendorFacetLocation)[]).map((entry) =>
|
||||||
|
typeof entry === "string" ? entry : entry.label,
|
||||||
|
);
|
||||||
|
setDraft((current) => ({ ...current, locations: next }));
|
||||||
|
}}
|
||||||
|
renderValue={(value, getItemProps) =>
|
||||||
|
value.map((option, index) => {
|
||||||
|
const label = typeof option === "string" ? option : option.label;
|
||||||
|
const tagProps = getItemProps({ index });
|
||||||
|
const { key, ...chipProps } = tagProps;
|
||||||
|
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={draft.locations.length === 0 ? "All locations" : ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FilterSection>
|
||||||
|
|
||||||
|
<FilterSection title="Total Jobs" icon={<TagOutlinedIcon />}>
|
||||||
|
<Autocomplete
|
||||||
|
multiple
|
||||||
|
size="small"
|
||||||
|
options={jobBucketOptions}
|
||||||
|
getOptionLabel={(option) => (typeof option === "string" ? option : option.label)}
|
||||||
|
isOptionEqualToValue={(option, value) =>
|
||||||
|
typeof option === "string" || typeof value === "string"
|
||||||
|
? option === value
|
||||||
|
: option.id === value.id
|
||||||
|
}
|
||||||
|
value={jobBucketOptions.filter((option) => draft.jobBuckets.includes(option.id))}
|
||||||
|
onChange={(_event, value) => {
|
||||||
|
const next = (value as (string | VendorFacetJobBucket)[]).map((entry) =>
|
||||||
|
typeof entry === "string" ? entry : entry.id,
|
||||||
|
);
|
||||||
|
setDraft((current) => ({ ...current, jobBuckets: next }));
|
||||||
|
}}
|
||||||
|
renderValue={(value, getItemProps) =>
|
||||||
|
value.map((option, index) => {
|
||||||
|
const label = typeof option === "string" ? option : option.label;
|
||||||
|
const tagProps = getItemProps({ index });
|
||||||
|
const { key, ...chipProps } = tagProps;
|
||||||
|
return <Chip key={key} size="small" label={label} {...chipProps} />;
|
||||||
|
})
|
||||||
|
}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField
|
||||||
|
{...params}
|
||||||
|
placeholder={draft.jobBuckets.length === 0 ? "All job counts" : ""}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FilterSection>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Stack
|
<Stack
|
||||||
|
|
@ -85,16 +303,11 @@ export function VendorFiltersDrawer({
|
||||||
borderTop: (theme) => `1px solid ${theme.palette.divider}`,
|
borderTop: (theme) => `1px solid ${theme.palette.divider}`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Button
|
<Button variant="outlined" onClick={handleClear} disabled={activeCount === 0} fullWidth>
|
||||||
variant="outlined"
|
|
||||||
onClick={() => setDraft(emptyVendorFilters)}
|
|
||||||
disabled={activeCount === 0}
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
Clear all
|
Clear all
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant="contained" onClick={handleApply} fullWidth>
|
<Button variant="contained" onClick={handleApply} fullWidth>
|
||||||
Apply filters
|
Apply
|
||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ interface VendorRosterFormFieldsProps {
|
||||||
selectedCompanyId?: string | number | null;
|
selectedCompanyId?: string | number | null;
|
||||||
onSelectCompany?: (company: VendorFacetCompany | null) => Promise<void>;
|
onSelectCompany?: (company: VendorFacetCompany | null) => Promise<void>;
|
||||||
onClearSelectedCompany?: (nextName?: string) => void;
|
onClearSelectedCompany?: (nextName?: string) => void;
|
||||||
showTechnicianStatus?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function CompanyNameField({
|
function CompanyNameField({
|
||||||
|
|
@ -55,7 +54,6 @@ function CompanyNameField({
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Company"
|
label="Company"
|
||||||
placeholder="Start typing a company…"
|
|
||||||
required
|
required
|
||||||
error={Boolean(errors.name)}
|
error={Boolean(errors.name)}
|
||||||
helperText={errors.name?.message}
|
helperText={errors.name?.message}
|
||||||
|
|
@ -100,9 +98,8 @@ function CompanyNameField({
|
||||||
{...params}
|
{...params}
|
||||||
label="Company"
|
label="Company"
|
||||||
required
|
required
|
||||||
placeholder="Start typing a company…"
|
|
||||||
error={Boolean(errors.name)}
|
error={Boolean(errors.name)}
|
||||||
helperText={errors.name?.message}
|
helperText={errors.name?.message ?? "Choose an existing company or enter a new one"}
|
||||||
inputRef={field.ref}
|
inputRef={field.ref}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -122,7 +119,10 @@ function CompanyFields({
|
||||||
}: VendorRosterFormFieldsProps) {
|
}: VendorRosterFormFieldsProps) {
|
||||||
return (
|
return (
|
||||||
<Box>
|
<Box>
|
||||||
<Stack spacing={2}>
|
<Typography variant="subtitle2" className="font-semibold uppercase">
|
||||||
|
Company
|
||||||
|
</Typography>
|
||||||
|
<Stack spacing={2} className="mt-2">
|
||||||
<CompanyNameField
|
<CompanyNameField
|
||||||
control={control}
|
control={control}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
|
|
@ -138,13 +138,13 @@ function CompanyFields({
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Company Phone (optional)"
|
label="Company Phone"
|
||||||
placeholder="(214) 555-0100"
|
placeholder="(XXX) XXX-XXXX"
|
||||||
inputMode="tel"
|
inputMode="tel"
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
onChange={(event) => field.onChange(formatNorthAmericanPhone(event.target.value))}
|
onChange={(event) => field.onChange(formatNorthAmericanPhone(event.target.value))}
|
||||||
error={Boolean(errors.companyPhone)}
|
error={Boolean(errors.companyPhone)}
|
||||||
helperText={errors.companyPhone?.message}
|
helperText={errors.companyPhone?.message ?? "Phone or email required"}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -155,8 +155,7 @@ function CompanyFields({
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Email (optional)"
|
label="Email"
|
||||||
placeholder="dispatch@vendor.com"
|
|
||||||
type="email"
|
type="email"
|
||||||
error={Boolean(errors.email)}
|
error={Boolean(errors.email)}
|
||||||
helperText={errors.email?.message}
|
helperText={errors.email?.message}
|
||||||
|
|
@ -168,16 +167,9 @@ function CompanyFields({
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="address"
|
name="address"
|
||||||
render={({ field }) => (
|
render={({ field }) => <TextField {...field} label="Address" fullWidth />}
|
||||||
<TextField
|
|
||||||
{...field}
|
|
||||||
label="Address (optional)"
|
|
||||||
placeholder="123 Industrial Pkwy, Dallas, TX 75201"
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
<Stack direction={{ xs: "column", sm: "row" }} spacing={2} sx={{ display: "none" }}>
|
<Stack direction={{ xs: "column", sm: "row" }} spacing={2}>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="city"
|
name="city"
|
||||||
|
|
@ -202,10 +194,10 @@ function CompanyFields({
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Google Maps URL (optional)"
|
label="Google Maps URL"
|
||||||
placeholder="https://maps.google.com/…"
|
placeholder="https://maps.google.com/..."
|
||||||
error={Boolean(errors.googleMapsUrl)}
|
error={Boolean(errors.googleMapsUrl)}
|
||||||
helperText={errors.googleMapsUrl?.message}
|
helperText={errors.googleMapsUrl?.message ?? "Must be an HTTPS link"}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
@ -214,14 +206,7 @@ function CompanyFields({
|
||||||
control={control}
|
control={control}
|
||||||
name="notes"
|
name="notes"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField {...field} label="Notes" multiline minRows={2} fullWidth />
|
||||||
{...field}
|
|
||||||
label="Notes (optional)"
|
|
||||||
placeholder="Internal notes, scheduling preferences, certifications…"
|
|
||||||
multiline
|
|
||||||
minRows={2}
|
|
||||||
fullWidth
|
|
||||||
/>
|
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
@ -236,7 +221,6 @@ interface TechnicianRowProps {
|
||||||
onRemove: () => void;
|
onRemove: () => void;
|
||||||
canRemove: boolean;
|
canRemove: boolean;
|
||||||
tradeOptions: string[];
|
tradeOptions: string[];
|
||||||
showStatus: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function TechnicianRow({
|
function TechnicianRow({
|
||||||
|
|
@ -246,13 +230,12 @@ function TechnicianRow({
|
||||||
onRemove,
|
onRemove,
|
||||||
canRemove,
|
canRemove,
|
||||||
tradeOptions,
|
tradeOptions,
|
||||||
showStatus,
|
|
||||||
}: TechnicianRowProps) {
|
}: TechnicianRowProps) {
|
||||||
return (
|
return (
|
||||||
<Stack spacing={2} className="rounded-md border border-solid border-gray-200 p-3">
|
<Stack spacing={2} className="rounded-md border border-solid border-gray-200 p-3">
|
||||||
<Stack direction="row" sx={{ alignItems: "center", justifyContent: "space-between" }}>
|
<Stack direction="row" sx={{ alignItems: "center", justifyContent: "space-between" }}>
|
||||||
<Typography variant="subtitle2" className="font-semibold">
|
<Typography variant="subtitle2" className="font-semibold">
|
||||||
{index + 1} - TECHNICIAN
|
Technician {index + 1}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Tooltip title="Remove technician">
|
<Tooltip title="Remove technician">
|
||||||
<span>
|
<span>
|
||||||
|
|
@ -273,8 +256,7 @@ function TechnicianRow({
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Technician name (optional)"
|
label="Technician Name"
|
||||||
placeholder="Technician name"
|
|
||||||
error={Boolean(error?.contactName)}
|
error={Boolean(error?.contactName)}
|
||||||
helperText={error?.contactName?.message}
|
helperText={error?.contactName?.message}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
|
@ -288,8 +270,8 @@ function TechnicianRow({
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...field}
|
{...field}
|
||||||
label="Technician phone (optional)"
|
label="Technician Phone"
|
||||||
placeholder="(000) 000-0000"
|
placeholder="(XXX) XXX-XXXX"
|
||||||
inputMode="tel"
|
inputMode="tel"
|
||||||
value={field.value ?? ""}
|
value={field.value ?? ""}
|
||||||
onChange={(event) => field.onChange(formatNorthAmericanPhone(event.target.value))}
|
onChange={(event) => field.onChange(formatNorthAmericanPhone(event.target.value))}
|
||||||
|
|
@ -310,29 +292,26 @@ function TechnicianRow({
|
||||||
error={Boolean(error?.email)}
|
error={Boolean(error?.email)}
|
||||||
helperText={error?.email?.message}
|
helperText={error?.email?.message}
|
||||||
fullWidth
|
fullWidth
|
||||||
sx={{ display: "none" }}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<VendorTradeSpecialtiesField control={control} index={index} tradeOptions={tradeOptions} />
|
<VendorTradeSpecialtiesField control={control} index={index} tradeOptions={tradeOptions} />
|
||||||
{showStatus && (
|
<Controller
|
||||||
<Controller
|
control={control}
|
||||||
control={control}
|
name={`technicians.${index}.isActive`}
|
||||||
name={`technicians.${index}.isActive`}
|
render={({ field }) => (
|
||||||
render={({ field }) => (
|
<FormControlLabel
|
||||||
<FormControlLabel
|
control={
|
||||||
control={
|
<Switch
|
||||||
<Switch
|
checked={field.value}
|
||||||
checked={field.value}
|
onChange={(_event, checked) => field.onChange(checked)}
|
||||||
onChange={(_event, checked) => field.onChange(checked)}
|
/>
|
||||||
/>
|
}
|
||||||
}
|
label={field.value ? "Active" : "Inactive"}
|
||||||
label={field.value ? "Active" : "Inactive"}
|
/>
|
||||||
/>
|
)}
|
||||||
)}
|
/>
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
@ -341,12 +320,10 @@ function TechniciansFieldArray({
|
||||||
control,
|
control,
|
||||||
errors,
|
errors,
|
||||||
tradeOptions,
|
tradeOptions,
|
||||||
showStatus,
|
|
||||||
}: {
|
}: {
|
||||||
control: Control<VendorCompanyRosterFormValues>;
|
control: Control<VendorCompanyRosterFormValues>;
|
||||||
errors: FieldErrors<VendorCompanyRosterFormValues>;
|
errors: FieldErrors<VendorCompanyRosterFormValues>;
|
||||||
tradeOptions: string[];
|
tradeOptions: string[];
|
||||||
showStatus: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
const { fields, append, remove } = useFieldArray({ control, name: "technicians" });
|
const { fields, append, remove } = useFieldArray({ control, name: "technicians" });
|
||||||
|
|
||||||
|
|
@ -389,7 +366,6 @@ function TechniciansFieldArray({
|
||||||
onRemove={() => remove(index)}
|
onRemove={() => remove(index)}
|
||||||
canRemove
|
canRemove
|
||||||
tradeOptions={tradeOptions}
|
tradeOptions={tradeOptions}
|
||||||
showStatus={showStatus}
|
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|
@ -399,17 +375,12 @@ function TechniciansFieldArray({
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VendorRosterFormFields(props: VendorRosterFormFieldsProps) {
|
export function VendorRosterFormFields(props: VendorRosterFormFieldsProps) {
|
||||||
const { control, errors, tradeOptions = [], showTechnicianStatus = true } = props;
|
const { control, errors, tradeOptions = [] } = props;
|
||||||
return (
|
return (
|
||||||
<Stack spacing={3}>
|
<Stack spacing={3}>
|
||||||
<CompanyFields {...props} />
|
<CompanyFields {...props} />
|
||||||
<Divider />
|
<Divider />
|
||||||
<TechniciansFieldArray
|
<TechniciansFieldArray control={control} errors={errors} tradeOptions={tradeOptions} />
|
||||||
control={control}
|
|
||||||
errors={errors}
|
|
||||||
tradeOptions={tradeOptions}
|
|
||||||
showStatus={showTechnicianStatus}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
import { Button, Chip, CircularProgress, Stack, TablePagination } from "@mui/material";
|
import FilterListIcon from "@mui/icons-material/FilterList";
|
||||||
import { Plus, SlidersHorizontal } from "lucide-react";
|
import {
|
||||||
import { PageHeader } from "@/components/ui/page-header";
|
Button,
|
||||||
import { SearchInput } from "@/components/ui/search-input";
|
Chip,
|
||||||
import { Text } from "@/components/ui/text";
|
CircularProgress,
|
||||||
import { ToolbarButton } from "@/components/ui/toolbar-button";
|
Stack,
|
||||||
|
TablePagination,
|
||||||
|
TextField,
|
||||||
|
Typography,
|
||||||
|
} from "@mui/material";
|
||||||
|
|
||||||
interface VendorsListToolbarProps {
|
interface VendorsListToolbarProps {
|
||||||
globalCount: number;
|
globalCount: number;
|
||||||
|
|
@ -29,44 +33,52 @@ export function VendorsListToolbar({
|
||||||
onAddVendor,
|
onAddVendor,
|
||||||
}: VendorsListToolbarProps) {
|
}: VendorsListToolbarProps) {
|
||||||
return (
|
return (
|
||||||
<PageHeader
|
<Stack
|
||||||
surface
|
direction={{ xs: "column", md: "row" }}
|
||||||
className="-mx-4 -mt-4"
|
spacing={2}
|
||||||
title="Vendors / Technicians"
|
sx={{
|
||||||
subtitle={`${globalCount} technicians · ${activeCount} active`}
|
alignItems: { xs: "stretch", md: "center" },
|
||||||
actions={
|
justifyContent: "space-between",
|
||||||
<>
|
}}
|
||||||
<SearchInput
|
>
|
||||||
value={search}
|
<Stack direction="row" spacing={2} sx={{ alignItems: "baseline" }}>
|
||||||
onChange={onSearchChange}
|
<Typography variant="h5" component="h1">
|
||||||
placeholder="Search name, company, trade…"
|
Vendors / Technicians
|
||||||
aria-label="Search vendors"
|
</Typography>
|
||||||
inputClassName="h-8 py-0 text-[13px]"
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>
|
||||||
/>
|
{globalCount} vendor entries · {activeCount} active
|
||||||
<ToolbarButton
|
</Typography>
|
||||||
variant="outline"
|
{isFetching && !isLoading && <CircularProgress size={16} />}
|
||||||
icon={<SlidersHorizontal size={16} />}
|
</Stack>
|
||||||
onClick={onOpenFilters}
|
|
||||||
aria-label="Open vendor filters"
|
<Stack
|
||||||
badge={appliedFilterCount}
|
direction={{ xs: "column", sm: "row" }}
|
||||||
className="w-[88.609375px] text-[13px]"
|
spacing={2}
|
||||||
>
|
sx={{ alignItems: { xs: "stretch", sm: "center" } }}
|
||||||
Filters
|
>
|
||||||
</ToolbarButton>
|
<TextField
|
||||||
<ToolbarButton
|
size="small"
|
||||||
variant="primary"
|
value={search}
|
||||||
icon={<Plus size={16} />}
|
onChange={(e) => onSearchChange(e.target.value)}
|
||||||
onClick={onAddVendor}
|
placeholder="Search name, company, trade..."
|
||||||
className="w-[115.546875px] border-0 px-3 text-[13px]"
|
className="min-w-[260px]"
|
||||||
>
|
/>
|
||||||
Add Vendor
|
<Button
|
||||||
</ToolbarButton>
|
variant="outlined"
|
||||||
{isFetching && !isLoading && (
|
onClick={onOpenFilters}
|
||||||
<CircularProgress size={14} aria-label="Refreshing vendors" role="status" />
|
startIcon={<FilterListIcon />}
|
||||||
|
aria-label="Open vendor filters"
|
||||||
|
>
|
||||||
|
Filters
|
||||||
|
{appliedFilterCount > 0 && (
|
||||||
|
<Chip size="small" color="primary" label={appliedFilterCount} sx={{ ml: 1 }} />
|
||||||
)}
|
)}
|
||||||
</>
|
</Button>
|
||||||
}
|
<Button variant="contained" onClick={onAddVendor}>
|
||||||
/>
|
+ Add Vendor
|
||||||
|
</Button>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,21 +90,16 @@ interface AppliedChipEntry {
|
||||||
|
|
||||||
interface VendorAppliedFiltersBarProps {
|
interface VendorAppliedFiltersBarProps {
|
||||||
chips: AppliedChipEntry[];
|
chips: AppliedChipEntry[];
|
||||||
resultCount: number;
|
|
||||||
onClearAll: () => void;
|
onClearAll: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VendorAppliedFiltersBar({
|
export function VendorAppliedFiltersBar({ chips, onClearAll }: VendorAppliedFiltersBarProps) {
|
||||||
chips,
|
|
||||||
resultCount,
|
|
||||||
onClearAll,
|
|
||||||
}: VendorAppliedFiltersBarProps) {
|
|
||||||
if (chips.length === 0) return null;
|
if (chips.length === 0) return null;
|
||||||
return (
|
return (
|
||||||
<Stack direction="row" spacing={1} className="flex flex-wrap items-center">
|
<Stack direction="row" spacing={1} className="flex flex-wrap items-center">
|
||||||
<Text variant="caption" tone="muted">
|
<Typography variant="caption" sx={{ color: "text.secondary" }}>
|
||||||
{resultCount} {resultCount === 1 ? "technician" : "technicians"} · filtered by
|
Applied:
|
||||||
</Text>
|
</Typography>
|
||||||
{chips.map((chip) => (
|
{chips.map((chip) => (
|
||||||
<Chip
|
<Chip
|
||||||
key={chip.key}
|
key={chip.key}
|
||||||
|
|
@ -139,31 +146,23 @@ export function VendorsListFooter({
|
||||||
sx={{
|
sx={{
|
||||||
alignItems: { xs: "stretch", sm: "center" },
|
alignItems: { xs: "stretch", sm: "center" },
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
minHeight: 33.5,
|
|
||||||
mx: -2,
|
|
||||||
px: 2,
|
|
||||||
backgroundColor: "var(--color-bg-surface)",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text variant="caption" as="span" sx={{ color: "#6b7a96", fontSize: 11, lineHeight: 1.5 }}>
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>
|
||||||
{totalCount} {isActive ? "active" : "inactive"}{" "}
|
{totalCount} {isActive ? "active" : "inactive"}{" "}
|
||||||
{totalCount === 1 ? "technician" : "technicians"}
|
{totalCount === 1 ? "vendor entry" : "vendor entries"}
|
||||||
{isFiltered && " · filtered"}
|
{isFiltered && " · filtered"}
|
||||||
</Text>
|
{` · ${activeCount} active · ${inactiveCount} inactive`}
|
||||||
<Text variant="caption" as="span" sx={{ color: "#6b7a96", fontSize: 11, lineHeight: 1.5 }}>
|
</Typography>
|
||||||
{activeCount} active · {inactiveCount} inactive
|
<TablePagination
|
||||||
</Text>
|
component="div"
|
||||||
{totalCount > pageSize && (
|
count={totalCount}
|
||||||
<TablePagination
|
page={page}
|
||||||
component="div"
|
onPageChange={(_e, nextPage) => onPageChange(nextPage)}
|
||||||
count={totalCount}
|
rowsPerPage={pageSize}
|
||||||
page={page}
|
onRowsPerPageChange={(e) => onPageSizeChange(Number(e.target.value))}
|
||||||
onPageChange={(_e, nextPage) => onPageChange(nextPage)}
|
rowsPerPageOptions={[12, 24, 48]}
|
||||||
rowsPerPage={pageSize}
|
/>
|
||||||
onRowsPerPageChange={(e) => onPageSizeChange(Number(e.target.value))}
|
|
||||||
rowsPerPageOptions={[24, 48, 96]}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import { type KeyboardEvent, type MouseEvent } from "react";
|
import { type KeyboardEvent, type MouseEvent } from "react";
|
||||||
import SearchOffOutlinedIcon from "@mui/icons-material/SearchOffOutlined";
|
import { useNavigate } from "react-router";
|
||||||
|
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutlined";
|
||||||
import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
|
import EditOutlinedIcon from "@mui/icons-material/EditOutlined";
|
||||||
import VisibilityOutlinedIcon from "@mui/icons-material/VisibilityOutlined";
|
import VisibilityOutlinedIcon from "@mui/icons-material/VisibilityOutlined";
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
Box,
|
Chip,
|
||||||
CircularProgress,
|
CircularProgress,
|
||||||
IconButton,
|
IconButton,
|
||||||
Link,
|
Link,
|
||||||
|
|
@ -17,8 +18,8 @@ import {
|
||||||
TableHead,
|
TableHead,
|
||||||
TableRow,
|
TableRow,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { Text } from "@/components/ui/text";
|
|
||||||
import type { VendorListItem } from "@/domain/vendors/types/vendor";
|
import type { VendorListItem } from "@/domain/vendors/types/vendor";
|
||||||
|
|
||||||
const TABLE_COLUMNS = [
|
const TABLE_COLUMNS = [
|
||||||
|
|
@ -29,6 +30,9 @@ const TABLE_COLUMNS = [
|
||||||
"Phone",
|
"Phone",
|
||||||
"Email",
|
"Email",
|
||||||
"Total Jobs",
|
"Total Jobs",
|
||||||
|
"Status",
|
||||||
|
"View",
|
||||||
|
"Edit",
|
||||||
] as const;
|
] as const;
|
||||||
|
|
||||||
function getInitials(name: string): string {
|
function getInitials(name: string): string {
|
||||||
|
|
@ -50,34 +54,19 @@ function stopPropagation(event: MouseEvent): void {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
}
|
}
|
||||||
|
|
||||||
function VendorStatus({ isActive }: { isActive: boolean }) {
|
|
||||||
return (
|
|
||||||
<Stack direction="row" spacing={1} sx={{ alignItems: "center", pl: 1 }}>
|
|
||||||
<Box
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
width: 6,
|
|
||||||
height: 6,
|
|
||||||
borderRadius: "9999px",
|
|
||||||
backgroundColor: isActive ? "success.main" : "text.secondary",
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Text variant="description">{isActive ? "Active" : "Inactive"}</Text>
|
|
||||||
</Stack>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface VendorTableRowProps {
|
interface VendorTableRowProps {
|
||||||
row: VendorListItem;
|
row: VendorListItem;
|
||||||
onOpenDetail: (row: VendorListItem) => void;
|
onOpenDetail: (row: VendorListItem) => void;
|
||||||
onOpenEdit: (row: VendorListItem) => void;
|
onOpenDeactivation: (row: VendorListItem) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps) {
|
function VendorTableRow({ row, onOpenDetail, onOpenDeactivation }: VendorTableRowProps) {
|
||||||
|
const navigate = useNavigate();
|
||||||
const trades = splitTrades(row.tradeSpecialties);
|
const trades = splitTrades(row.tradeSpecialties);
|
||||||
const primaryTrade = trades[0] ?? "—";
|
const primaryTrade = trades[0] ?? "—";
|
||||||
const extraTrades = trades.length > 1 ? trades.length - 1 : 0;
|
const extraTrades = trades.length > 1 ? trades.length - 1 : 0;
|
||||||
const locationText = [row.city, row.state].filter(Boolean).join(", ") || "—";
|
const locationText = [row.city, row.state].filter(Boolean).join(", ") || "—";
|
||||||
|
const hasVendorId = row.id != null;
|
||||||
const rowKey = String(row.id ?? `company-${row.companyId ?? ""}`);
|
const rowKey = String(row.id ?? `company-${row.companyId ?? ""}`);
|
||||||
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|
@ -99,62 +88,37 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
>
|
>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Text variant="description" sx={{ color: "var(--color-foreground)" }}>
|
<Typography className="font-semibold">{row.companyName || "—"}</Typography>
|
||||||
{row.companyName || "—"}
|
|
||||||
</Text>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Stack direction="row" spacing={1.25} sx={{ alignItems: "center" }}>
|
<Stack direction="row" spacing={1.5} sx={{ alignItems: "center" }}>
|
||||||
<Avatar
|
<Avatar
|
||||||
sx={{
|
sx={{
|
||||||
width: 28,
|
width: 28,
|
||||||
height: 28,
|
height: 28,
|
||||||
backgroundColor: "var(--color-bg-muted)",
|
fontSize: 12,
|
||||||
color: "var(--color-primary)",
|
backgroundColor: "var(--accent, #1976d2)",
|
||||||
fontSize: 10.5,
|
|
||||||
fontWeight: 600,
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{getInitials(row.contactName)}
|
{getInitials(row.contactName)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<Text variant="description" sx={{ color: "var(--color-foreground)" }}>
|
<Typography variant="body2">{row.contactName || "—"}</Typography>
|
||||||
{row.contactName || "—"}
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>{locationText}</TableCell>
|
<TableCell>{locationText}</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
<TableCell>
|
||||||
{primaryTrade === "—" ? (
|
{primaryTrade === "—" ? (
|
||||||
"—"
|
"—"
|
||||||
) : (
|
) : (
|
||||||
<Stack direction="row" spacing={0.5} sx={{ alignItems: "center" }}>
|
<Stack direction="row" spacing={0.5} sx={{ alignItems: "center" }}>
|
||||||
<span>{primaryTrade}</span>
|
<span>{primaryTrade}</span>
|
||||||
{extraTrades > 0 && (
|
{extraTrades > 0 && <Chip size="small" label={`+${extraTrades}`} />}
|
||||||
<Box
|
|
||||||
component="span"
|
|
||||||
sx={{
|
|
||||||
borderRadius: "9999px",
|
|
||||||
backgroundColor: "var(--color-bg-muted)",
|
|
||||||
px: 0.75,
|
|
||||||
py: 0.25,
|
|
||||||
fontSize: 10.5,
|
|
||||||
lineHeight: 1.2,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
+{extraTrades}
|
|
||||||
</Box>
|
|
||||||
)}
|
|
||||||
</Stack>
|
</Stack>
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
<TableCell>
|
||||||
{row.phone ? (
|
{row.phone ? (
|
||||||
<Link
|
<Link href={`tel:${row.phone}`} underline="hover" onClick={stopPropagation}>
|
||||||
href={`tel:${row.phone}`}
|
|
||||||
underline="hover"
|
|
||||||
color="inherit"
|
|
||||||
onClick={stopPropagation}
|
|
||||||
>
|
|
||||||
{row.phone}
|
{row.phone}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -163,53 +127,71 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{row.email ? (
|
{row.email ? (
|
||||||
<Link
|
<Link href={`mailto:${row.email}`} underline="hover" onClick={stopPropagation}>
|
||||||
href={`mailto:${row.email}`}
|
|
||||||
underline="hover"
|
|
||||||
sx={{ color: "#6b7a96" }}
|
|
||||||
onClick={stopPropagation}
|
|
||||||
>
|
|
||||||
{row.email}
|
{row.email}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
"—"
|
"—"
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="center">{row.totalJobs ?? 0}</TableCell>
|
<TableCell>{row.totalJobs ?? 0}</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<VendorStatus isActive={row.isActive} />
|
<Chip
|
||||||
|
size="small"
|
||||||
|
label={row.isActive ? "Active" : "Inactive"}
|
||||||
|
color={row.isActive ? "success" : "default"}
|
||||||
|
/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="right">
|
<TableCell align="center">
|
||||||
|
<Tooltip title="View details">
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
aria-label={`View vendor ${row.companyName}`}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onOpenDetail(row);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<VisibilityOutlinedIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
</TableCell>
|
||||||
|
<TableCell align="center">
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
spacing={0.5}
|
spacing={0.5}
|
||||||
className="vendor-row-actions"
|
sx={{ alignItems: "center", justifyContent: "center" }}
|
||||||
sx={{ alignItems: "center", justifyContent: "flex-end" }}
|
|
||||||
>
|
>
|
||||||
<Tooltip title="View details">
|
|
||||||
<IconButton
|
|
||||||
size="small"
|
|
||||||
aria-label={`View vendor ${row.companyName}`}
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
onOpenDetail(row);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<VisibilityOutlinedIcon fontSize="small" />
|
|
||||||
</IconButton>
|
|
||||||
</Tooltip>
|
|
||||||
<Tooltip title="Edit">
|
<Tooltip title="Edit">
|
||||||
<IconButton
|
<IconButton
|
||||||
size="small"
|
size="small"
|
||||||
aria-label={`Edit vendor ${row.companyName}`}
|
aria-label={`Edit vendor ${row.companyName}`}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
onOpenEdit(row);
|
navigate(
|
||||||
|
row.id != null
|
||||||
|
? `/vendors/edit/${row.id}`
|
||||||
|
: `/vendors/company/${row.companyId ?? ""}`,
|
||||||
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<EditOutlinedIcon fontSize="small" />
|
<EditOutlinedIcon fontSize="small" />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
{hasVendorId && row.isActive && (
|
||||||
|
<Tooltip title="Deactivate">
|
||||||
|
<IconButton
|
||||||
|
size="small"
|
||||||
|
aria-label="Deactivate vendor"
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onOpenDeactivation(row);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DeleteOutlineIcon fontSize="small" />
|
||||||
|
</IconButton>
|
||||||
|
</Tooltip>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
|
@ -218,118 +200,50 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
|
|
||||||
interface VendorsTableProps {
|
interface VendorsTableProps {
|
||||||
rows: VendorListItem[];
|
rows: VendorListItem[];
|
||||||
isActive: boolean;
|
|
||||||
isFiltered: boolean;
|
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
showError: boolean;
|
showError: boolean;
|
||||||
onOpenDetail: (row: VendorListItem) => void;
|
onOpenDetail: (row: VendorListItem) => void;
|
||||||
onOpenEdit: (row: VendorListItem) => void;
|
onOpenDeactivation: (row: VendorListItem) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function VendorsTable({
|
export function VendorsTable({
|
||||||
rows,
|
rows,
|
||||||
isActive,
|
|
||||||
isFiltered,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
showError,
|
showError,
|
||||||
onOpenDetail,
|
onOpenDetail,
|
||||||
onOpenEdit,
|
onOpenDeactivation,
|
||||||
}: VendorsTableProps) {
|
}: VendorsTableProps) {
|
||||||
const showEmptyRow = !isLoading && !showError && rows.length === 0;
|
const showEmptyRow = !isLoading && !showError && rows.length === 0;
|
||||||
const columnCount = TABLE_COLUMNS.length + 2;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableContainer
|
<TableContainer component={Paper} variant="outlined" sx={{ overflowX: "auto" }}>
|
||||||
component={Paper}
|
<Table size="small" sx={{ minWidth: 960 }}>
|
||||||
variant="outlined"
|
|
||||||
sx={{
|
|
||||||
mt: 2,
|
|
||||||
mb: 2,
|
|
||||||
flex: "1 1 auto",
|
|
||||||
overflow: "auto",
|
|
||||||
borderRadius: 1.5,
|
|
||||||
fontSize: 13,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Table
|
|
||||||
size="small"
|
|
||||||
stickyHeader
|
|
||||||
sx={{
|
|
||||||
minWidth: 1550,
|
|
||||||
tableLayout: "fixed",
|
|
||||||
"& .MuiTableCell-head": {
|
|
||||||
backgroundColor: "var(--color-bg-muted)",
|
|
||||||
color: "var(--color-foreground)",
|
|
||||||
fontSize: 10.5,
|
|
||||||
fontWeight: 700,
|
|
||||||
letterSpacing: "0.06em",
|
|
||||||
lineHeight: "24px",
|
|
||||||
px: 1.75,
|
|
||||||
py: 1.375,
|
|
||||||
textTransform: "uppercase",
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
},
|
|
||||||
"& .MuiTableCell-body": {
|
|
||||||
fontSize: 13,
|
|
||||||
px: 1.5,
|
|
||||||
py: 1,
|
|
||||||
height: 52,
|
|
||||||
lineHeight: 1.43,
|
|
||||||
whiteSpace: "nowrap",
|
|
||||||
},
|
|
||||||
"& .vendor-row-actions": {
|
|
||||||
opacity: { xs: 1, md: 0 },
|
|
||||||
transition: "opacity 120ms ease",
|
|
||||||
},
|
|
||||||
"& .MuiTableRow-root:hover .vendor-row-actions, & .MuiTableRow-root:focus-within .vendor-row-actions":
|
|
||||||
{
|
|
||||||
opacity: 1,
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<colgroup>
|
|
||||||
<col style={{ width: 196.34375 }} />
|
|
||||||
<col style={{ width: 207.25 }} />
|
|
||||||
<col style={{ width: 152.703125 }} />
|
|
||||||
<col style={{ width: 218.15625 }} />
|
|
||||||
<col style={{ width: 152.703125 }} />
|
|
||||||
<col style={{ width: 251.90625 }} />
|
|
||||||
<col style={{ width: 109.078125 }} />
|
|
||||||
<col style={{ width: 119.984375 }} />
|
|
||||||
<col style={{ width: 141.875 }} />
|
|
||||||
</colgroup>
|
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
{TABLE_COLUMNS.map((column) => (
|
{TABLE_COLUMNS.map((column) => (
|
||||||
<TableCell key={column} align={column === "Total Jobs" ? "center" : "left"}>
|
<TableCell
|
||||||
|
key={column}
|
||||||
|
align={column === "View" || column === "Edit" ? "center" : "left"}
|
||||||
|
className="font-semibold"
|
||||||
|
>
|
||||||
{column}
|
{column}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
))}
|
))}
|
||||||
<TableCell>Status</TableCell>
|
|
||||||
<TableCell align="right" aria-label="Vendor actions" />
|
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={columnCount} align="center" className="py-10">
|
<TableCell colSpan={TABLE_COLUMNS.length} align="center" className="py-10">
|
||||||
<CircularProgress size={28} />
|
<CircularProgress size={28} />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : showEmptyRow ? (
|
) : showEmptyRow ? (
|
||||||
<TableRow>
|
<TableRow>
|
||||||
<TableCell colSpan={columnCount} align="center" className="py-10">
|
<TableCell colSpan={TABLE_COLUMNS.length} align="center" className="py-10">
|
||||||
<Stack spacing={1} sx={{ alignItems: "center" }}>
|
<Typography sx={{ color: "text.secondary" }}>
|
||||||
<SearchOffOutlinedIcon sx={{ color: "text.secondary", fontSize: 32 }} />
|
No vendors match the current filters.
|
||||||
<Text variant="description" className="font-semibold">
|
</Typography>
|
||||||
{`No ${isActive ? "active" : "inactive"} technicians found`}
|
|
||||||
</Text>
|
|
||||||
<Text variant="caption" tone="muted">
|
|
||||||
{isFiltered
|
|
||||||
? "Try a different search, or add a new vendor."
|
|
||||||
: "Add a vendor to get started."}
|
|
||||||
</Text>
|
|
||||||
</Stack>
|
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
|
|
@ -338,7 +252,7 @@ export function VendorsTable({
|
||||||
key={String(row.id ?? `company-${row.companyId ?? ""}`)}
|
key={String(row.id ?? `company-${row.companyId ?? ""}`)}
|
||||||
row={row}
|
row={row}
|
||||||
onOpenDetail={onOpenDetail}
|
onOpenDetail={onOpenDetail}
|
||||||
onOpenEdit={onOpenEdit}
|
onOpenDeactivation={onOpenDeactivation}
|
||||||
/>
|
/>
|
||||||
))
|
))
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
125
src/app/(protected)/vendors/index.tsx
vendored
125
src/app/(protected)/vendors/index.tsx
vendored
|
|
@ -23,91 +23,16 @@ interface AppliedChip {
|
||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function statusTabLabel(label: string, count: number) {
|
|
||||||
return (
|
|
||||||
<Box className="flex items-center gap-2">
|
|
||||||
<Box component="span">{label}</Box>
|
|
||||||
<Box
|
|
||||||
component="span"
|
|
||||||
className="min-w-5 rounded-full px-1.5 py-0.5 text-[10px] font-semibold leading-none"
|
|
||||||
sx={{ backgroundColor: "action.hover", color: "text.secondary" }}
|
|
||||||
>
|
|
||||||
{count}
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function VendorStatusTabs({
|
|
||||||
isActive,
|
|
||||||
activeCount,
|
|
||||||
inactiveCount,
|
|
||||||
onChange,
|
|
||||||
}: {
|
|
||||||
isActive: boolean;
|
|
||||||
activeCount: number;
|
|
||||||
inactiveCount: number;
|
|
||||||
onChange: (isActive: boolean) => void;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<Tabs
|
|
||||||
value={isActive ? "active" : "inactive"}
|
|
||||||
onChange={(_event, value: "active" | "inactive") => onChange(value === "active")}
|
|
||||||
aria-label="Vendor status"
|
|
||||||
sx={{
|
|
||||||
minHeight: 36,
|
|
||||||
flexShrink: 0,
|
|
||||||
borderBottom: (theme) => `1px solid ${theme.palette.divider}`,
|
|
||||||
backgroundColor: "var(--color-bg-surface)",
|
|
||||||
mx: -2,
|
|
||||||
px: 1.5,
|
|
||||||
"& .MuiTab-root": {
|
|
||||||
minHeight: 36,
|
|
||||||
px: 2,
|
|
||||||
py: 0,
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: 500,
|
|
||||||
textTransform: "none",
|
|
||||||
},
|
|
||||||
"& .MuiTab-root:first-of-type": { width: 102.84375 },
|
|
||||||
"& .Mui-selected": { fontWeight: 600 },
|
|
||||||
"& .MuiTabs-indicator": { height: 2 },
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Tab
|
|
||||||
value="active"
|
|
||||||
label={statusTabLabel("Active", activeCount)}
|
|
||||||
aria-label={`Active (${activeCount})`}
|
|
||||||
/>
|
|
||||||
<Tab
|
|
||||||
value="inactive"
|
|
||||||
label={statusTabLabel("Inactive", inactiveCount)}
|
|
||||||
aria-label={`Inactive (${inactiveCount})`}
|
|
||||||
/>
|
|
||||||
</Tabs>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function describeChips(
|
function describeChips(
|
||||||
filters: VendorFilters,
|
filters: VendorFilters,
|
||||||
jobBucketLabels: Map<string, string>,
|
jobBucketLabels: Map<string, string>,
|
||||||
): AppliedChip[] {
|
): AppliedChip[] {
|
||||||
const chips: AppliedChip[] = [];
|
const chips: AppliedChip[] = [];
|
||||||
filters.companies.forEach((value) =>
|
filters.companies.forEach((value) => chips.push({ category: "companies", value, label: value }));
|
||||||
chips.push({ category: "companies", value, label: `Company: ${value}` }),
|
filters.trades.forEach((value) => chips.push({ category: "trades", value, label: value }));
|
||||||
);
|
filters.locations.forEach((value) => chips.push({ category: "locations", value, label: value }));
|
||||||
filters.trades.forEach((value) =>
|
|
||||||
chips.push({ category: "trades", value, label: `Trade: ${value}` }),
|
|
||||||
);
|
|
||||||
filters.locations.forEach((value) =>
|
|
||||||
chips.push({ category: "locations", value, label: `Location: ${value}` }),
|
|
||||||
);
|
|
||||||
filters.jobBuckets.forEach((value) =>
|
filters.jobBuckets.forEach((value) =>
|
||||||
chips.push({
|
chips.push({ category: "jobBuckets", value, label: jobBucketLabels.get(value) ?? value }),
|
||||||
category: "jobBuckets",
|
|
||||||
value,
|
|
||||||
label: `Total Jobs: ${jobBucketLabels.get(value) ?? value}`,
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
return chips;
|
return chips;
|
||||||
}
|
}
|
||||||
|
|
@ -117,12 +42,7 @@ export default function VendorsListPage() {
|
||||||
const [filtersOpen, setFiltersOpen] = useState(false);
|
const [filtersOpen, setFiltersOpen] = useState(false);
|
||||||
const [createOpen, setCreateOpen] = useState(false);
|
const [createOpen, setCreateOpen] = useState(false);
|
||||||
const [detailTarget, setDetailTarget] = useState<VendorListItem | null>(null);
|
const [detailTarget, setDetailTarget] = useState<VendorListItem | null>(null);
|
||||||
const [detailStartsInEdit, setDetailStartsInEdit] = useState(false);
|
const deactivation = useVendorDeactivation();
|
||||||
const closeDetail = () => {
|
|
||||||
setDetailTarget(null);
|
|
||||||
setDetailStartsInEdit(false);
|
|
||||||
};
|
|
||||||
const deactivation = useVendorDeactivation(closeDetail);
|
|
||||||
|
|
||||||
const { data: facets } = useVendorFacets(filters.isActive);
|
const { data: facets } = useVendorFacets(filters.isActive);
|
||||||
const { data, isLoading, isFetching, error } = useVendorsList(filters.listParams);
|
const { data, isLoading, isFetching, error } = useVendorsList(filters.listParams);
|
||||||
|
|
@ -141,7 +61,7 @@ export default function VendorsListPage() {
|
||||||
const appliedChips = describeChips(filters.appliedFilters, jobBucketLabels);
|
const appliedChips = describeChips(filters.appliedFilters, jobBucketLabels);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="flex h-full flex-col overflow-hidden px-4 pt-4 pb-0">
|
<Box className="flex flex-col gap-4 p-4">
|
||||||
<VendorsListToolbar
|
<VendorsListToolbar
|
||||||
globalCount={activeCount + inactiveCount}
|
globalCount={activeCount + inactiveCount}
|
||||||
activeCount={activeCount}
|
activeCount={activeCount}
|
||||||
|
|
@ -154,15 +74,18 @@ export default function VendorsListPage() {
|
||||||
onAddVendor={() => setCreateOpen(true)}
|
onAddVendor={() => setCreateOpen(true)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VendorStatusTabs
|
<Tabs
|
||||||
isActive={filters.isActive}
|
value={filters.isActive ? "active" : "inactive"}
|
||||||
activeCount={activeCount}
|
onChange={(_event, value: "active" | "inactive") =>
|
||||||
inactiveCount={inactiveCount}
|
filters.setIsActiveWithReset(value === "active")
|
||||||
onChange={filters.setIsActiveWithReset}
|
}
|
||||||
/>
|
aria-label="Vendor status"
|
||||||
|
>
|
||||||
|
<Tab value="active" label={`Active (${activeCount})`} />
|
||||||
|
<Tab value="inactive" label={`Inactive (${inactiveCount})`} />
|
||||||
|
</Tabs>
|
||||||
|
|
||||||
<VendorAppliedFiltersBar
|
<VendorAppliedFiltersBar
|
||||||
resultCount={totalCount}
|
|
||||||
chips={appliedChips.map((chip) => ({
|
chips={appliedChips.map((chip) => ({
|
||||||
key: `${chip.category}-${chip.value}`,
|
key: `${chip.category}-${chip.value}`,
|
||||||
label: chip.label,
|
label: chip.label,
|
||||||
|
|
@ -179,18 +102,10 @@ export default function VendorsListPage() {
|
||||||
|
|
||||||
<VendorsTable
|
<VendorsTable
|
||||||
rows={rows}
|
rows={rows}
|
||||||
isActive={filters.isActive}
|
|
||||||
isFiltered={appliedChips.length > 0 || Boolean(filters.debouncedSearch)}
|
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
showError={Boolean(error)}
|
showError={Boolean(error)}
|
||||||
onOpenDetail={(row) => {
|
onOpenDetail={setDetailTarget}
|
||||||
setDetailStartsInEdit(false);
|
onOpenDeactivation={deactivation.open}
|
||||||
setDetailTarget(row);
|
|
||||||
}}
|
|
||||||
onOpenEdit={(row) => {
|
|
||||||
setDetailStartsInEdit(true);
|
|
||||||
setDetailTarget(row);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VendorsListFooter
|
<VendorsListFooter
|
||||||
|
|
@ -218,9 +133,7 @@ export default function VendorsListPage() {
|
||||||
<VendorDetailDrawer
|
<VendorDetailDrawer
|
||||||
open={Boolean(detailTarget)}
|
open={Boolean(detailTarget)}
|
||||||
vendor={detailTarget}
|
vendor={detailTarget}
|
||||||
startInEdit={detailStartsInEdit}
|
onClose={() => setDetailTarget(null)}
|
||||||
onRequestDeactivation={deactivation.open}
|
|
||||||
onClose={closeDetail}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<VendorDeactivationDialog
|
<VendorDeactivationDialog
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ export function buildInlineDraftCreateInput(
|
||||||
pocName: draft.pocName,
|
pocName: draft.pocName,
|
||||||
pocPhone: draft.pocPhone,
|
pocPhone: draft.pocPhone,
|
||||||
pocNotes: draft.pocNotes,
|
pocNotes: draft.pocNotes,
|
||||||
|
additionalContacts: draft.additionalContacts ?? [],
|
||||||
scheduleWeekOnly: draft.scheduleWeekOnly,
|
scheduleWeekOnly: draft.scheduleWeekOnly,
|
||||||
targetWeek: draft.targetWeek || "",
|
targetWeek: draft.targetWeek || "",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { MapPin } from "lucide-react";
|
import { MapPin } from "lucide-react";
|
||||||
import { formatSitePlace } from "@/domain/locations/mappers/location-mapper";
|
import { formatSitePlace } from "@/domain/locations/mappers/location-mapper";
|
||||||
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
||||||
import { HighlightText } from "./highlight-text";
|
import { HighlightText } from "./highlight-text";
|
||||||
import { HoverChevron } from "./hover-chevron";
|
import { HoverChevron } from "./hover-chevron";
|
||||||
|
|
@ -15,6 +16,7 @@ type SiteCellProps = {
|
||||||
pocName?: string;
|
pocName?: string;
|
||||||
pocPhone?: string;
|
pocPhone?: string;
|
||||||
pocNotes?: string;
|
pocNotes?: string;
|
||||||
|
additionalContacts?: WorkOrderAdditionalContact[];
|
||||||
sites: LocationOption[];
|
sites: LocationOption[];
|
||||||
q?: string;
|
q?: string;
|
||||||
onSave: (patch: SitePatch) => void;
|
onSave: (patch: SitePatch) => void;
|
||||||
|
|
@ -29,6 +31,7 @@ export function SiteCell({
|
||||||
pocName,
|
pocName,
|
||||||
pocPhone,
|
pocPhone,
|
||||||
pocNotes,
|
pocNotes,
|
||||||
|
additionalContacts,
|
||||||
sites,
|
sites,
|
||||||
q,
|
q,
|
||||||
onSave,
|
onSave,
|
||||||
|
|
@ -82,6 +85,7 @@ export function SiteCell({
|
||||||
pocName={pocName}
|
pocName={pocName}
|
||||||
pocPhone={pocPhone}
|
pocPhone={pocPhone}
|
||||||
pocNotes={pocNotes}
|
pocNotes={pocNotes}
|
||||||
|
additionalContacts={additionalContacts}
|
||||||
sites={sites}
|
sites={sites}
|
||||||
onSave={onSave}
|
onSave={onSave}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import type { SitePatch } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog";
|
||||||
|
|
||||||
|
type SiteDialogFooterProps = {
|
||||||
|
onClose: () => void;
|
||||||
|
onSave: (patch: SitePatch) => void;
|
||||||
|
buildPatch: () => SitePatch;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SiteDialogFooter({ onClose, onSave, buildPatch }: SiteDialogFooterProps) {
|
||||||
|
return (
|
||||||
|
<div className="mt-4 flex items-center justify-end gap-2">
|
||||||
|
<Button variant="ghost" className="min-h-0 px-2 py-1 text-[12px]" onClick={onClose}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="min-h-0 px-3 py-1 text-[12px]"
|
||||||
|
onClick={() => {
|
||||||
|
onSave(buildPatch());
|
||||||
|
onClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,47 +1 @@
|
||||||
import {
|
export { PocContactFields as SiteDialogPocFields } from "@/app/(protected)/workorders/_components/poc/poc-contact-fields";
|
||||||
DLG_INPUT_CLS,
|
|
||||||
DLG_INPUT_STYLE,
|
|
||||||
} from "@/app/(protected)/workorders/_components/wizard/wizard-input-styles";
|
|
||||||
import { Text } from "@/components/ui/text";
|
|
||||||
import { FieldLabel } from "@/app/(protected)/workorders/_components/list/table/cells/dialog-field-label";
|
|
||||||
|
|
||||||
type SiteDialogPocFieldsProps = {
|
|
||||||
pocName: string;
|
|
||||||
pocPhone: string;
|
|
||||||
pocNotes: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function SiteDialogPocFields({ pocName, pocPhone, pocNotes }: SiteDialogPocFieldsProps) {
|
|
||||||
return (
|
|
||||||
<div className="pt-1">
|
|
||||||
<FieldLabel>Point of Contact</FieldLabel>
|
|
||||||
<Text as="p" className="mb-2 text-[11px]" style={{ color: "var(--color-text-muted)" }}>
|
|
||||||
Shown from site/work order records. Board edit saves site code only.
|
|
||||||
</Text>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<input
|
|
||||||
value={pocName}
|
|
||||||
readOnly
|
|
||||||
placeholder="POC name"
|
|
||||||
className={DLG_INPUT_CLS}
|
|
||||||
style={{ ...DLG_INPUT_STYLE, opacity: 0.85 }}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
value={pocPhone}
|
|
||||||
readOnly
|
|
||||||
placeholder="POC phone"
|
|
||||||
className={DLG_INPUT_CLS}
|
|
||||||
style={{ ...DLG_INPUT_STYLE, opacity: 0.85 }}
|
|
||||||
/>
|
|
||||||
<textarea
|
|
||||||
value={pocNotes}
|
|
||||||
readOnly
|
|
||||||
placeholder="Notes…"
|
|
||||||
rows={2}
|
|
||||||
className={`${DLG_INPUT_CLS} resize-none`}
|
|
||||||
style={{ ...DLG_INPUT_STYLE, fontFamily: "inherit", opacity: 0.85 }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { PocContactFields } from "@/app/(protected)/workorders/_components/poc/poc-contact-fields";
|
||||||
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
|
|
||||||
|
type SiteDialogPocSectionProps = {
|
||||||
|
pocName: string;
|
||||||
|
pocPhone: string;
|
||||||
|
pocNotes: string;
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
|
onPocNameChange: (value: string) => void;
|
||||||
|
onPocPhoneChange: (value: string) => void;
|
||||||
|
onPocNotesChange: (value: string) => void;
|
||||||
|
onAdditionalContactsChange: (contacts: WorkOrderAdditionalContact[]) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function SiteDialogPocSection({
|
||||||
|
pocName,
|
||||||
|
pocPhone,
|
||||||
|
pocNotes,
|
||||||
|
additionalContacts,
|
||||||
|
onPocNameChange,
|
||||||
|
onPocPhoneChange,
|
||||||
|
onPocNotesChange,
|
||||||
|
onAdditionalContactsChange,
|
||||||
|
}: SiteDialogPocSectionProps) {
|
||||||
|
return (
|
||||||
|
<PocContactFields
|
||||||
|
pocName={pocName}
|
||||||
|
pocPhone={pocPhone}
|
||||||
|
pocNotes={pocNotes}
|
||||||
|
additionalContacts={additionalContacts}
|
||||||
|
onPocNameChange={onPocNameChange}
|
||||||
|
onPocPhoneChange={onPocPhoneChange}
|
||||||
|
onPocNotesChange={onPocNotesChange}
|
||||||
|
onAdditionalContactsChange={onAdditionalContactsChange}
|
||||||
|
helperText="Auto-filled from site records when empty. Additional contacts persist on save."
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -2,12 +2,12 @@ import { useEffect, useState, type MouseEvent } from "react";
|
||||||
import { MapPin } from "lucide-react";
|
import { MapPin } from "lucide-react";
|
||||||
import { Dialog, DialogContent, DialogTitle } from "@mui/material";
|
import { Dialog, DialogContent, DialogTitle } from "@mui/material";
|
||||||
import { WizardFieldSelect } from "@/app/(protected)/workorders/_components/wizard/wizard-field-select";
|
import { WizardFieldSelect } from "@/app/(protected)/workorders/_components/wizard/wizard-field-select";
|
||||||
import { Button } from "@/components/ui/button";
|
|
||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
import { dialogBlurBackdropSlotProps } from "@/components/ui/dialog-blur-backdrop";
|
import { dialogBlurBackdropSlotProps } from "@/components/ui/dialog-blur-backdrop";
|
||||||
import { formatLocationAddressPreview } from "@/domain/locations/mappers/location-mapper";
|
import { formatLocationAddressPreview } from "@/domain/locations/mappers/location-mapper";
|
||||||
import { useLocationDetail } from "@/domain/locations/use-cases/use-location-detail";
|
import { useLocationDetail } from "@/domain/locations/use-cases/use-location-detail";
|
||||||
import { resolveSiteCode } from "@/domain/work-orders/mappers/work-order-board-mapper";
|
import { resolveSiteCode } from "@/domain/work-orders/mappers/work-order-board-mapper";
|
||||||
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
||||||
import { FieldLabel } from "@/app/(protected)/workorders/_components/list/table/cells/dialog-field-label";
|
import { FieldLabel } from "@/app/(protected)/workorders/_components/list/table/cells/dialog-field-label";
|
||||||
import {
|
import {
|
||||||
|
|
@ -15,7 +15,8 @@ import {
|
||||||
resolveLocationId,
|
resolveLocationId,
|
||||||
} from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-helpers";
|
} from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-helpers";
|
||||||
import { SiteDialogDetailPanel } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-detail-panel";
|
import { SiteDialogDetailPanel } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-detail-panel";
|
||||||
import { SiteDialogPocFields } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-poc-fields";
|
import { SiteDialogFooter } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-footer";
|
||||||
|
import { SiteDialogPocSection } from "@/app/(protected)/workorders/_components/list/table/cells/site-dialog-poc-section";
|
||||||
|
|
||||||
export type SitePatch = {
|
export type SitePatch = {
|
||||||
site: string;
|
site: string;
|
||||||
|
|
@ -24,6 +25,7 @@ export type SitePatch = {
|
||||||
pocName: string;
|
pocName: string;
|
||||||
pocPhone: string;
|
pocPhone: string;
|
||||||
pocNotes: string;
|
pocNotes: string;
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
};
|
};
|
||||||
|
|
||||||
type SiteDialogProps = {
|
type SiteDialogProps = {
|
||||||
|
|
@ -34,6 +36,7 @@ type SiteDialogProps = {
|
||||||
pocName?: string;
|
pocName?: string;
|
||||||
pocPhone?: string;
|
pocPhone?: string;
|
||||||
pocNotes?: string;
|
pocNotes?: string;
|
||||||
|
additionalContacts?: WorkOrderAdditionalContact[];
|
||||||
sites: LocationOption[];
|
sites: LocationOption[];
|
||||||
onSave: (patch: SitePatch) => void;
|
onSave: (patch: SitePatch) => void;
|
||||||
};
|
};
|
||||||
|
|
@ -46,6 +49,7 @@ export function SiteDialog({
|
||||||
pocName = "",
|
pocName = "",
|
||||||
pocPhone = "",
|
pocPhone = "",
|
||||||
pocNotes = "",
|
pocNotes = "",
|
||||||
|
additionalContacts = [],
|
||||||
sites,
|
sites,
|
||||||
onSave,
|
onSave,
|
||||||
}: SiteDialogProps) {
|
}: SiteDialogProps) {
|
||||||
|
|
@ -54,6 +58,7 @@ export function SiteDialog({
|
||||||
const [pn, setPn] = useState(pocName);
|
const [pn, setPn] = useState(pocName);
|
||||||
const [pp, setPp] = useState(pocPhone);
|
const [pp, setPp] = useState(pocPhone);
|
||||||
const [notes, setNotes] = useState(pocNotes);
|
const [notes, setNotes] = useState(pocNotes);
|
||||||
|
const [extraContacts, setExtraContacts] = useState(additionalContacts);
|
||||||
const [pocFilledFor, setPocFilledFor] = useState("");
|
const [pocFilledFor, setPocFilledFor] = useState("");
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
|
@ -75,9 +80,9 @@ export function SiteDialog({
|
||||||
setPn(pocName);
|
setPn(pocName);
|
||||||
setPp(pocPhone);
|
setPp(pocPhone);
|
||||||
setNotes(pocNotes);
|
setNotes(pocNotes);
|
||||||
// Preserve existing WO POC; allow one auto-fill from site detail when POC is empty.
|
setExtraContacts(additionalContacts);
|
||||||
setPocFilledFor(pocName.trim() || pocPhone.trim() ? resolved : "");
|
setPocFilledFor(pocName.trim() || pocPhone.trim() ? resolved : "");
|
||||||
}, [open, value, locationId, pocName, pocPhone, pocNotes, sites]);
|
}, [open, value, locationId, pocName, pocPhone, pocNotes, additionalContacts, sites]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!open || !locId || !locationDetail || pocFilledFor === locId) {
|
if (!open || !locId || !locationDetail || pocFilledFor === locId) {
|
||||||
|
|
@ -99,6 +104,16 @@ export function SiteDialog({
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const buildPatch = (): SitePatch => ({
|
||||||
|
site: code || (selected ? resolveSiteCode(selected) : ""),
|
||||||
|
location: selected ? extractLocationLabel(selected) : "",
|
||||||
|
locationId: locId,
|
||||||
|
pocName: pn,
|
||||||
|
pocPhone: pp,
|
||||||
|
pocNotes: notes,
|
||||||
|
additionalContacts: extraContacts,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
open={open}
|
open={open}
|
||||||
|
|
@ -153,34 +168,23 @@ export function SiteDialog({
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<SiteDialogPocFields pocName={pn} pocPhone={pp} pocNotes={notes} />
|
<SiteDialogPocSection
|
||||||
|
pocName={pn}
|
||||||
|
pocPhone={pp}
|
||||||
|
pocNotes={notes}
|
||||||
|
additionalContacts={extraContacts}
|
||||||
|
onPocNameChange={setPn}
|
||||||
|
onPocPhoneChange={setPp}
|
||||||
|
onPocNotesChange={setNotes}
|
||||||
|
onAdditionalContactsChange={setExtraContacts}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mt-4 flex items-center justify-end gap-2">
|
<SiteDialogFooter
|
||||||
<Button
|
onClose={() => onOpenChange(false)}
|
||||||
variant="ghost"
|
onSave={onSave}
|
||||||
className="min-h-0 px-2 py-1 text-[12px]"
|
buildPatch={buildPatch}
|
||||||
onClick={() => onOpenChange(false)}
|
/>
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
className="min-h-0 px-3 py-1 text-[12px]"
|
|
||||||
onClick={() => {
|
|
||||||
onSave({
|
|
||||||
site: code || (selected ? resolveSiteCode(selected) : ""),
|
|
||||||
location: selected ? extractLocationLabel(selected) : "",
|
|
||||||
locationId: locId,
|
|
||||||
pocName: pn,
|
|
||||||
pocPhone: pp,
|
|
||||||
pocNotes: notes,
|
|
||||||
});
|
|
||||||
onOpenChange(false);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
Save
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ export function WoTableInlineRowCells({
|
||||||
pocName={draft.pocName}
|
pocName={draft.pocName}
|
||||||
pocPhone={draft.pocPhone}
|
pocPhone={draft.pocPhone}
|
||||||
pocNotes={draft.pocNotes}
|
pocNotes={draft.pocNotes}
|
||||||
|
additionalContacts={draft.additionalContacts}
|
||||||
sites={sites}
|
sites={sites}
|
||||||
onSave={(p) =>
|
onSave={(p) =>
|
||||||
onPatch({
|
onPatch({
|
||||||
|
|
@ -61,6 +62,7 @@ export function WoTableInlineRowCells({
|
||||||
pocName: p.pocName,
|
pocName: p.pocName,
|
||||||
pocPhone: p.pocPhone,
|
pocPhone: p.pocPhone,
|
||||||
pocNotes: p.pocNotes,
|
pocNotes: p.pocNotes,
|
||||||
|
additionalContacts: p.additionalContacts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ export function WoTableRowCells({
|
||||||
pocName={row.pocName}
|
pocName={row.pocName}
|
||||||
pocPhone={row.pocPhone}
|
pocPhone={row.pocPhone}
|
||||||
pocNotes={row.pocNotes}
|
pocNotes={row.pocNotes}
|
||||||
|
additionalContacts={row.additionalContacts}
|
||||||
sites={sites}
|
sites={sites}
|
||||||
q={search}
|
q={search}
|
||||||
onSave={(p) =>
|
onSave={(p) =>
|
||||||
|
|
@ -59,6 +60,7 @@ export function WoTableRowCells({
|
||||||
pocName: p.pocName,
|
pocName: p.pocName,
|
||||||
pocPhone: p.pocPhone,
|
pocPhone: p.pocPhone,
|
||||||
pocNotes: p.pocNotes,
|
pocNotes: p.pocNotes,
|
||||||
|
additionalContacts: p.additionalContacts,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,165 @@
|
||||||
|
import { Plus, Trash2 } from "lucide-react";
|
||||||
|
import { Button } from "@/components/ui/button";
|
||||||
|
import { Text } from "@/components/ui/text";
|
||||||
|
import {
|
||||||
|
DLG_INPUT_CLS,
|
||||||
|
DLG_INPUT_STYLE,
|
||||||
|
} from "@/app/(protected)/workorders/_components/wizard/wizard-input-styles";
|
||||||
|
import { FieldLabel } from "@/app/(protected)/workorders/_components/list/table/cells/dialog-field-label";
|
||||||
|
import {
|
||||||
|
EMPTY_ADDITIONAL_CONTACT,
|
||||||
|
type WorkOrderAdditionalContact,
|
||||||
|
} from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
|
|
||||||
|
type PocContactFieldsProps = {
|
||||||
|
pocName: string;
|
||||||
|
pocPhone: string;
|
||||||
|
pocNotes: string;
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
|
onPocNameChange: (value: string) => void;
|
||||||
|
onPocPhoneChange: (value: string) => void;
|
||||||
|
onPocNotesChange: (value: string) => void;
|
||||||
|
onAdditionalContactsChange: (contacts: WorkOrderAdditionalContact[]) => void;
|
||||||
|
helperText?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateContactAt(
|
||||||
|
contacts: WorkOrderAdditionalContact[],
|
||||||
|
index: number,
|
||||||
|
patch: Partial<WorkOrderAdditionalContact>,
|
||||||
|
): WorkOrderAdditionalContact[] {
|
||||||
|
return contacts.map((contact, contactIndex) =>
|
||||||
|
contactIndex === index ? { ...contact, ...patch } : contact,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function PocContactFields({
|
||||||
|
pocName,
|
||||||
|
pocPhone,
|
||||||
|
pocNotes,
|
||||||
|
additionalContacts,
|
||||||
|
onPocNameChange,
|
||||||
|
onPocPhoneChange,
|
||||||
|
onPocNotesChange,
|
||||||
|
onAdditionalContactsChange,
|
||||||
|
helperText,
|
||||||
|
}: PocContactFieldsProps) {
|
||||||
|
const handleAddContact = () => {
|
||||||
|
onAdditionalContactsChange([...additionalContacts, { ...EMPTY_ADDITIONAL_CONTACT }]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRemoveContact = (index: number) => {
|
||||||
|
onAdditionalContactsChange(
|
||||||
|
additionalContacts.filter((_, contactIndex) => contactIndex !== index),
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="pt-1">
|
||||||
|
<FieldLabel>Point of Contact</FieldLabel>
|
||||||
|
{Boolean(helperText) && (
|
||||||
|
<Text as="p" className="mb-2 text-[11px]" style={{ color: "var(--color-text-muted)" }}>
|
||||||
|
{helperText}
|
||||||
|
</Text>
|
||||||
|
)}
|
||||||
|
<div className="space-y-2">
|
||||||
|
<input
|
||||||
|
value={pocName}
|
||||||
|
onChange={(event) => onPocNameChange(event.target.value)}
|
||||||
|
placeholder="POC name"
|
||||||
|
className={DLG_INPUT_CLS}
|
||||||
|
style={DLG_INPUT_STYLE}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={pocPhone}
|
||||||
|
onChange={(event) => onPocPhoneChange(event.target.value)}
|
||||||
|
placeholder="POC phone"
|
||||||
|
className={DLG_INPUT_CLS}
|
||||||
|
style={DLG_INPUT_STYLE}
|
||||||
|
/>
|
||||||
|
<textarea
|
||||||
|
value={pocNotes}
|
||||||
|
onChange={(event) => onPocNotesChange(event.target.value)}
|
||||||
|
placeholder="Notes…"
|
||||||
|
rows={2}
|
||||||
|
className={`${DLG_INPUT_CLS} resize-none`}
|
||||||
|
style={{ ...DLG_INPUT_STYLE, fontFamily: "inherit" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{additionalContacts.map((contact, index) => (
|
||||||
|
<div
|
||||||
|
key={`additional-poc-${index}`}
|
||||||
|
className="mt-3 space-y-2 rounded-lg p-3"
|
||||||
|
style={{ border: "1px solid var(--color-border)", background: "var(--color-bg-muted)" }}
|
||||||
|
>
|
||||||
|
<div className="flex items-center justify-between gap-2">
|
||||||
|
<Text
|
||||||
|
as="p"
|
||||||
|
className="text-[11px] font-semibold uppercase tracking-wide"
|
||||||
|
style={{ color: "var(--color-text-muted)" }}
|
||||||
|
>
|
||||||
|
Point of contact {index + 2}
|
||||||
|
</Text>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={`Remove point of contact ${index + 2}`}
|
||||||
|
className="inline-flex shrink-0 items-center justify-center rounded p-1 transition-colors hover:bg-[var(--color-bg-surface)]"
|
||||||
|
style={{ color: "var(--color-text-muted)" }}
|
||||||
|
onClick={() => handleRemoveContact(index)}
|
||||||
|
>
|
||||||
|
<Trash2 size={14} />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<input
|
||||||
|
value={contact.name}
|
||||||
|
onChange={(event) =>
|
||||||
|
onAdditionalContactsChange(
|
||||||
|
updateContactAt(additionalContacts, index, { name: event.target.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="POC name"
|
||||||
|
className={DLG_INPUT_CLS}
|
||||||
|
style={DLG_INPUT_STYLE}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
value={contact.phone}
|
||||||
|
onChange={(event) =>
|
||||||
|
onAdditionalContactsChange(
|
||||||
|
updateContactAt(additionalContacts, index, { phone: event.target.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="POC phone"
|
||||||
|
className={DLG_INPUT_CLS}
|
||||||
|
style={DLG_INPUT_STYLE}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
value={contact.notes ?? ""}
|
||||||
|
onChange={(event) =>
|
||||||
|
onAdditionalContactsChange(
|
||||||
|
updateContactAt(additionalContacts, index, { notes: event.target.value }),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
placeholder="Notes…"
|
||||||
|
rows={2}
|
||||||
|
className={`${DLG_INPUT_CLS} resize-none`}
|
||||||
|
style={{ ...DLG_INPUT_STYLE, fontFamily: "inherit" }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="ghost"
|
||||||
|
className="mt-3 min-h-0 gap-1.5 px-0 py-1 text-[12px]"
|
||||||
|
style={{ color: "var(--color-primary)" }}
|
||||||
|
onClick={handleAddContact}
|
||||||
|
>
|
||||||
|
<Plus size={14} className="shrink-0" />
|
||||||
|
Add point of contact
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -121,6 +121,18 @@ export function WizardSidebar({ step, draft }: WizardSidebarProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatAdditionalPocSummary(draft: WorkOrderWizardDraft): string {
|
||||||
|
const count = draft.additionalContacts.length;
|
||||||
|
if (count === 0) {
|
||||||
|
return "—";
|
||||||
|
}
|
||||||
|
const names = draft.additionalContacts.map((contact) => contact.name.trim()).filter(Boolean);
|
||||||
|
if (names.length > 0) {
|
||||||
|
return names.join(", ");
|
||||||
|
}
|
||||||
|
return `${count} contact${count === 1 ? "" : "s"}`;
|
||||||
|
}
|
||||||
|
|
||||||
function WizardSidebarSummary({ draft }: { draft: WorkOrderWizardDraft }) {
|
function WizardSidebarSummary({ draft }: { draft: WorkOrderWizardDraft }) {
|
||||||
const summary: [string, string][] = [
|
const summary: [string, string][] = [
|
||||||
["WO #", draft.woNumber ? `#${draft.woNumber}` : "—"],
|
["WO #", draft.woNumber ? `#${draft.woNumber}` : "—"],
|
||||||
|
|
@ -144,6 +156,7 @@ function WizardSidebarSummary({ draft }: { draft: WorkOrderWizardDraft }) {
|
||||||
: draft.pocName
|
: draft.pocName
|
||||||
: "—",
|
: "—",
|
||||||
],
|
],
|
||||||
|
["Additional POCs", formatAdditionalPocSummary(draft)],
|
||||||
["Service", draft.pm || "—"],
|
["Service", draft.pm || "—"],
|
||||||
["Technician", draft.vendorName || "—"],
|
["Technician", draft.vendorName || "—"],
|
||||||
["Company", draft.vendorName || "—"],
|
["Company", draft.vendorName || "—"],
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,11 @@
|
||||||
import { ExternalLink, Info, Mail, MapPin, Phone } from "lucide-react";
|
import { ExternalLink, Info, Mail, MapPin, Phone } from "lucide-react";
|
||||||
import { Text } from "@/components/ui/text";
|
import { Text } from "@/components/ui/text";
|
||||||
|
import { PocContactFields } from "@/app/(protected)/workorders/_components/poc/poc-contact-fields";
|
||||||
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
import type { LocationOption } from "@/domain/work-orders/types/work-order";
|
||||||
import type { Location } from "@/domain/locations/types/location";
|
import type { Location } from "@/domain/locations/types/location";
|
||||||
import type { WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard";
|
import type { WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard";
|
||||||
import { WizardFieldSelect } from "@/app/(protected)/workorders/_components/wizard/wizard-field-select";
|
import { WizardFieldSelect } from "@/app/(protected)/workorders/_components/wizard/wizard-field-select";
|
||||||
import {
|
import { Detail, WizLabel } from "@/app/(protected)/workorders/_components/wizard/wizard-labels";
|
||||||
DLG_INPUT_CLS,
|
|
||||||
DLG_INPUT_STYLE,
|
|
||||||
} from "@/app/(protected)/workorders/_components/wizard/wizard-input-styles";
|
|
||||||
import {
|
|
||||||
Detail,
|
|
||||||
WizLabel,
|
|
||||||
WizSubLabel,
|
|
||||||
} from "@/app/(protected)/workorders/_components/wizard/wizard-labels";
|
|
||||||
|
|
||||||
type ServiceOption = { id: string | number; value: string };
|
type ServiceOption = { id: string | number; value: string };
|
||||||
|
|
||||||
|
|
@ -60,6 +53,7 @@ export function WizardStepLocationService({
|
||||||
onPatch({
|
onPatch({
|
||||||
locationId: id,
|
locationId: id,
|
||||||
locationName: loc?.name ?? "",
|
locationName: loc?.name ?? "",
|
||||||
|
additionalContacts: [],
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
@ -112,40 +106,17 @@ export function WizardStepLocationService({
|
||||||
</a>
|
</a>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<PocContactFields
|
||||||
<WizSubLabel>Point of contact</WizSubLabel>
|
pocName={draft.pocName}
|
||||||
<Text
|
pocPhone={draft.pocPhone}
|
||||||
as="p"
|
pocNotes={draft.pocNotes}
|
||||||
variant="description"
|
additionalContacts={draft.additionalContacts}
|
||||||
sx={{ fontSize: 11.5, color: "var(--muted-foreground)", margin: "2px 0 8px" }}
|
onPocNameChange={(value) => onUpdate("pocName", value)}
|
||||||
>
|
onPocPhoneChange={(value) => onUpdate("pocPhone", value)}
|
||||||
Auto-filled from records — edit if outdated
|
onPocNotesChange={(value) => onUpdate("pocNotes", value)}
|
||||||
</Text>
|
onAdditionalContactsChange={(contacts) => onUpdate("additionalContacts", contacts)}
|
||||||
<div className="grid grid-cols-2 gap-2">
|
helperText="Auto-filled from records — edit if outdated"
|
||||||
<input
|
/>
|
||||||
value={draft.pocName}
|
|
||||||
onChange={(e) => onUpdate("pocName", e.target.value)}
|
|
||||||
placeholder="POC name"
|
|
||||||
className={DLG_INPUT_CLS}
|
|
||||||
style={DLG_INPUT_STYLE}
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
value={draft.pocPhone}
|
|
||||||
onChange={(e) => onUpdate("pocPhone", e.target.value)}
|
|
||||||
placeholder="POC phone"
|
|
||||||
className={DLG_INPUT_CLS}
|
|
||||||
style={DLG_INPUT_STYLE}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<textarea
|
|
||||||
value={draft.pocNotes}
|
|
||||||
onChange={(e) => onUpdate("pocNotes", e.target.value)}
|
|
||||||
placeholder="Notes…"
|
|
||||||
rows={2}
|
|
||||||
className={`${DLG_INPUT_CLS} mt-2 resize-none`}
|
|
||||||
style={{ ...DLG_INPUT_STYLE, fontFamily: "inherit" }}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,17 +49,10 @@ export function PageHeader({
|
||||||
"m-0 font-display mt-1! text-[30px]! font-extrabold leading-[1.1] tracking-[-0.02em] text-foreground",
|
"m-0 font-display mt-1! text-[30px]! font-extrabold leading-[1.1] tracking-[-0.02em] text-foreground",
|
||||||
eyebrow && "mt-1",
|
eyebrow && "mt-1",
|
||||||
)}
|
)}
|
||||||
sx={{ fontSize: 30, fontWeight: 800, lineHeight: 1.1, letterSpacing: "-0.02em" }}
|
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
</Text>
|
</Text>
|
||||||
<Text
|
<Text variant="description" tone="muted" when={Boolean(subtitle)}>
|
||||||
variant="description"
|
|
||||||
as="span"
|
|
||||||
tone="muted"
|
|
||||||
when={Boolean(subtitle)}
|
|
||||||
sx={{ mt: 0.75, fontWeight: 500 }}
|
|
||||||
>
|
|
||||||
{subtitle}
|
{subtitle}
|
||||||
</Text>
|
</Text>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
|
|
||||||
91
src/domain/work-orders/mappers/additional-contacts-mapper.ts
Normal file
91
src/domain/work-orders/mappers/additional-contacts-mapper.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
|
|
||||||
|
function asRecord(raw: unknown): Record<string, unknown> {
|
||||||
|
return typeof raw === "object" && raw !== null ? (raw as Record<string, unknown>) : {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function readString(record: Record<string, unknown>, ...keys: string[]): string {
|
||||||
|
for (const key of keys) {
|
||||||
|
const value = record[key];
|
||||||
|
if (typeof value === "string") {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
if (typeof value === "number") {
|
||||||
|
return String(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapContactItem(raw: unknown): WorkOrderAdditionalContact | null {
|
||||||
|
const item = asRecord(raw);
|
||||||
|
const name = readString(item, "name", "Name");
|
||||||
|
const phone = readString(item, "phone", "Phone");
|
||||||
|
const notes = readString(item, "notes", "Notes");
|
||||||
|
|
||||||
|
if (!name.trim() && !phone.trim()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contact: WorkOrderAdditionalContact = {
|
||||||
|
name,
|
||||||
|
phone,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (notes.trim()) {
|
||||||
|
contact.notes = notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return contact;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Reads additional POCs from board/detail payloads; missing field yields []. */
|
||||||
|
export function readAdditionalContacts(
|
||||||
|
record: Record<string, unknown>,
|
||||||
|
): WorkOrderAdditionalContact[] {
|
||||||
|
for (const key of ["additionalContacts", "AdditionalContacts"]) {
|
||||||
|
const value = record[key];
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
.map(mapContactItem)
|
||||||
|
.filter((contact): contact is WorkOrderAdditionalContact => contact !== null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drops empty rows and trims strings; returns undefined when nothing to persist. */
|
||||||
|
export function normalizeAdditionalContacts(
|
||||||
|
contacts: WorkOrderAdditionalContact[],
|
||||||
|
): WorkOrderAdditionalContact[] | undefined {
|
||||||
|
const out: WorkOrderAdditionalContact[] = [];
|
||||||
|
|
||||||
|
for (const raw of contacts) {
|
||||||
|
const name = raw.name.trim();
|
||||||
|
const phone = raw.phone.trim();
|
||||||
|
const notes = raw.notes?.trim();
|
||||||
|
|
||||||
|
if (!name && !phone) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const contact: WorkOrderAdditionalContact = { name, phone };
|
||||||
|
|
||||||
|
if (notes) {
|
||||||
|
contact.notes = notes;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.push(contact);
|
||||||
|
}
|
||||||
|
|
||||||
|
return out.length > 0 ? out : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function serializeAdditionalContactsForPatch(
|
||||||
|
contacts: WorkOrderAdditionalContact[],
|
||||||
|
): string {
|
||||||
|
return JSON.stringify(normalizeAdditionalContacts(contacts) ?? []);
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import type { WorkOrderBoardCreatePayload } from "@/domain/work-orders/types/work-order-board";
|
import type { WorkOrderBoardCreatePayload } from "@/domain/work-orders/types/work-order-board";
|
||||||
import type { WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard";
|
import type { WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard";
|
||||||
|
import { normalizeAdditionalContacts } from "@/domain/work-orders/mappers/additional-contacts-mapper";
|
||||||
|
|
||||||
function trimOrUndefined(value: string | undefined): string | undefined {
|
function trimOrUndefined(value: string | undefined): string | undefined {
|
||||||
const trimmed = value?.trim();
|
const trimmed = value?.trim();
|
||||||
|
|
@ -83,6 +84,11 @@ export function assignWizardServicePocFields(
|
||||||
payload.pocNotes = pocNotes;
|
payload.pocNotes = pocNotes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const additionalContacts = normalizeAdditionalContacts(draft.additionalContacts);
|
||||||
|
if (additionalContacts) {
|
||||||
|
payload.additionalContacts = additionalContacts;
|
||||||
|
}
|
||||||
|
|
||||||
const techPhone = trimOrUndefined(draft.techPhone);
|
const techPhone = trimOrUndefined(draft.techPhone);
|
||||||
|
|
||||||
if (techPhone) {
|
if (techPhone) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
import type { WorkOrderBoardEditableField } from "@/domain/work-orders/types/work-order-board";
|
import type { WorkOrderBoardEditableField } from "@/domain/work-orders/types/work-order-board";
|
||||||
import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row";
|
import type { WorkOrderTablePatch } from "@/domain/work-orders/types/work-order-table-row";
|
||||||
|
import type { WorkOrderAdditionalContact } from "@/domain/work-orders/types/work-order-additional-contact";
|
||||||
|
import { serializeAdditionalContactsForPatch } from "@/domain/work-orders/mappers/additional-contacts-mapper";
|
||||||
|
|
||||||
export type BoardFieldOp = {
|
export type BoardFieldOp = {
|
||||||
field: WorkOrderBoardEditableField;
|
field: WorkOrderBoardEditableField;
|
||||||
|
|
@ -34,6 +36,11 @@ const SCALAR_BOARD_OP_RULES: ScalarBoardOpRule[] = [
|
||||||
{ key: "extraServices", field: "extraServices", toValue: (value) => JSON.stringify(value) },
|
{ key: "extraServices", field: "extraServices", toValue: (value) => JSON.stringify(value) },
|
||||||
{ key: "serviceNotes", field: "serviceNotes", toValue: (value) => value as string },
|
{ key: "serviceNotes", field: "serviceNotes", toValue: (value) => value as string },
|
||||||
{ key: "flagColor", field: "flagColor", toValue: (value) => (value as string | null) ?? "" },
|
{ key: "flagColor", field: "flagColor", toValue: (value) => (value as string | null) ?? "" },
|
||||||
|
{
|
||||||
|
key: "additionalContacts",
|
||||||
|
field: "additionalContacts",
|
||||||
|
toValue: (value) => serializeAdditionalContactsForPatch(value as WorkOrderAdditionalContact[]),
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export function expandScalarBoardOps(patch: WorkOrderTablePatch): BoardFieldOp[] {
|
export function expandScalarBoardOps(patch: WorkOrderTablePatch): BoardFieldOp[] {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { readAdditionalContacts } from "@/domain/work-orders/mappers/additional-contacts-mapper";
|
||||||
import { mapApiStatusToWizard } from "@/domain/work-orders/mappers/wizard-draft-mapper";
|
import { mapApiStatusToWizard } from "@/domain/work-orders/mappers/wizard-draft-mapper";
|
||||||
import {
|
import {
|
||||||
DOC_STATUS_API,
|
DOC_STATUS_API,
|
||||||
|
|
@ -258,6 +259,7 @@ export function mapWorkOrderTableRow(raw: unknown): WorkOrderTableRow {
|
||||||
pocName: readString(item, "pocName", "PocName", "POCName"),
|
pocName: readString(item, "pocName", "PocName", "POCName"),
|
||||||
pocPhone: readString(item, "pocPhone", "PocPhone", "POCPhone"),
|
pocPhone: readString(item, "pocPhone", "PocPhone", "POCPhone"),
|
||||||
pocNotes: readString(item, "pocNotes", "PocNotes", "POCNotes"),
|
pocNotes: readString(item, "pocNotes", "PocNotes", "POCNotes"),
|
||||||
|
additionalContacts: readAdditionalContacts(item),
|
||||||
dueDate: toDateInputValue(readString(item, "dueDate", "DueDate")),
|
dueDate: toDateInputValue(readString(item, "dueDate", "DueDate")),
|
||||||
rescheduleCount: readNumber(item, "rescheduleCount", "RescheduleCount") ?? 0,
|
rescheduleCount: readNumber(item, "rescheduleCount", "RescheduleCount") ?? 0,
|
||||||
carriedOver: readNumber(item, "carriedOver", "CarriedOver") ?? 0,
|
carriedOver: readNumber(item, "carriedOver", "CarriedOver") ?? 0,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
export interface WorkOrderAdditionalContact {
|
||||||
|
name: string;
|
||||||
|
phone: string;
|
||||||
|
notes?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const EMPTY_ADDITIONAL_CONTACT: WorkOrderAdditionalContact = {
|
||||||
|
name: "",
|
||||||
|
phone: "",
|
||||||
|
notes: "",
|
||||||
|
};
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import type { WorkOrderAuditEntry, WorkOrderComment } from "./work-order-detail";
|
import type { WorkOrderAuditEntry, WorkOrderComment } from "./work-order-detail";
|
||||||
|
import type { WorkOrderAdditionalContact } from "./work-order-additional-contact";
|
||||||
import type { CompletionDocStatus, WorkOrderTableRow } from "./work-order-table-row";
|
import type { CompletionDocStatus, WorkOrderTableRow } from "./work-order-table-row";
|
||||||
|
|
||||||
/** API media.category: 1=Before, 2=After, 3=Extra, 4=Completion */
|
/** API media.category: 1=Before, 2=After, 3=Extra, 4=Completion */
|
||||||
|
|
@ -26,6 +27,7 @@ export interface WorkOrderBoardDetailInfoApi {
|
||||||
pocName?: string | null;
|
pocName?: string | null;
|
||||||
pocPhone?: string | null;
|
pocPhone?: string | null;
|
||||||
pocNotes?: string | null;
|
pocNotes?: string | null;
|
||||||
|
additionalContacts?: WorkOrderAdditionalContact[] | null;
|
||||||
lifecycleStatus?: number | null;
|
lifecycleStatus?: number | null;
|
||||||
lifecycleStatusLabel?: string | null;
|
lifecycleStatusLabel?: string | null;
|
||||||
legacyStatus?: string | null;
|
legacyStatus?: string | null;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import type { DateRangeKey } from "./work-order-advanced-filters";
|
import type { DateRangeKey } from "./work-order-advanced-filters";
|
||||||
|
import type { WorkOrderAdditionalContact } from "./work-order-additional-contact";
|
||||||
import type { WorkOrderTableRow } from "./work-order-table-row";
|
import type { WorkOrderTableRow } from "./work-order-table-row";
|
||||||
import type { WizardWOStatus, WOType } from "./work-order-wizard";
|
import type { WizardWOStatus, WOType } from "./work-order-wizard";
|
||||||
|
|
||||||
|
|
@ -89,6 +90,7 @@ export interface WorkOrderBoardCreatePayload {
|
||||||
pocName?: string;
|
pocName?: string;
|
||||||
pocPhone?: string;
|
pocPhone?: string;
|
||||||
pocNotes?: string;
|
pocNotes?: string;
|
||||||
|
additionalContacts?: WorkOrderAdditionalContact[];
|
||||||
techPhone?: string;
|
techPhone?: string;
|
||||||
vendorNotes?: string;
|
vendorNotes?: string;
|
||||||
}
|
}
|
||||||
|
|
@ -119,7 +121,8 @@ export type WorkOrderBoardEditableField =
|
||||||
| "pm"
|
| "pm"
|
||||||
| "serviceNotes"
|
| "serviceNotes"
|
||||||
| "extraServices"
|
| "extraServices"
|
||||||
| "flagColor";
|
| "flagColor"
|
||||||
|
| "additionalContacts";
|
||||||
|
|
||||||
/** Espelha WorkOrderBoardRowDto (JSON camelCase). */
|
/** Espelha WorkOrderBoardRowDto (JSON camelCase). */
|
||||||
export interface WorkOrderBoardRowApi {
|
export interface WorkOrderBoardRowApi {
|
||||||
|
|
@ -134,6 +137,7 @@ export interface WorkOrderBoardRowApi {
|
||||||
pocName?: string | null;
|
pocName?: string | null;
|
||||||
pocPhone?: string | null;
|
pocPhone?: string | null;
|
||||||
pocNotes?: string | null;
|
pocNotes?: string | null;
|
||||||
|
additionalContacts?: WorkOrderAdditionalContact[] | null;
|
||||||
lifecycleStatus?: number | null;
|
lifecycleStatus?: number | null;
|
||||||
lifecycleStatusLabel?: string | null;
|
lifecycleStatusLabel?: string | null;
|
||||||
legacyStatus?: string | null;
|
legacyStatus?: string | null;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import type { WorkOrderAdditionalContact } from "./work-order-additional-contact";
|
||||||
import type { WizardWOStatus, WOType } from "./work-order-wizard";
|
import type { WizardWOStatus, WOType } from "./work-order-wizard";
|
||||||
|
|
||||||
export type CompletionDocStatus = "Yes" | "No" | "NN" | "";
|
export type CompletionDocStatus = "Yes" | "No" | "NN" | "";
|
||||||
|
|
@ -34,6 +35,7 @@ export interface WorkOrderTableRow {
|
||||||
pocName: string;
|
pocName: string;
|
||||||
pocPhone: string;
|
pocPhone: string;
|
||||||
pocNotes: string;
|
pocNotes: string;
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
dueDate: string;
|
dueDate: string;
|
||||||
rescheduleCount: number;
|
rescheduleCount: number;
|
||||||
carriedOver: number;
|
carriedOver: number;
|
||||||
|
|
@ -74,6 +76,7 @@ export interface WorkOrderTableDraft {
|
||||||
pocName: string;
|
pocName: string;
|
||||||
pocPhone: string;
|
pocPhone: string;
|
||||||
pocNotes: string;
|
pocNotes: string;
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
scheduleWeekOnly: boolean;
|
scheduleWeekOnly: boolean;
|
||||||
targetWeek: string;
|
targetWeek: string;
|
||||||
}
|
}
|
||||||
|
|
@ -101,6 +104,7 @@ export const EMPTY_TABLE_DRAFT: WorkOrderTableDraft = {
|
||||||
pocName: "",
|
pocName: "",
|
||||||
pocPhone: "",
|
pocPhone: "",
|
||||||
pocNotes: "",
|
pocNotes: "",
|
||||||
|
additionalContacts: [],
|
||||||
scheduleWeekOnly: false,
|
scheduleWeekOnly: false,
|
||||||
targetWeek: "",
|
targetWeek: "",
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import type { WorkOrderAdditionalContact } from "./work-order-additional-contact";
|
||||||
|
|
||||||
export const WO_TYPES = ["PM", "Reactive", "Emergency", "Add-On", "Overdue"] as const;
|
export const WO_TYPES = ["PM", "Reactive", "Emergency", "Add-On", "Overdue"] as const;
|
||||||
|
|
||||||
export type WOType = (typeof WO_TYPES)[number];
|
export type WOType = (typeof WO_TYPES)[number];
|
||||||
|
|
@ -43,6 +45,8 @@ export interface WorkOrderWizardDraft {
|
||||||
pocName: string;
|
pocName: string;
|
||||||
pocPhone: string;
|
pocPhone: string;
|
||||||
pocNotes: string;
|
pocNotes: string;
|
||||||
|
/** Secondary POCs beyond primary pocName/pocPhone/pocNotes. */
|
||||||
|
additionalContacts: WorkOrderAdditionalContact[];
|
||||||
scheduleWeekOnly: boolean;
|
scheduleWeekOnly: boolean;
|
||||||
/** Monday ISO when week-only; preferred over deriving from scheduledOn (inline create). */
|
/** Monday ISO when week-only; preferred over deriving from scheduledOn (inline create). */
|
||||||
targetWeek?: string;
|
targetWeek?: string;
|
||||||
|
|
@ -75,6 +79,7 @@ export const EMPTY_WIZARD_DRAFT: WorkOrderWizardDraft = {
|
||||||
pocName: "",
|
pocName: "",
|
||||||
pocPhone: "",
|
pocPhone: "",
|
||||||
pocNotes: "",
|
pocNotes: "",
|
||||||
|
additionalContacts: [],
|
||||||
scheduleWeekOnly: false,
|
scheduleWeekOnly: false,
|
||||||
targetWeek: "",
|
targetWeek: "",
|
||||||
scheduleEnd: "",
|
scheduleEnd: "",
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import { useController } from "react-hook-form";
|
||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
const rosterGet = vi.fn();
|
const rosterGet = vi.fn();
|
||||||
const saveMutate = vi.fn();
|
|
||||||
|
|
||||||
vi.mock("@/domain/vendors/api/vendor-company-roster-api", () => ({
|
vi.mock("@/domain/vendors/api/vendor-company-roster-api", () => ({
|
||||||
vendorCompanyRosterApi: { get: (...args: unknown[]) => rosterGet(...args) },
|
vendorCompanyRosterApi: { get: (...args: unknown[]) => rosterGet(...args) },
|
||||||
|
|
@ -29,10 +28,7 @@ vi.mock("@/domain/vendors/use-cases/use-save-vendor-company-roster", async () =>
|
||||||
const actual = await vi.importActual<
|
const actual = await vi.importActual<
|
||||||
typeof import("@/domain/vendors/use-cases/use-save-vendor-company-roster")
|
typeof import("@/domain/vendors/use-cases/use-save-vendor-company-roster")
|
||||||
>("@/domain/vendors/use-cases/use-save-vendor-company-roster");
|
>("@/domain/vendors/use-cases/use-save-vendor-company-roster");
|
||||||
return {
|
return { ...actual, useSaveVendorCompanyRoster: () => ({ mutate: vi.fn(), isPending: false }) };
|
||||||
...actual,
|
|
||||||
useSaveVendorCompanyRoster: () => ({ mutate: saveMutate, isPending: false }),
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|
||||||
import { useVendorRosterForm } from "@/app/(protected)/vendors/_components/use-vendor-roster-form";
|
import { useVendorRosterForm } from "@/app/(protected)/vendors/_components/use-vendor-roster-form";
|
||||||
|
|
@ -105,7 +101,6 @@ function deferRoster(): {
|
||||||
describe("useVendorRosterForm load-error handling", () => {
|
describe("useVendorRosterForm load-error handling", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
rosterGet.mockReset();
|
rosterGet.mockReset();
|
||||||
saveMutate.mockReset();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("shows a safe retryable error when selecting an existing company fetch is rejected", async () => {
|
it("shows a safe retryable error when selecting an existing company fetch is rejected", async () => {
|
||||||
|
|
@ -201,44 +196,6 @@ describe("useVendorRosterForm load-error handling", () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("useVendorRosterForm prototype defaults", () => {
|
|
||||||
it("does not persist the prototype's untouched optional technician card", () => {
|
|
||||||
const { result } = renderHook(
|
|
||||||
() => useVendorRosterForm({ mode: "create", startWithTechnician: true }),
|
|
||||||
{ wrapper: makeWrapper(createClient()) },
|
|
||||||
);
|
|
||||||
|
|
||||||
act(() => {
|
|
||||||
result.current.submit({
|
|
||||||
name: "Independent Vendor LLC",
|
|
||||||
companyPhone: "(314) 555-0199",
|
|
||||||
email: "",
|
|
||||||
address: "",
|
|
||||||
city: "",
|
|
||||||
state: "",
|
|
||||||
zip: "",
|
|
||||||
googleMapsUrl: "",
|
|
||||||
notes: "",
|
|
||||||
technicians: [
|
|
||||||
{
|
|
||||||
contactName: "",
|
|
||||||
phone: "",
|
|
||||||
email: "",
|
|
||||||
preferredContact: "Phone",
|
|
||||||
tradeSpecialties: "",
|
|
||||||
isActive: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(saveMutate).toHaveBeenCalledWith(
|
|
||||||
expect.objectContaining({ values: expect.objectContaining({ technicians: [] }) }),
|
|
||||||
expect.any(Object),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("useVendorRosterForm stale-selection handling", () => {
|
describe("useVendorRosterForm stale-selection handling", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
rosterGet.mockReset();
|
rosterGet.mockReset();
|
||||||
|
|
|
||||||
|
|
@ -49,11 +49,11 @@ function rosterWith(technicians: Array<Record<string, unknown>>) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("VendorDetailDrawer selected-technician display", () => {
|
describe("VendorDetailDrawer preferred-contact display", () => {
|
||||||
it("renders no preference label when preferredContact is absent", () => {
|
it("renders no preference label when preferredContact is absent", () => {
|
||||||
useVendorCompanyRoster.mockReturnValue(
|
useVendorCompanyRoster.mockReturnValue(
|
||||||
rosterWith([
|
rosterWith([
|
||||||
{ id: 1, contactName: "Adam", phone: "314-555-0198", isActive: true, totalJobs: 5 },
|
{ id: 7, contactName: "Adam", phone: "314-555-0198", isActive: true, totalJobs: 5 },
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -62,15 +62,15 @@ describe("VendorDetailDrawer selected-technician display", () => {
|
||||||
withAuth: false,
|
withAuth: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(screen.getByRole("heading", { level: 2, name: "Adam" })).toBeInTheDocument();
|
expect(screen.getByText("Adam")).toBeInTheDocument();
|
||||||
expect(screen.queryByText(/^Prefers/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/^Prefers/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("keeps the retired preferred-contact value out of the detail view", () => {
|
it("renders the preference label when an explicit preferredContact is present", () => {
|
||||||
useVendorCompanyRoster.mockReturnValue(
|
useVendorCompanyRoster.mockReturnValue(
|
||||||
rosterWith([
|
rosterWith([
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 7,
|
||||||
contactName: "Adam",
|
contactName: "Adam",
|
||||||
phone: "314-555-0198",
|
phone: "314-555-0198",
|
||||||
preferredContact: "Email",
|
preferredContact: "Email",
|
||||||
|
|
@ -85,52 +85,6 @@ describe("VendorDetailDrawer selected-technician display", () => {
|
||||||
withAuth: false,
|
withAuth: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(screen.getByRole("heading", { level: 2, name: "Adam" })).toBeInTheDocument();
|
expect(screen.getByText("Prefers Email")).toBeInTheDocument();
|
||||||
expect(screen.queryByText(/^Prefers/)).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("falls back to the clicked row when the roster has no matching stable id", () => {
|
|
||||||
useVendorCompanyRoster.mockReturnValue(
|
|
||||||
rosterWith([
|
|
||||||
{
|
|
||||||
id: 7,
|
|
||||||
contactName: "Adam Whyte",
|
|
||||||
phone: "999-999-9999",
|
|
||||||
isActive: true,
|
|
||||||
totalJobs: 99,
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
|
|
||||||
renderWithProviders(<VendorDetailDrawer open={true} vendor={vendor} onClose={vi.fn()} />, {
|
|
||||||
route: "/vendors",
|
|
||||||
withAuth: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(screen.getByText("0")).toBeInTheDocument();
|
|
||||||
expect(screen.queryByText("999-999-9999")).not.toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("does not expose a status control for a different technician", () => {
|
|
||||||
useVendorCompanyRoster.mockReturnValue(
|
|
||||||
rosterWith([
|
|
||||||
{
|
|
||||||
id: 7,
|
|
||||||
contactName: "Different Technician",
|
|
||||||
phone: "314-555-0101",
|
|
||||||
email: "",
|
|
||||||
tradeSpecialties: "Plumbing",
|
|
||||||
isActive: true,
|
|
||||||
totalJobs: 10,
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
|
|
||||||
renderWithProviders(
|
|
||||||
<VendorDetailDrawer open={true} vendor={vendor} startInEdit={true} onClose={vi.fn()} />,
|
|
||||||
{ route: "/vendors", withAuth: false },
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(screen.queryByRole("switch", { name: "Active status" })).not.toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,21 @@
|
||||||
import { screen, within } from "@testing-library/react";
|
import { screen } from "@testing-library/react";
|
||||||
import userEvent from "@testing-library/user-event";
|
import userEvent from "@testing-library/user-event";
|
||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import VendorsListPage from "@/app/(protected)/vendors/index";
|
import VendorsListPage from "@/app/(protected)/vendors/index";
|
||||||
import type { VendorCompanyRoster, VendorListItem } from "@/domain/vendors/types/vendor";
|
import type { VendorListItem } from "@/domain/vendors/types/vendor";
|
||||||
import { renderWithProviders } from "@/test/test-utils";
|
import { renderWithProviders } from "@/test/test-utils";
|
||||||
|
|
||||||
const useVendorsList = vi.fn();
|
const useVendorsList = vi.fn();
|
||||||
const useVendorCompanyRoster = vi.fn();
|
const useVendorCompanyRoster = vi.fn();
|
||||||
const useVendorDeactivationImpact = vi.fn();
|
const useVendorDeactivationImpact = vi.fn();
|
||||||
const mutate = vi.fn();
|
const mutate = vi.fn();
|
||||||
|
const navigate = vi.fn();
|
||||||
|
|
||||||
|
vi.mock("react-router", async () => {
|
||||||
|
const actual = await vi.importActual("react-router");
|
||||||
|
return { ...actual, useNavigate: () => navigate };
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock("@/domain/vendors/use-cases/use-vendors-list", () => ({
|
vi.mock("@/domain/vendors/use-cases/use-vendors-list", () => ({
|
||||||
useVendorsList: (...args: unknown[]) => useVendorsList(...args),
|
useVendorsList: (...args: unknown[]) => useVendorsList(...args),
|
||||||
}));
|
}));
|
||||||
|
|
@ -54,32 +61,6 @@ const inactiveVendor = {
|
||||||
isActive: false,
|
isActive: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
const activeRoster: VendorCompanyRoster = {
|
|
||||||
companyId: "co-1",
|
|
||||||
rowVersion: "rv-1",
|
|
||||||
name: "Gateway Plumbing",
|
|
||||||
companyPhone: "(314) 555-0100",
|
|
||||||
email: "dispatch@gatewayplumbing.com",
|
|
||||||
address: "",
|
|
||||||
city: "St. Louis",
|
|
||||||
state: "MO",
|
|
||||||
zip: "",
|
|
||||||
googleMapsUrl: "",
|
|
||||||
notes: "",
|
|
||||||
technicians: [
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
contactName: "Adam Whyte",
|
|
||||||
phone: "(314) 555-0198",
|
|
||||||
email: "dispatch@gatewayplumbing.com",
|
|
||||||
preferredContact: "Email",
|
|
||||||
tradeSpecialties: "Backflow Preventers",
|
|
||||||
isActive: true,
|
|
||||||
totalJobs: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
function result(items: VendorListItem[], totalCount: number) {
|
function result(items: VendorListItem[], totalCount: number) {
|
||||||
return {
|
return {
|
||||||
data: { items, totalCount, page: 1, pageSize: 12 },
|
data: { items, totalCount, page: 1, pageSize: 12 },
|
||||||
|
|
@ -90,13 +71,7 @@ function result(items: VendorListItem[], totalCount: number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupDefaults() {
|
function setupDefaults() {
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
useVendorCompanyRoster.mockReturnValue({ data: undefined, isLoading: false, error: null });
|
||||||
data: undefined,
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
useVendorDeactivationImpact.mockReturnValue({
|
useVendorDeactivationImpact.mockReturnValue({
|
||||||
data: undefined,
|
data: undefined,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
|
|
@ -105,7 +80,7 @@ function setupDefaults() {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("VendorsListPage", () => {
|
describe("VendorsListPage", () => {
|
||||||
it("renders prototype-aligned status and two row actions in both tabs", async () => {
|
it("renders prototype-aligned status tabs and location, then hides deactivation for inactive rows", async () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
if (params.pageSize === 1) return result([], params.isActive ? 1 : 1);
|
if (params.pageSize === 1) return result([], params.isActive ? 1 : 1);
|
||||||
|
|
@ -116,20 +91,11 @@ describe("VendorsListPage", () => {
|
||||||
|
|
||||||
expect(screen.getByRole("heading", { name: "Vendors / Technicians" })).toBeInTheDocument();
|
expect(screen.getByRole("heading", { name: "Vendors / Technicians" })).toBeInTheDocument();
|
||||||
expect(screen.getByText("St. Louis, MO")).toBeInTheDocument();
|
expect(screen.getByText("St. Louis, MO")).toBeInTheDocument();
|
||||||
expect(screen.getByRole("columnheader", { name: "Status" })).toBeInTheDocument();
|
expect(screen.getByRole("button", { name: "Deactivate vendor" })).toBeInTheDocument();
|
||||||
expect(screen.getByRole("cell", { name: "Active" })).toBeInTheDocument();
|
|
||||||
expect(
|
|
||||||
screen.getByRole("button", { name: "View vendor Gateway Plumbing" }),
|
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(
|
|
||||||
screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }),
|
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(screen.queryByRole("button", { name: "Deactivate vendor" })).not.toBeInTheDocument();
|
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole("tab", { name: "Inactive (1)" }));
|
await userEvent.click(screen.getByRole("tab", { name: "Inactive (1)" }));
|
||||||
|
|
||||||
expect(screen.getByText("Drain Cleaning Bros")).toBeInTheDocument();
|
expect(screen.getByText("Drain Cleaning Bros")).toBeInTheDocument();
|
||||||
expect(screen.getByRole("cell", { name: "Inactive" })).toBeInTheDocument();
|
|
||||||
expect(screen.queryByRole("button", { name: "Deactivate vendor" })).not.toBeInTheDocument();
|
expect(screen.queryByRole("button", { name: "Deactivate vendor" })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -148,18 +114,39 @@ describe("VendorsListPage", () => {
|
||||||
|
|
||||||
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
||||||
|
|
||||||
expect(screen.getByText(/25 active technicians/)).toBeInTheDocument();
|
expect(screen.getByText(/25 active vendor entries/)).toBeInTheDocument();
|
||||||
expect(screen.queryByText(/3 active technicians/)).not.toBeInTheDocument();
|
expect(screen.queryByText(/3 active vendor entries/)).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens the detail drawer when a row is clicked or activated by keyboard", async () => {
|
it("opens the detail drawer when a row is clicked or activated by keyboard", async () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
useVendorCompanyRoster.mockReturnValue({
|
||||||
data: activeRoster,
|
data: {
|
||||||
|
companyId: "co-1",
|
||||||
|
rowVersion: "rv-1",
|
||||||
|
name: "Gateway Plumbing",
|
||||||
|
companyPhone: "(314) 555-0198",
|
||||||
|
email: "dispatch@gatewayplumbing.com",
|
||||||
|
address: "",
|
||||||
|
city: "St. Louis",
|
||||||
|
state: "MO",
|
||||||
|
zip: "",
|
||||||
|
googleMapsUrl: "",
|
||||||
|
notes: "",
|
||||||
|
technicians: [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
contactName: "Adam Whyte",
|
||||||
|
phone: "(314) 555-0198",
|
||||||
|
email: "dispatch@gatewayplumbing.com",
|
||||||
|
preferredContact: "Email",
|
||||||
|
tradeSpecialties: "Backflow Preventers",
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
isError: false,
|
|
||||||
error: null,
|
error: null,
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
});
|
||||||
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
if (params.pageSize === 1) return result([], 1);
|
if (params.pageSize === 1) return result([], 1);
|
||||||
|
|
@ -174,18 +161,11 @@ describe("VendorsListPage", () => {
|
||||||
row.focus();
|
row.focus();
|
||||||
await userEvent.keyboard("{Enter}");
|
await userEvent.keyboard("{Enter}");
|
||||||
|
|
||||||
expect(screen.getByRole("heading", { level: 2, name: "Adam Whyte" })).toBeInTheDocument();
|
expect(screen.getByRole("heading", { level: 2, name: "Gateway Plumbing" })).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("blocks deactivation when the preflight reports open work orders", async () => {
|
it("blocks deactivation when the preflight reports open work orders", async () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
|
||||||
data: activeRoster,
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
useVendorDeactivationImpact.mockReturnValue({
|
useVendorDeactivationImpact.mockReturnValue({
|
||||||
data: {
|
data: {
|
||||||
vendorId: 1,
|
vendorId: 1,
|
||||||
|
|
@ -209,8 +189,7 @@ describe("VendorsListPage", () => {
|
||||||
|
|
||||||
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
await userEvent.click(screen.getByRole("button", { name: "Deactivate vendor" }));
|
||||||
await userEvent.click(screen.getByRole("switch", { name: "Active status" }));
|
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
screen.getByText(/cannot be deactivated because it still has open work orders/),
|
screen.getByText(/cannot be deactivated because it still has open work orders/),
|
||||||
|
|
@ -220,51 +199,9 @@ describe("VendorsListPage", () => {
|
||||||
expect(mutate).not.toHaveBeenCalled();
|
expect(mutate).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("preserves inline edits when deactivation is cancelled", async () => {
|
it("navigates to the vendor edit route when the table Edit control is clicked", async () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
navigate.mockClear();
|
||||||
data: activeRoster,
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
useVendorDeactivationImpact.mockReturnValue({
|
|
||||||
data: { vendorId: 1, canDeactivate: true, openWorkOrders: [] },
|
|
||||||
isLoading: false,
|
|
||||||
error: null,
|
|
||||||
});
|
|
||||||
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
|
||||||
if (params.pageSize === 1) return result([], 1);
|
|
||||||
return params.isActive ? result([activeVendor], 1) : result([], 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
|
||||||
const company = screen.getByRole("textbox", { name: "Company" });
|
|
||||||
await userEvent.clear(company);
|
|
||||||
await userEvent.type(company, "Draft Company Name");
|
|
||||||
await userEvent.click(screen.getByRole("switch", { name: "Active status" }));
|
|
||||||
await userEvent.click(
|
|
||||||
within(screen.getByRole("dialog", { name: "Deactivate Vendor" })).getByRole("button", {
|
|
||||||
name: "Cancel",
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(company).toBeInTheDocument();
|
|
||||||
expect(company).toHaveValue("Draft Company Name");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("opens inline edit when the table Edit control is clicked", async () => {
|
|
||||||
setupDefaults();
|
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
|
||||||
data: activeRoster,
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
if (params.pageSize === 1) return result([], 1);
|
if (params.pageSize === 1) return result([], 1);
|
||||||
return params.isActive ? result([activeVendor], 1) : result([], 0);
|
return params.isActive ? result([activeVendor], 1) : result([], 0);
|
||||||
|
|
@ -274,20 +211,16 @@ describe("VendorsListPage", () => {
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
||||||
|
|
||||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeInTheDocument();
|
expect(navigate).toHaveBeenCalledWith("/vendors/edit/1");
|
||||||
expect(screen.getByRole("textbox", { name: "Company" })).toHaveValue("Gateway Plumbing");
|
expect(
|
||||||
|
screen.queryByRole("heading", { level: 2, name: "Gateway Plumbing" }),
|
||||||
|
).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("opens inline company edit when the row has no vendor id", async () => {
|
it("navigates to the company route when editing a vendor without a vendor id", async () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
|
navigate.mockClear();
|
||||||
const companyOnlyVendor = { ...activeVendor, id: null, companyId: "co-9" };
|
const companyOnlyVendor = { ...activeVendor, id: null, companyId: "co-9" };
|
||||||
useVendorCompanyRoster.mockReturnValue({
|
|
||||||
data: { ...activeRoster, companyId: "co-9", technicians: [] },
|
|
||||||
isLoading: false,
|
|
||||||
isError: false,
|
|
||||||
error: null,
|
|
||||||
refetch: vi.fn(),
|
|
||||||
});
|
|
||||||
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
if (params.pageSize === 1) return result([], 1);
|
if (params.pageSize === 1) return result([], 1);
|
||||||
return params.isActive ? result([companyOnlyVendor], 1) : result([], 0);
|
return params.isActive ? result([companyOnlyVendor], 1) : result([], 0);
|
||||||
|
|
@ -297,7 +230,6 @@ describe("VendorsListPage", () => {
|
||||||
|
|
||||||
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
await userEvent.click(screen.getByRole("button", { name: "Edit vendor Gateway Plumbing" }));
|
||||||
|
|
||||||
expect(screen.getByRole("button", { name: "Save changes" })).toBeInTheDocument();
|
expect(navigate).toHaveBeenCalledWith("/vendors/company/co-9");
|
||||||
expect(screen.getByRole("textbox", { name: "Company" })).toHaveValue("Gateway Plumbing");
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -95,6 +95,7 @@ const canceledRow: WorkOrderTableRow = {
|
||||||
pocName: "",
|
pocName: "",
|
||||||
pocPhone: "",
|
pocPhone: "",
|
||||||
pocNotes: "",
|
pocNotes: "",
|
||||||
|
additionalContacts: [],
|
||||||
dueDate: "",
|
dueDate: "",
|
||||||
rescheduleCount: 0,
|
rescheduleCount: 0,
|
||||||
carriedOver: 0,
|
carriedOver: 0,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import {
|
||||||
|
normalizeAdditionalContacts,
|
||||||
|
readAdditionalContacts,
|
||||||
|
serializeAdditionalContactsForPatch,
|
||||||
|
} from "@/domain/work-orders/mappers/additional-contacts-mapper";
|
||||||
|
|
||||||
|
describe("readAdditionalContacts", () => {
|
||||||
|
it("returns [] when field is missing", () => {
|
||||||
|
expect(readAdditionalContacts({ id: 1 })).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("maps camelCase and PascalCase arrays", () => {
|
||||||
|
expect(
|
||||||
|
readAdditionalContacts({
|
||||||
|
additionalContacts: [{ name: "Alex", phone: "555-0100", notes: "Gate code" }],
|
||||||
|
}),
|
||||||
|
).toEqual([{ name: "Alex", phone: "555-0100", notes: "Gate code" }]);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
readAdditionalContacts({
|
||||||
|
AdditionalContacts: [{ Name: "Sam", Phone: "555-0200" }],
|
||||||
|
}),
|
||||||
|
).toEqual([{ name: "Sam", phone: "555-0200" }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("drops empty rows", () => {
|
||||||
|
expect(
|
||||||
|
readAdditionalContacts({
|
||||||
|
additionalContacts: [
|
||||||
|
{ name: "", phone: "" },
|
||||||
|
{ name: "Pat", phone: "111" },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
).toEqual([{ name: "Pat", phone: "111" }]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("normalizeAdditionalContacts", () => {
|
||||||
|
it("trims and omits empty notes", () => {
|
||||||
|
expect(
|
||||||
|
normalizeAdditionalContacts([
|
||||||
|
{ name: " Alex ", phone: " 555 ", notes: " " },
|
||||||
|
{ name: "", phone: "" },
|
||||||
|
]),
|
||||||
|
).toEqual([{ name: "Alex", phone: "555" }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns undefined when all rows are empty", () => {
|
||||||
|
expect(normalizeAdditionalContacts([{ name: "", phone: "" }])).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("serializeAdditionalContactsForPatch", () => {
|
||||||
|
it("JSON-stringifies normalized contacts for board PATCH", () => {
|
||||||
|
expect(
|
||||||
|
serializeAdditionalContactsForPatch([
|
||||||
|
{ name: "Alex", phone: "555-0100" },
|
||||||
|
{ name: "", phone: "" },
|
||||||
|
]),
|
||||||
|
).toBe('[{"name":"Alex","phone":"555-0100"}]');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("serializes empty array when nothing to persist", () => {
|
||||||
|
expect(serializeAdditionalContactsForPatch([])).toBe("[]");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -94,6 +94,8 @@ describe("mapWizardDraftToBoardCreatePayload", () => {
|
||||||
|
|
||||||
pocNotes: "Call before arrival",
|
pocNotes: "Call before arrival",
|
||||||
|
|
||||||
|
additionalContacts: [{ name: "Backup Lead", phone: "+1 555-0101", notes: "After hours" }],
|
||||||
|
|
||||||
techPhone: "+1 555-0199",
|
techPhone: "+1 555-0199",
|
||||||
|
|
||||||
vendorNotes: "Gate code 4421",
|
vendorNotes: "Gate code 4421",
|
||||||
|
|
@ -137,6 +139,8 @@ describe("mapWizardDraftToBoardCreatePayload", () => {
|
||||||
vendorNotes: "Gate code 4421",
|
vendorNotes: "Gate code 4421",
|
||||||
|
|
||||||
locationId: 12,
|
locationId: 12,
|
||||||
|
|
||||||
|
additionalContacts: [{ name: "Backup Lead", phone: "+1 555-0101", notes: "After hours" }],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(payload.trade).toBeUndefined();
|
expect(payload.trade).toBeUndefined();
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,19 @@ describe("expandTablePatchToBoardFieldOps", () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("emits additionalContacts as serialized JSON for board PATCH", () => {
|
||||||
|
expect(
|
||||||
|
expandTablePatchToBoardFieldOps({
|
||||||
|
additionalContacts: [{ name: "Alex", phone: "555-0100", notes: "Gate" }],
|
||||||
|
}),
|
||||||
|
).toEqual([
|
||||||
|
{
|
||||||
|
field: "additionalContacts",
|
||||||
|
value: JSON.stringify([{ name: "Alex", phone: "555-0100", notes: "Gate" }]),
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("ignores local-only companion keys when expanding vendor/site", () => {
|
it("ignores local-only companion keys when expanding vendor/site", () => {
|
||||||
expect(
|
expect(
|
||||||
expandTablePatchToBoardFieldOps({
|
expandTablePatchToBoardFieldOps({
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ describe("mapWorkOrderTableRow (board DTO)", () => {
|
||||||
expect(row.serviceNotes).toBe("service notes");
|
expect(row.serviceNotes).toBe("service notes");
|
||||||
expect(row.extraServices).toEqual(["Filter change", "Coil clean"]);
|
expect(row.extraServices).toEqual(["Filter change", "Coil clean"]);
|
||||||
expect(row.docStatus).toBe("Yes");
|
expect(row.docStatus).toBe("Yes");
|
||||||
|
expect(row.additionalContacts).toEqual([]);
|
||||||
expect(row.dayGroup).toBe("07/15");
|
expect(row.dayGroup).toBe("07/15");
|
||||||
expect(row.flagColor).toBe("#EF4444");
|
expect(row.flagColor).toBe("#EF4444");
|
||||||
});
|
});
|
||||||
|
|
@ -119,4 +120,13 @@ describe("mapWorkOrderTableRow (board DTO)", () => {
|
||||||
expect(mapWorkOrderTableRow({ id: 1, flagColor: "" }).flagColor).toBeNull();
|
expect(mapWorkOrderTableRow({ id: 1, flagColor: "" }).flagColor).toBeNull();
|
||||||
expect(mapWorkOrderTableRow({ id: 1, FlagColor: "#3B82F6" }).flagColor).toBe("#3B82F6");
|
expect(mapWorkOrderTableRow({ id: 1, FlagColor: "#3B82F6" }).flagColor).toBe("#3B82F6");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("maps additionalContacts from board rows", () => {
|
||||||
|
expect(
|
||||||
|
mapWorkOrderTableRow({
|
||||||
|
id: 1,
|
||||||
|
additionalContacts: [{ name: "Alex", phone: "555-0100" }],
|
||||||
|
}).additionalContacts,
|
||||||
|
).toEqual([{ name: "Alex", phone: "555-0100" }]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ function baseRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow
|
||||||
pocName: "",
|
pocName: "",
|
||||||
pocPhone: "",
|
pocPhone: "",
|
||||||
pocNotes: "",
|
pocNotes: "",
|
||||||
|
additionalContacts: [],
|
||||||
dueDate: "2026-07-20",
|
dueDate: "2026-07-20",
|
||||||
rescheduleCount: 0,
|
rescheduleCount: 0,
|
||||||
carriedOver: 0,
|
carriedOver: 0,
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ function makeRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow
|
||||||
pocName: "",
|
pocName: "",
|
||||||
pocPhone: "",
|
pocPhone: "",
|
||||||
pocNotes: "",
|
pocNotes: "",
|
||||||
|
additionalContacts: [],
|
||||||
dueDate: "2026-06-30",
|
dueDate: "2026-06-30",
|
||||||
rescheduleCount: 0,
|
rescheduleCount: 0,
|
||||||
carriedOver: 0,
|
carriedOver: 0,
|
||||||
|
|
|
||||||
37
tmp/pr-descriptions/pr6-multi-poc.md
Normal file
37
tmp/pr-descriptions/pr6-multi-poc.md
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
## Jira
|
||||||
|
|
||||||
|
- [SH-218](https://luby-us.atlassian.net/browse/SH-218) — multiple additional contacts
|
||||||
|
- Related: [SH-108](https://luby-us.atlassian.net/browse/SH-108)
|
||||||
|
|
||||||
|
## QA residual
|
||||||
|
|
||||||
|
- Pass-UI / Blocked-BE until `additionalContacts` lands. Documented in pending BE contract.
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
- Add `additionalContacts[]` (`{ name, phone, notes? }`) across board types, table rows, wizard draft, create payload, and PATCH expansion.
|
||||||
|
- Site dialog and wizard step 2 share editable primary POC fields plus **+ Add point of contact** for POC 2+; wizard sidebar summarizes additional contacts.
|
||||||
|
- Missing backend field tolerates as `[]`; normalized contacts persist via `field: "additionalContacts"` JSON PATCH and POST create.
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
**In:** `additionalContacts` types/mappers (create, detail row, PATCH); Site dialog; wizard step 2; persist + display POC 2+.
|
||||||
|
|
||||||
|
**Out:** Add technician (PR7), severity (PR2/PR5), filters, uplift (PR3–PR5).
|
||||||
|
|
||||||
|
## Backend contract
|
||||||
|
|
||||||
|
See `docs/work-orders/pending-be-contract.md` — confirm `additionalContacts[]` on GET board/detail, POST create, and PATCH before production. Until then FE sends typed payloads and reads missing field as `[]`.
|
||||||
|
|
||||||
|
## Test plan
|
||||||
|
|
||||||
|
- [ ] Open Site dialog on a board row → edit primary POC, add a second contact, Save → network PATCH includes `additionalContacts` JSON.
|
||||||
|
- [ ] New WO wizard step 2 → add additional POC → create payload includes `additionalContacts`.
|
||||||
|
- [ ] Reload board row with BE returning `additionalContacts` → Site dialog shows stored POC 2+.
|
||||||
|
- [ ] BE omitting `additionalContacts` → no UI errors; lists render empty.
|
||||||
|
- [ ] `npm run verify` green.
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- Primary POC remains `pocName` / `pocPhone` / `pocNotes`; `additionalContacts` holds POC 2+ only.
|
||||||
|
- Site save still PATCHes `siteCode`; POC scalar fields remain local-only cache until BE exposes scalar PATCH.
|
||||||
Loading…
Add table
Reference in a new issue