mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 11:12:04 +00:00
Merge branch 'dev' into fix/sh-221-board-create-customer
This commit is contained in:
commit
367e7f8a10
6 changed files with 59 additions and 4 deletions
|
|
@ -61,7 +61,9 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
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 cityStateText = [row.city.trim(), row.state.trim()].filter(Boolean).join(", ");
|
||||||
|
const locationText = cityStateText || row.address.trim() || "—";
|
||||||
|
const phoneText = row.phone.trim() || row.companyPhone.trim();
|
||||||
const rowKey = String(row.id ?? `company-${row.companyId ?? ""}`);
|
const rowKey = String(row.id ?? `company-${row.companyId ?? ""}`);
|
||||||
|
|
||||||
const handleKeyDown = (event: KeyboardEvent) => {
|
const handleKeyDown = (event: KeyboardEvent) => {
|
||||||
|
|
@ -132,14 +134,14 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
|
||||||
)}
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
|
||||||
{row.phone ? (
|
{phoneText ? (
|
||||||
<Link
|
<Link
|
||||||
href={`tel:${row.phone}`}
|
href={`tel:${phoneText}`}
|
||||||
underline="hover"
|
underline="hover"
|
||||||
color="inherit"
|
color="inherit"
|
||||||
onClick={stopPropagation}
|
onClick={stopPropagation}
|
||||||
>
|
>
|
||||||
{row.phone}
|
{phoneText}
|
||||||
</Link>
|
</Link>
|
||||||
) : (
|
) : (
|
||||||
"—"
|
"—"
|
||||||
|
|
|
||||||
1
src/domain/vendors/mappers/vendor-mapper.ts
vendored
1
src/domain/vendors/mappers/vendor-mapper.ts
vendored
|
|
@ -119,6 +119,7 @@ export function mapVendorListItem(raw: unknown): VendorListItem {
|
||||||
googleMapsUrl: readString(item, "googleMapsUrl", "GoogleMapsUrl"),
|
googleMapsUrl: readString(item, "googleMapsUrl", "GoogleMapsUrl"),
|
||||||
notes: readString(item, "notes", "Notes"),
|
notes: readString(item, "notes", "Notes"),
|
||||||
totalJobs: readNumber(item, "totalJobs", "TotalJobs"),
|
totalJobs: readNumber(item, "totalJobs", "TotalJobs"),
|
||||||
|
address: readString(item, "address", "Address"),
|
||||||
city: readString(item, "city", "City"),
|
city: readString(item, "city", "City"),
|
||||||
state: readString(item, "state", "State"),
|
state: readString(item, "state", "State"),
|
||||||
tradeSpecialties: readString(item, "tradeSpecialties", "TradeSpecialties"),
|
tradeSpecialties: readString(item, "tradeSpecialties", "TradeSpecialties"),
|
||||||
|
|
|
||||||
1
src/domain/vendors/types/vendor.ts
vendored
1
src/domain/vendors/types/vendor.ts
vendored
|
|
@ -13,6 +13,7 @@ export interface VendorListItem {
|
||||||
googleMapsUrl: string;
|
googleMapsUrl: string;
|
||||||
notes: string;
|
notes: string;
|
||||||
totalJobs: number;
|
totalJobs: number;
|
||||||
|
address: string;
|
||||||
city: string;
|
city: string;
|
||||||
state: string;
|
state: string;
|
||||||
tradeSpecialties: string;
|
tradeSpecialties: string;
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@ const vendor: VendorListItem = {
|
||||||
googleMapsUrl: "",
|
googleMapsUrl: "",
|
||||||
notes: "",
|
notes: "",
|
||||||
totalJobs: 0,
|
totalJobs: 0,
|
||||||
|
address: "",
|
||||||
city: "",
|
city: "",
|
||||||
state: "",
|
state: "",
|
||||||
tradeSpecialties: "",
|
tradeSpecialties: "",
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,7 @@ const activeVendor: VendorListItem = {
|
||||||
googleMapsUrl: "",
|
googleMapsUrl: "",
|
||||||
notes: "",
|
notes: "",
|
||||||
totalJobs: 0,
|
totalJobs: 0,
|
||||||
|
address: "1 Market St",
|
||||||
city: "St. Louis",
|
city: "St. Louis",
|
||||||
state: "MO",
|
state: "MO",
|
||||||
tradeSpecialties: "Backflow Preventers",
|
tradeSpecialties: "Backflow Preventers",
|
||||||
|
|
@ -133,6 +134,53 @@ describe("VendorsListPage", () => {
|
||||||
expect(screen.queryByRole("button", { name: "Deactivate vendor" })).not.toBeInTheDocument();
|
expect(screen.queryByRole("button", { name: "Deactivate vendor" })).not.toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("prefers trimmed city and state over address and technician phone over company phone", () => {
|
||||||
|
setupDefaults();
|
||||||
|
const vendorWithAllFields: VendorListItem = {
|
||||||
|
...activeVendor,
|
||||||
|
id: 3,
|
||||||
|
address: " 1 Market St ",
|
||||||
|
city: " St. Louis ",
|
||||||
|
state: " MO ",
|
||||||
|
phone: " (314) 555-0198 ",
|
||||||
|
};
|
||||||
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
|
if (params.pageSize === 1) return result([], 1);
|
||||||
|
return params.isActive ? result([vendorWithAllFields], 1) : result([], 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
||||||
|
|
||||||
|
expect(screen.getByText("St. Louis, MO")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText(/1 Market St/)).not.toBeInTheDocument();
|
||||||
|
const phoneLink = screen.getByRole("link", { name: "(314) 555-0198" });
|
||||||
|
expect(phoneLink).toHaveAttribute("href", "tel:(314) 555-0198");
|
||||||
|
expect(screen.queryByText("(314) 555-0100")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("falls back to the trimmed address and company phone when technician fields are absent", () => {
|
||||||
|
setupDefaults();
|
||||||
|
const fallbackVendor: VendorListItem = {
|
||||||
|
...activeVendor,
|
||||||
|
id: 3,
|
||||||
|
address: " 1 Market St ",
|
||||||
|
city: " ",
|
||||||
|
state: "",
|
||||||
|
phone: " ",
|
||||||
|
};
|
||||||
|
useVendorsList.mockImplementation((params: { isActive?: boolean; pageSize?: number }) => {
|
||||||
|
if (params.pageSize === 1) return result([], 1);
|
||||||
|
return params.isActive ? result([fallbackVendor], 1) : result([], 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
renderWithProviders(<VendorsListPage />, { route: "/vendors", withAuth: false });
|
||||||
|
|
||||||
|
expect(screen.getByText("1 Market St")).toBeInTheDocument();
|
||||||
|
const companyPhoneLink = screen.getByRole("link", { name: "(314) 555-0100" });
|
||||||
|
expect(companyPhoneLink).toHaveAttribute("href", "tel:(314) 555-0100");
|
||||||
|
expect(screen.queryByText(/555-0198/)).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it("reports the filtered totalCount in the footer when page rows are fewer than total", () => {
|
it("reports the filtered totalCount in the footer when page rows are fewer than total", () => {
|
||||||
setupDefaults();
|
setupDefaults();
|
||||||
const pageVendors = Array.from({ length: 3 }, (_, index) => ({
|
const pageVendors = Array.from({ length: 3 }, (_, index) => ({
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ describe("vendorsApi.getList", () => {
|
||||||
CompanyId: "co-1",
|
CompanyId: "co-1",
|
||||||
CompanyName: "Gateway Plumbing",
|
CompanyName: "Gateway Plumbing",
|
||||||
ContactName: "Adam Whyte",
|
ContactName: "Adam Whyte",
|
||||||
|
Address: "1 Market St",
|
||||||
City: "St. Louis",
|
City: "St. Louis",
|
||||||
State: "MO",
|
State: "MO",
|
||||||
IsActive: false,
|
IsActive: false,
|
||||||
|
|
@ -45,6 +46,7 @@ describe("vendorsApi.getList", () => {
|
||||||
searchParams: { search: "gateway", isActive: "false", page: 1, pageSize: 12 },
|
searchParams: { search: "gateway", isActive: "false", page: 1, pageSize: 12 },
|
||||||
});
|
});
|
||||||
expect(result.items[0]).toMatchObject({
|
expect(result.items[0]).toMatchObject({
|
||||||
|
address: "1 Market St",
|
||||||
city: "St. Louis",
|
city: "St. Louis",
|
||||||
state: "MO",
|
state: "MO",
|
||||||
isActive: false,
|
isActive: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue