mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 04:12:09 +00:00
Allow empty Appt Time in wizard, table, and slide-over without blocking create or complete. Omit appointment fields without vendorId so create does not hit DispatchRequired.
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
import type { WorkOrderBoardCreatePayload } from "@/domain/work-orders/types/work-order-board";
|
|
import type { WorkOrderWizardDraft } from "@/domain/work-orders/types/work-order-wizard";
|
|
import { formatApptTimeValue } from "@/domain/work-orders/utils/wizard-date-utils";
|
|
|
|
/**
|
|
* Mutates `payload` with `vendorId` and, when applicable, single-day appt date/time.
|
|
* Board create rejects appointment fields without vendorId (`DispatchRequired`).
|
|
*/
|
|
export function assignWizardVendorApptFields(
|
|
payload: WorkOrderBoardCreatePayload,
|
|
draft: WorkOrderWizardDraft,
|
|
): void {
|
|
const vendorId = draft.vendorId.trim() ? Number(draft.vendorId) : NaN;
|
|
const hasVendor = Number.isFinite(vendorId);
|
|
|
|
if (hasVendor) {
|
|
payload.vendorId = vendorId;
|
|
}
|
|
|
|
const apptTime = formatApptTimeValue(draft.apptStart, draft.apptEnd);
|
|
const isRange = draft.schedMode === "range";
|
|
|
|
if (hasVendor && (draft.scheduledOn || apptTime) && !draft.scheduleWeekOnly && !isRange) {
|
|
if (draft.scheduledOn) {
|
|
payload.apptDate = draft.scheduledOn;
|
|
}
|
|
|
|
if (apptTime) {
|
|
payload.apptTime = apptTime;
|
|
}
|
|
}
|
|
}
|