mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 12:22:03 +00:00
fix(work-orders): stop uplift column reading WO status; strip blank techs
mapUpliftSummary no longer treats row status as uplift primaryStatus, getUpliftCellLabel hides pills without hasUplift, and vendor submit filters blank new technicians.
This commit is contained in:
parent
31c5559d23
commit
d5fd6aa5d6
4 changed files with 60 additions and 4 deletions
|
|
@ -20,6 +20,24 @@ 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;
|
||||||
|
|
@ -109,7 +127,7 @@ export function useVendorRosterForm({
|
||||||
save.mutate(
|
save.mutate(
|
||||||
{
|
{
|
||||||
mode: isUpdate ? "update" : "create",
|
mode: isUpdate ? "update" : "create",
|
||||||
values: formValues,
|
values: withoutBlankNewTechnicians(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,
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,8 @@ function normalizeUpliftStatus(raw: string): WorkOrderUpliftStatus {
|
||||||
export function mapUpliftSummary(raw: unknown): UpliftSummary {
|
export function mapUpliftSummary(raw: unknown): UpliftSummary {
|
||||||
const item = asRecord(raw);
|
const item = asRecord(raw);
|
||||||
const nested = asRecord(item.upliftSummary ?? item.UpliftSummary);
|
const nested = asRecord(item.upliftSummary ?? item.UpliftSummary);
|
||||||
const source = Object.keys(nested).length > 0 ? nested : item;
|
const hasNested = Object.keys(nested).length > 0;
|
||||||
|
const source = hasNested ? nested : item;
|
||||||
|
|
||||||
const pendingCount =
|
const pendingCount =
|
||||||
readNumber(source, "pendingCount", "PendingCount") ??
|
readNumber(source, "pendingCount", "PendingCount") ??
|
||||||
|
|
@ -99,8 +100,13 @@ export function mapUpliftSummary(raw: unknown): UpliftSummary {
|
||||||
readBool(item, "hasUplift", "HasUplift") ||
|
readBool(item, "hasUplift", "HasUplift") ||
|
||||||
pendingCount > 0;
|
pendingCount > 0;
|
||||||
|
|
||||||
const primaryStatusRaw = readString(source, "primaryStatus", "PrimaryStatus", "status", "Status");
|
// Never treat the work-order lifecycle status/Status as uplift primaryStatus.
|
||||||
const amount = readNumber(source, "amount", "Amount");
|
const primaryStatusRaw = hasNested
|
||||||
|
? readString(source, "primaryStatus", "PrimaryStatus", "status", "Status")
|
||||||
|
: readString(item, "primaryStatus", "PrimaryStatus");
|
||||||
|
const amount = hasNested
|
||||||
|
? readNumber(source, "amount", "Amount")
|
||||||
|
: readNumber(item, "amount", "Amount");
|
||||||
|
|
||||||
const summary: UpliftSummary = {
|
const summary: UpliftSummary = {
|
||||||
hasUplift,
|
hasUplift,
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,9 @@ export function formatUpliftStatusLabel(status: WorkOrderUpliftStatus): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getUpliftCellLabel(summary: UpliftSummary): string | null {
|
export function getUpliftCellLabel(summary: UpliftSummary): string | null {
|
||||||
|
if (!summary.hasUplift && summary.pendingCount <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (summary.pendingCount > 0) {
|
if (summary.pendingCount > 0) {
|
||||||
return summary.pendingCount === 1 ? "1 Pending" : `${summary.pendingCount} Pending`;
|
return summary.pendingCount === 1 ? "1 Pending" : `${summary.pendingCount} Pending`;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,18 @@ describe("mapUpliftSummary", () => {
|
||||||
expect(result.pendingCount).toBe(1);
|
expect(result.pendingCount).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not treat work-order status as uplift primaryStatus when nested summary is absent", () => {
|
||||||
|
const result = mapUpliftSummary({
|
||||||
|
status: "Cancelled",
|
||||||
|
Status: "Cancelled",
|
||||||
|
hasUplift: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.hasUplift).toBe(false);
|
||||||
|
expect(result.primaryStatus).toBeUndefined();
|
||||||
|
expect(getUpliftCellLabel(result)).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it("normalizes auto-approved and canceled status aliases", () => {
|
it("normalizes auto-approved and canceled status aliases", () => {
|
||||||
expect(mapUpliftSummary({ primaryStatus: "AutoApproved" }).primaryStatus).toBe("auto_approved");
|
expect(mapUpliftSummary({ primaryStatus: "AutoApproved" }).primaryStatus).toBe("auto_approved");
|
||||||
expect(mapWorkOrderUplift({ status: "Canceled" }).status).toBe("cancelled");
|
expect(mapWorkOrderUplift({ status: "Canceled" }).status).toBe("cancelled");
|
||||||
|
|
@ -69,4 +81,21 @@ describe("uplift display utils", () => {
|
||||||
}),
|
}),
|
||||||
).toBe("Approved $1,200");
|
).toBe("Approved $1,200");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("hides Pending/Cancelled when hasUplift is false", () => {
|
||||||
|
expect(
|
||||||
|
getUpliftCellLabel({
|
||||||
|
hasUplift: false,
|
||||||
|
pendingCount: 0,
|
||||||
|
primaryStatus: "pending",
|
||||||
|
}),
|
||||||
|
).toBeNull();
|
||||||
|
expect(
|
||||||
|
getUpliftCellLabel({
|
||||||
|
hasUplift: false,
|
||||||
|
pendingCount: 0,
|
||||||
|
primaryStatus: "cancelled",
|
||||||
|
}),
|
||||||
|
).toBeNull();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue