Merge branch 'fix/sh-221-board-create-customer' of https://github.com/Sea-Haven-Industries/shoc-frontend-new into fix/sh-221-board-create-customer

This commit is contained in:
Arthur Bassi 2026-08-25 21:11:38 -03:00
commit 2bff57fd02
6 changed files with 59 additions and 4 deletions

View file

@ -61,7 +61,9 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
const trades = splitTrades(row.tradeSpecialties);
const primaryTrade = trades[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 handleKeyDown = (event: KeyboardEvent) => {
@ -132,14 +134,14 @@ function VendorTableRow({ row, onOpenDetail, onOpenEdit }: VendorTableRowProps)
)}
</TableCell>
<TableCell sx={{ color: "var(--color-muted-foreground)" }}>
{row.phone ? (
{phoneText ? (
<Link
href={`tel:${row.phone}`}
href={`tel:${phoneText}`}
underline="hover"
color="inherit"
onClick={stopPropagation}
>
{row.phone}
{phoneText}
</Link>
) : (
"—"

View file

@ -119,6 +119,7 @@ export function mapVendorListItem(raw: unknown): VendorListItem {
googleMapsUrl: readString(item, "googleMapsUrl", "GoogleMapsUrl"),
notes: readString(item, "notes", "Notes"),
totalJobs: readNumber(item, "totalJobs", "TotalJobs"),
address: readString(item, "address", "Address"),
city: readString(item, "city", "City"),
state: readString(item, "state", "State"),
tradeSpecialties: readString(item, "tradeSpecialties", "TradeSpecialties"),

View file

@ -13,6 +13,7 @@ export interface VendorListItem {
googleMapsUrl: string;
notes: string;
totalJobs: number;
address: string;
city: string;
state: string;
tradeSpecialties: string;

View file

@ -33,6 +33,7 @@ const vendor: VendorListItem = {
googleMapsUrl: "",
notes: "",
totalJobs: 0,
address: "",
city: "",
state: "",
tradeSpecialties: "",

View file

@ -40,6 +40,7 @@ const activeVendor: VendorListItem = {
googleMapsUrl: "",
notes: "",
totalJobs: 0,
address: "1 Market St",
city: "St. Louis",
state: "MO",
tradeSpecialties: "Backflow Preventers",
@ -133,6 +134,53 @@ describe("VendorsListPage", () => {
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", () => {
setupDefaults();
const pageVendors = Array.from({ length: 3 }, (_, index) => ({

View file

@ -28,6 +28,7 @@ describe("vendorsApi.getList", () => {
CompanyId: "co-1",
CompanyName: "Gateway Plumbing",
ContactName: "Adam Whyte",
Address: "1 Market St",
City: "St. Louis",
State: "MO",
IsActive: false,
@ -45,6 +46,7 @@ describe("vendorsApi.getList", () => {
searchParams: { search: "gateway", isActive: "false", page: 1, pageSize: 12 },
});
expect(result.items[0]).toMatchObject({
address: "1 Market St",
city: "St. Louis",
state: "MO",
isActive: false,