shoc-frontend-new/src/domain/work-orders/mappers/assign-wizard-schedule-fields.ts
Arthur Bassi ee90d73a44
Some checks are pending
CI / ci (push) Waiting to run
CI / governance (push) Waiting to run
CI / vendor-visual-regression (push) Waiting to run
Deploy / deploy (push) Waiting to run
feat(work-orders): board wizard create with service notes (#99)
* feat(work-orders): board wizard create with service notes

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(work-orders): enforce single-service wizard create per SH-118

Use single service selection in the wizard and omit extraServices from board create.

* refactor(work-orders): extract wizard controller for maintainability gate

Move duplicate-WO wiring and lookup hooks out of NewWoWizard so the
changed-file function line cap passes after merging dev.

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-13 18:43:11 -03:00

31 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 { mondayOf } from "@/domain/work-orders/utils/wizard-date-utils";
/**
* Mutates `payload` with `dueDate` and schedule fields.
* Range mode lands on the board using the range start as `scheduledDate`
* (prototype `hasScheduleDate`: a range start qualifies as scheduled).
*/
export function assignWizardScheduleFields(
payload: WorkOrderBoardCreatePayload,
draft: WorkOrderWizardDraft,
): void {
if (draft.dueDate) {
payload.dueDate = draft.dueDate;
}
const isRange = draft.schedMode === "range";
if (!isRange && draft.scheduleWeekOnly) {
const week = draft.targetWeek?.trim() || (draft.scheduledOn ? mondayOf(draft.scheduledOn) : "");
// Only emit week-mode flags when a concrete week exists (SH-109: undated create).
if (week) {
payload.scheduleWeekOnly = true;
payload.targetWeek = week;
}
} else if (draft.scheduledOn && (isRange || !draft.scheduleWeekOnly)) {
payload.scheduledDate = draft.scheduledOn;
}
}