mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 09:43:12 +00:00
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import type { Location } from "@/domain/locations/types/location";
|
|
import type { CompDocSiteInfo } from "@/domain/work-orders/types/completion-doc";
|
|
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
|
|
|
function buildLabel(city?: string, state?: string): string {
|
|
return [city, state].filter(Boolean).join(", ");
|
|
}
|
|
|
|
export function resolveCompDocSite(
|
|
row: Pick<WorkOrderTableRow, "site" | "location">,
|
|
location?: Location | null,
|
|
): CompDocSiteInfo {
|
|
if (location?.address || location?.city) {
|
|
const city = location.city ?? "";
|
|
const state = location.state ?? "";
|
|
const zip = location.zipCode ?? "";
|
|
const label = buildLabel(city, state);
|
|
const street = location.address ?? "";
|
|
const fullAddress = [street, label, zip].filter(Boolean).join(", ") || "—";
|
|
return { street, city, state, zip, label, fullAddress };
|
|
}
|
|
|
|
const locationParts = row.location.split(",").map((s) => s.trim());
|
|
const city = locationParts[0] ?? "";
|
|
const state = locationParts[1] ?? "";
|
|
const label = buildLabel(city, state);
|
|
const street = row.location && !label ? row.location : "";
|
|
const fullAddress = [street, label].filter(Boolean).join(", ") || "—";
|
|
|
|
return { street, city, state, zip: "", label, fullAddress };
|
|
}
|