mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 09:13:11 +00:00
Merge remote-tracking branch 'origin/dev' into fix/ab/sh-369-completion-doc-service-gate
# Conflicts: # src/app/(protected)/workorders/_components/detail/tabs/slide-over-completion-tab.tsx
This commit is contained in:
commit
9722805300
47 changed files with 1374 additions and 99 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 99 KiB |
80
e2e/work-orders/due-date-schedule-floor.spec.ts
Normal file
80
e2e/work-orders/due-date-schedule-floor.spec.ts
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
import { expect, test, type Route } from "@playwright/test";
|
||||
|
||||
const FROZEN_NOW = "2026-08-19T15:00:00.000Z";
|
||||
|
||||
const TEST_USER = {
|
||||
token: "due-date-floor-e2e-token",
|
||||
expiration: "2030-01-01T00:00:00.000Z",
|
||||
email: "admin@seahavenind.com",
|
||||
userRoles: "Admin",
|
||||
phoneNumber: "5551234567",
|
||||
fullname: "Work Order E2E Admin",
|
||||
id: "1",
|
||||
};
|
||||
|
||||
async function fulfillJson(route: Route, body: unknown, status = 200) {
|
||||
await route.fulfill({ status, contentType: "application/json", body: JSON.stringify(body) });
|
||||
}
|
||||
|
||||
test.describe("Due Date floor in the Create WO wizard (SH-356)", () => {
|
||||
test.setTimeout(60_000);
|
||||
|
||||
test("disables days before Schedule On and clears Due Date when Schedule On passes it", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.clock.install({ time: new Date(FROZEN_NOW) });
|
||||
await page.clock.resume();
|
||||
await page.addInitScript((user) => {
|
||||
localStorage.setItem("auth", JSON.stringify(user));
|
||||
const style = document.createElement("style");
|
||||
style.textContent = ".tsqd-parent-container { display: none !important; }";
|
||||
document.documentElement.appendChild(style);
|
||||
}, TEST_USER);
|
||||
await page.route(
|
||||
(url) => url.pathname.startsWith("/api/"),
|
||||
async (route) => {
|
||||
if (route.request().method() !== "GET") {
|
||||
await fulfillJson(route, {}, 500);
|
||||
return;
|
||||
}
|
||||
await fulfillJson(route, {
|
||||
data: [],
|
||||
items: [],
|
||||
weekStart: "2026-08-17",
|
||||
weekEnd: "2026-08-21",
|
||||
counts: { returned: 0, total: 0 },
|
||||
unscheduled: [],
|
||||
scheduled: [],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
await page.goto("/workorders");
|
||||
await page.getByRole("button", { name: "New WO" }).click();
|
||||
await expect(page.getByRole("heading", { name: "Type & schedule" })).toBeVisible({
|
||||
timeout: 20_000,
|
||||
});
|
||||
|
||||
await page.getByRole("button", { name: /Pick a date/ }).click();
|
||||
const dateTab = page.getByRole("button", { name: "Date", exact: true });
|
||||
if (await dateTab.isVisible()) {
|
||||
await dateTab.click();
|
||||
}
|
||||
await page.getByRole("button", { name: "20", exact: true }).click();
|
||||
|
||||
await page.getByRole("button", { name: /No due date/ }).click();
|
||||
await expect(page.getByRole("button", { name: "19", exact: true })).toBeDisabled();
|
||||
await expect(page.getByRole("button", { name: "20", exact: true })).toBeEnabled();
|
||||
await page.getByRole("button", { name: "21", exact: true }).click();
|
||||
await expect(page.getByRole("button", { name: /No due date/ })).toHaveCount(0);
|
||||
|
||||
await page.getByRole("button", { name: /Aug 20/ }).click();
|
||||
const dateTabAgain = page.getByRole("button", { name: "Date", exact: true });
|
||||
if (await dateTabAgain.isVisible()) {
|
||||
await dateTabAgain.click();
|
||||
}
|
||||
await page.getByRole("button", { name: "25", exact: true }).click();
|
||||
|
||||
await expect(page.getByRole("button", { name: /No due date/ })).toBeVisible();
|
||||
});
|
||||
});
|
||||
|
|
@ -6,8 +6,8 @@ import type { UploadableMediaCategory } from "@/domain/work-orders/mappers/work-
|
|||
import type { WorkOrderBoardCompletion } from "@/domain/work-orders/types/work-order-board-detail";
|
||||
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import type { WOType } from "@/domain/work-orders/types/work-order-wizard";
|
||||
import { hasCompletionDocService } from "@/domain/work-orders/utils/completion-doc-service-gate";
|
||||
import { hasCompletionMediaGallery } from "@/domain/work-orders/utils/partition-slide-over-media";
|
||||
import {
|
||||
formatMediaSizeLimit,
|
||||
isWorkOrderFileTooLarge,
|
||||
|
|
@ -17,10 +17,6 @@ import { SlideOverCompletionMedia } from "./slide-over-completion-media";
|
|||
import { SlideOverCompletionReadonlyStatus } from "./slide-over-completion-readonly-status";
|
||||
import { SlideOverCompletionSignoffs } from "./slide-over-completion-signoffs";
|
||||
|
||||
function isMediaWO(type: WOType | ""): boolean {
|
||||
return type === "Emergency" || type === "Reactive";
|
||||
}
|
||||
|
||||
type SlideOverCompletionTabProps = {
|
||||
row: WorkOrderTableRow;
|
||||
isReadOnly: boolean;
|
||||
|
|
@ -57,7 +53,7 @@ export function SlideOverCompletionTab({
|
|||
const templateUrl = completion?.template?.templateUrl;
|
||||
const signOffAttachment = completion?.signOffAttachment;
|
||||
|
||||
if (isMediaWO(row.type)) {
|
||||
if (hasCompletionMediaGallery(row.type)) {
|
||||
return (
|
||||
<SlideOverCompletionMedia
|
||||
isReadOnly={isReadOnly}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,14 @@ const FILETYPE_ICON: Record<FileCategory, typeof ImageIcon> = {
|
|||
other: Paperclip,
|
||||
};
|
||||
|
||||
const FILETYPE_LABEL: Record<FileCategory, string> = {
|
||||
image: "Photo",
|
||||
video: "Video",
|
||||
pdf: "PDF",
|
||||
doc: "Document",
|
||||
other: "File",
|
||||
};
|
||||
|
||||
const EXTRA_DOC_PURPOSES: Array<Extract<UploadableMediaCategory, "Extra" | "Aveta">> = [
|
||||
"Extra",
|
||||
"Aveta",
|
||||
|
|
@ -92,8 +100,13 @@ function ExtraDocRow({
|
|||
const purpose = file.purpose === "Aveta" || isAveta ? "Aveta" : "Extra";
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2 py-1">
|
||||
<div
|
||||
role="group"
|
||||
aria-label={`${FILETYPE_LABEL[file.fileType]}, ${purpose}: ${file.name}`}
|
||||
className="flex items-center gap-2 py-1"
|
||||
>
|
||||
<ItemIcon
|
||||
aria-hidden
|
||||
size={12}
|
||||
className="shrink-0"
|
||||
style={{ color: isAveta ? "var(--warning)" : "var(--color-text-muted)" }}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ import type { WizardWOStatus } from "@/domain/work-orders/types/work-order-wizar
|
|||
import { deriveDayFields } from "@/domain/work-orders/utils/table-day-utils";
|
||||
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
|
||||
import { DocBadge } from "./slide-over-doc-badge";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type SlideOverInfoTabEditViewProps = {
|
||||
draft: WorkOrderTableRow;
|
||||
|
|
@ -52,6 +56,7 @@ function SlideOverScheduleOnField({
|
|||
schedMode={draft.schedMode}
|
||||
onSave={(scheduledOn) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, scheduledOn),
|
||||
scheduledOn,
|
||||
scheduleWeekOnly: false,
|
||||
targetWeek: scheduledOn ? "" : draft.targetWeek,
|
||||
|
|
@ -63,6 +68,7 @@ function SlideOverScheduleOnField({
|
|||
}
|
||||
onSaveWeek={(weekStart) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, weekStart),
|
||||
scheduledOn: "",
|
||||
targetWeek: weekStart,
|
||||
scheduleWeekOnly: true,
|
||||
|
|
@ -74,6 +80,7 @@ function SlideOverScheduleOnField({
|
|||
}
|
||||
onSaveRange={(start, end) =>
|
||||
onDraftChange({
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||
scheduledOn: start,
|
||||
scheduleEnd: end,
|
||||
schedMode: "range",
|
||||
|
|
@ -175,6 +182,7 @@ export function SlideOverInfoTabEditView({
|
|||
<DueDateCell
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
onSave={(dueDate) => onDraftChange({ dueDate })}
|
||||
/>
|
||||
</SlideOverInfoRow>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import type {
|
|||
UploadWorkOrderMediaInput,
|
||||
} from "@/domain/work-orders/use-cases/use-work-order-mutations";
|
||||
import {
|
||||
hasCompletionMediaGallery,
|
||||
isCompletionSurfaceMedia,
|
||||
isExtrasSurfaceMedia,
|
||||
type MediaSurfaceOwnership,
|
||||
|
|
@ -80,6 +81,7 @@ export function useSlideOverMediaState({
|
|||
categorizeMediaMutation,
|
||||
}: UseSlideOverMediaStateArgs) {
|
||||
const workOrderId = detailForRow?.info.id;
|
||||
const completionHasGallery = hasCompletionMediaGallery(detailForRow?.info.type);
|
||||
const [mediaBatchPending, setMediaBatchPending] = useState(false);
|
||||
const [ownership, setOwnershipState] = useState<MediaSurfaceOwnership>(() =>
|
||||
loadOwnership(workOrderId),
|
||||
|
|
@ -116,16 +118,16 @@ export function useSlideOverMediaState({
|
|||
useMediaUploadSession(detailForRow, persistCompletionUpload);
|
||||
|
||||
const completionMedia = useMemo(
|
||||
() => uploads.filter((item) => isCompletionSurfaceMedia(item, ownership)),
|
||||
[uploads, ownership],
|
||||
() => uploads.filter((item) => isCompletionSurfaceMedia(item, ownership, completionHasGallery)),
|
||||
[uploads, ownership, completionHasGallery],
|
||||
);
|
||||
|
||||
const extrasUploads = useMemo(
|
||||
() =>
|
||||
boardMediaItemsToMediaFiles(detailForRow?.media ?? []).filter((item) =>
|
||||
isExtrasSurfaceMedia(item, ownership),
|
||||
isExtrasSurfaceMedia(item, ownership, completionHasGallery),
|
||||
),
|
||||
[detailForRow?.media, ownership],
|
||||
[detailForRow?.media, ownership, completionHasGallery],
|
||||
);
|
||||
|
||||
const hasLocalUploading = uploads.some((item) => item.uploadStatus === "uploading");
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ type DateCellProps = {
|
|||
onClear?: () => void;
|
||||
/** Screen-reader-only status appended inside the button so the accessible name keeps the visible date and adds durable state. */
|
||||
srStatusSuffix?: string;
|
||||
/** Earliest selectable day in the date calendar (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
export function DateCell({
|
||||
|
|
@ -41,6 +43,7 @@ export function DateCell({
|
|||
onSaveRange,
|
||||
onClear,
|
||||
srStatusSuffix,
|
||||
minDate,
|
||||
}: DateCellProps) {
|
||||
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
|
||||
const open = Boolean(anchorEl);
|
||||
|
|
@ -154,6 +157,7 @@ export function DateCell({
|
|||
) : (
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(d) => {
|
||||
onSave(d);
|
||||
setAnchorEl(null);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ type DueDateCalendarDialogProps = {
|
|||
onOpenChange: (open: boolean) => void;
|
||||
value: string;
|
||||
onSave: (iso: string) => void;
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -19,6 +20,7 @@ export function DueDateCalendarDialog({
|
|||
onOpenChange,
|
||||
value,
|
||||
onSave,
|
||||
minDate,
|
||||
}: DueDateCalendarDialogProps) {
|
||||
return (
|
||||
<Dialog
|
||||
|
|
@ -44,6 +46,7 @@ export function DueDateCalendarDialog({
|
|||
<div className="flex justify-center">
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(iso) => {
|
||||
onSave(iso);
|
||||
onOpenChange(false);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ type DueDateCellProps = {
|
|||
* read by colour alone.
|
||||
*/
|
||||
pastDue?: boolean;
|
||||
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||
minDate?: string;
|
||||
onSave: (date: string) => void;
|
||||
};
|
||||
|
||||
|
|
@ -29,6 +31,7 @@ export function DueDateCell({
|
|||
q,
|
||||
highlight,
|
||||
pastDue = false,
|
||||
minDate,
|
||||
onSave,
|
||||
}: DueDateCellProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
|
@ -40,6 +43,7 @@ export function DueDateCell({
|
|||
q={q}
|
||||
highlight={highlight}
|
||||
onSave={onSave}
|
||||
minDate={minDate}
|
||||
srStatusSuffix={pastDue ? "Past due" : undefined}
|
||||
/>
|
||||
);
|
||||
|
|
@ -87,7 +91,13 @@ export function DueDateCell({
|
|||
style={{ color: "var(--muted-foreground)" }}
|
||||
/>
|
||||
</button>
|
||||
<DueDateCalendarDialog open={open} onOpenChange={setOpen} value={value} onSave={onSave} />
|
||||
<DueDateCalendarDialog
|
||||
minDate={minDate}
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={value}
|
||||
onSave={onSave}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ type EditableWONumberCellProps = {
|
|||
onSave: (v: string) => void;
|
||||
onDuplicateFound?: (existing: WorkOrderTableRow) => void;
|
||||
locked?: boolean;
|
||||
/** Empty-state label for create flows; renders with a persistent required asterisk. */
|
||||
requiredPlaceholder?: string;
|
||||
};
|
||||
|
||||
async function resolveDuplicateWoNumber(
|
||||
|
|
@ -34,6 +36,28 @@ async function resolveDuplicateWoNumber(
|
|||
return remote && String(remote.id) !== String(currentId) ? remote : undefined;
|
||||
}
|
||||
|
||||
function EmptyWoNumberLabel({
|
||||
value,
|
||||
q,
|
||||
requiredPlaceholder,
|
||||
}: {
|
||||
value: string;
|
||||
q?: string;
|
||||
requiredPlaceholder?: string;
|
||||
}) {
|
||||
if (value) {
|
||||
return <HighlightText text={value} q={q} />;
|
||||
}
|
||||
if (!requiredPlaceholder) {
|
||||
return "-";
|
||||
}
|
||||
return (
|
||||
<span className="font-sans text-[13px] font-normal">
|
||||
{requiredPlaceholder} <span style={{ color: "var(--destructive)" }}>*</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
export function EditableWONumberCell({
|
||||
value,
|
||||
rescheduleCount,
|
||||
|
|
@ -49,6 +73,7 @@ export function EditableWONumberCell({
|
|||
onSave,
|
||||
onDuplicateFound,
|
||||
locked = false,
|
||||
requiredPlaceholder,
|
||||
}: EditableWONumberCellProps) {
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState(value);
|
||||
|
|
@ -162,7 +187,7 @@ export function EditableWONumberCell({
|
|||
padding: "2px 4px",
|
||||
}}
|
||||
>
|
||||
{value ? <HighlightText text={value} q={q} /> : "-"}
|
||||
<EmptyWoNumberLabel value={value} q={q} requiredPlaceholder={requiredPlaceholder} />
|
||||
</span>
|
||||
)}
|
||||
<AddOnPill when={isAddOn} />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ type SiteDialogPocSectionProps = {
|
|||
pocNotes: string;
|
||||
additionalContacts: WorkOrderAdditionalContact[];
|
||||
showPrimaryErrors?: boolean;
|
||||
primaryRequired?: boolean;
|
||||
onPocNameChange: (value: string) => void;
|
||||
onPocPhoneChange: (value: string) => void;
|
||||
onPocNotesChange: (value: string) => void;
|
||||
|
|
@ -19,6 +20,7 @@ export function SiteDialogPocSection({
|
|||
pocNotes,
|
||||
additionalContacts,
|
||||
showPrimaryErrors = false,
|
||||
primaryRequired = false,
|
||||
onPocNameChange,
|
||||
onPocPhoneChange,
|
||||
onPocNotesChange,
|
||||
|
|
@ -31,6 +33,7 @@ export function SiteDialogPocSection({
|
|||
pocNotes={pocNotes}
|
||||
additionalContacts={additionalContacts}
|
||||
showPrimaryErrors={showPrimaryErrors}
|
||||
primaryRequired={primaryRequired}
|
||||
onPocNameChange={onPocNameChange}
|
||||
onPocPhoneChange={onPocPhoneChange}
|
||||
onPocNotesChange={onPocNotesChange}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ export function SiteDialog({
|
|||
|
||||
<fieldset disabled={viewOnly} className="mt-3 space-y-3 border-0 p-0">
|
||||
<div>
|
||||
<FieldLabel>Site</FieldLabel>
|
||||
<FieldLabel required={createMode}>Site</FieldLabel>
|
||||
<WizardFieldSelect
|
||||
value={s.locId}
|
||||
placeholder="Select site …"
|
||||
|
|
@ -130,6 +130,7 @@ export function SiteDialog({
|
|||
pocNotes={s.notes}
|
||||
additionalContacts={s.extraContacts}
|
||||
showPrimaryErrors={createMode && s.showErrors}
|
||||
primaryRequired={createMode}
|
||||
onPocNameChange={s.setPn}
|
||||
onPocPhoneChange={s.setPp}
|
||||
onPocNotesChange={s.setNotes}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import { shouldNotifyCrossWeek } from "@/domain/work-orders/utils/should-notify-
|
|||
import type { ReturnTypeOfUseWorkOrdersTableData } from "./wo-table-types";
|
||||
import { rescheduleNotify, weekMoveNotify } from "./reschedule-notify";
|
||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||
import { clearDueDateBeforeSchedule } from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
function revealOrNotifyScheduledDay(args: {
|
||||
id: string | number;
|
||||
|
|
@ -31,6 +32,35 @@ function revealOrNotifyScheduledDay(args: {
|
|||
revealScheduledRow(id);
|
||||
}
|
||||
|
||||
type DragHandlersArgs = Pick<
|
||||
ReturnTypeOfUseWorkOrdersTableData,
|
||||
"dragState" | "setDragViz" | "reorderRows" | "endDrag"
|
||||
>;
|
||||
|
||||
function createDragHandlers({ dragState, setDragViz, reorderRows, endDrag }: DragHandlersArgs) {
|
||||
return {
|
||||
onDragStart: (id: string | number) => {
|
||||
dragState.current = { dragId: id, overId: null };
|
||||
setDragViz({ dragId: id, overId: null });
|
||||
},
|
||||
onDragOver: (id: string | number) => {
|
||||
const did = dragState.current.dragId;
|
||||
if (did && did !== id && dragState.current.overId !== id) {
|
||||
dragState.current.overId = id;
|
||||
setDragViz((v) => ({ ...v, overId: id }));
|
||||
}
|
||||
},
|
||||
onDrop: () => {
|
||||
const { dragId, overId } = dragState.current;
|
||||
if (dragId && overId) {
|
||||
reorderRows(dragId, overId);
|
||||
}
|
||||
endDrag();
|
||||
},
|
||||
onDragEnd: endDrag,
|
||||
};
|
||||
}
|
||||
|
||||
type UseWoTableRowHandlersOptions = {
|
||||
tableData: ReturnTypeOfUseWorkOrdersTableData;
|
||||
weekMonday: string;
|
||||
|
|
@ -101,8 +131,11 @@ export function useWoTableRowHandlers({
|
|||
onPatch: (id, patch, options) => {
|
||||
onPatch(id, patch, options);
|
||||
},
|
||||
onScheduleDate: (id: string | number, date: string) => {
|
||||
onPatch(id, applySchedulePatch(date, false));
|
||||
onScheduleDate: (id: string | number, date: string, dueDate?: string) => {
|
||||
onPatch(id, {
|
||||
...applySchedulePatch(date, false),
|
||||
...clearDueDateBeforeSchedule(dueDate, date),
|
||||
});
|
||||
revealOrNotifyScheduledDay({
|
||||
id,
|
||||
date,
|
||||
|
|
@ -111,8 +144,11 @@ export function useWoTableRowHandlers({
|
|||
revealScheduledRow,
|
||||
});
|
||||
},
|
||||
onScheduleRange: (id: string | number, start: string, end: string) => {
|
||||
onPatch(id, applyScheduleRangePatch(start, end));
|
||||
onScheduleRange: (id: string | number, start: string, end: string, dueDate?: string) => {
|
||||
onPatch(id, {
|
||||
...applyScheduleRangePatch(start, end),
|
||||
...clearDueDateBeforeSchedule(dueDate, start),
|
||||
});
|
||||
revealOrNotifyScheduledDay({
|
||||
id,
|
||||
date: start,
|
||||
|
|
@ -121,7 +157,7 @@ export function useWoTableRowHandlers({
|
|||
revealScheduledRow,
|
||||
});
|
||||
},
|
||||
onScheduleWeek: (id: string | number, week: string) => {
|
||||
onScheduleWeek: (id: string | number, week: string, dueDate?: string) => {
|
||||
const isClear = week === "";
|
||||
onPatch(
|
||||
id,
|
||||
|
|
@ -135,6 +171,7 @@ export function useWoTableRowHandlers({
|
|||
schedMode: "week",
|
||||
dayGroup: "",
|
||||
dayLabel: "",
|
||||
...clearDueDateBeforeSchedule(dueDate, week),
|
||||
},
|
||||
);
|
||||
weekMoveNotify(week, {
|
||||
|
|
@ -153,25 +190,12 @@ export function useWoTableRowHandlers({
|
|||
onRequestComplete,
|
||||
onPastDueAttempt: (id: string | number) => onScheduleHighlight(id),
|
||||
onReorder: reorderRows,
|
||||
onDragStart: (id: string | number) => {
|
||||
dragStateRef.current = { dragId: id, overId: null };
|
||||
setDragViz({ dragId: id, overId: null });
|
||||
},
|
||||
onDragOver: (id: string | number) => {
|
||||
const did = dragStateRef.current.dragId;
|
||||
if (did && did !== id && dragStateRef.current.overId !== id) {
|
||||
dragStateRef.current.overId = id;
|
||||
setDragViz((v) => ({ ...v, overId: id }));
|
||||
}
|
||||
},
|
||||
onDrop: () => {
|
||||
const { dragId, overId } = dragStateRef.current;
|
||||
if (dragId && overId) {
|
||||
reorderRows(dragId, overId);
|
||||
}
|
||||
endDrag();
|
||||
},
|
||||
onDragEnd: endDrag,
|
||||
...createDragHandlers({
|
||||
dragState: dragStateRef,
|
||||
setDragViz,
|
||||
reorderRows,
|
||||
endDrag,
|
||||
}),
|
||||
}),
|
||||
[
|
||||
tableData,
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ export function WoTableInlineIdentityCells({
|
|||
allOrders={allRows as never[]}
|
||||
onSave={(v) => onPatch({ woNumber: v })}
|
||||
onDuplicateFound={onDuplicateFound}
|
||||
requiredPlaceholder="Insert WO #"
|
||||
/>
|
||||
<AddOnOverrideToggle
|
||||
checked={draft.isAddOnOverride}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export function WoTableInlineRowActions({
|
|||
onCancel,
|
||||
}: WoTableInlineRowActionsProps) {
|
||||
return (
|
||||
<div className="flex items-center gap-0.5">
|
||||
<div className="flex items-center gap-0.5" style={{ minHeight: 34 }}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onSave}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { RefObject } from "react";
|
||||
import type { ReactNode, RefObject } from "react";
|
||||
import type {
|
||||
LocationOption,
|
||||
VendorDropdownItem,
|
||||
|
|
@ -21,8 +21,13 @@ import { StatusCell } from "./cells/status-cell";
|
|||
import { TypeCell } from "./cells/type-cell";
|
||||
import { VendorCell } from "./cells/vendor-cell";
|
||||
import { toVendorTablePatch } from "@/domain/work-orders/utils/vendor-assignment-patch";
|
||||
import { InlineCreateField } from "./inline-create-field";
|
||||
import { toInlineDraftRow } from "./to-inline-draft-row";
|
||||
import { WoTableInlineIdentityCells } from "./wo-table-inline-identity-cells";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type WoTableInlineRowCellsProps = {
|
||||
draft: WorkOrderTableDraft;
|
||||
|
|
@ -43,6 +48,17 @@ type WoTableInlineRowCellsProps = {
|
|||
onRequestComplete?: () => void;
|
||||
};
|
||||
|
||||
/** Matches the identity cells: top-aligned so field boxes and error helpers line up. */
|
||||
const INLINE_FIELD_TD_STYLE = { padding: "8px 6px 0", verticalAlign: "top" } as const;
|
||||
|
||||
function InlineFieldCell({ children }: { children: ReactNode }) {
|
||||
return (
|
||||
<td className="group/cell" style={INLINE_FIELD_TD_STYLE}>
|
||||
<InlineCreateField>{children}</InlineCreateField>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
||||
function InlineTypeSeverityCell({
|
||||
draft,
|
||||
onPatch,
|
||||
|
|
@ -51,20 +67,22 @@ function InlineTypeSeverityCell({
|
|||
onPatch: (patch: Partial<WorkOrderTableDraft>) => void;
|
||||
}) {
|
||||
return (
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
<InlineFieldCell>
|
||||
<TypeCell
|
||||
value={draft.type}
|
||||
severity={draft.severity}
|
||||
onSave={(t, sev) => onPatch({ type: t, severity: sev })}
|
||||
/>
|
||||
</td>
|
||||
</InlineFieldCell>
|
||||
);
|
||||
}
|
||||
|
||||
function InlineMutedDashCell() {
|
||||
return (
|
||||
<td style={{ padding: "0 14px" }}>
|
||||
<span style={{ fontSize: 11, color: "var(--color-text-muted)" }}>—</span>
|
||||
<td style={INLINE_FIELD_TD_STYLE}>
|
||||
<div className="flex items-center" style={{ minHeight: 34 }}>
|
||||
<span style={{ fontSize: 11, color: "var(--color-text-muted)" }}>—</span>
|
||||
</div>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
|
|
@ -81,18 +99,18 @@ function InlineScheduleOnCell({
|
|||
const hasSchedule =
|
||||
Boolean(draft.scheduledOn) || Boolean(draft.targetWeek) || Boolean(draft.scheduleEnd);
|
||||
return (
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
<InlineFieldCell>
|
||||
<DateCell
|
||||
value={draft.scheduledOn}
|
||||
allowWeekMode
|
||||
targetWeek={draft.targetWeek}
|
||||
defaultMode={weekDefault ? "week" : "date"}
|
||||
highlight={!draft.scheduledOn && !draft.targetWeek}
|
||||
scheduleEnd={draft.scheduleEnd}
|
||||
schedMode={draft.schedMode}
|
||||
onSave={(date) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, date),
|
||||
scheduledOn: date,
|
||||
scheduleWeekOnly: false,
|
||||
targetWeek: "",
|
||||
|
|
@ -105,6 +123,7 @@ function InlineScheduleOnCell({
|
|||
onSaveWeek={(week) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, week),
|
||||
scheduledOn: "",
|
||||
targetWeek: week,
|
||||
scheduleWeekOnly: true,
|
||||
|
|
@ -117,6 +136,7 @@ function InlineScheduleOnCell({
|
|||
onSaveRange={(start, end) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, start),
|
||||
scheduledOn: start,
|
||||
scheduleEnd: end,
|
||||
schedMode: "range",
|
||||
|
|
@ -142,7 +162,7 @@ function InlineScheduleOnCell({
|
|||
: undefined
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
</InlineFieldCell>
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -184,26 +204,26 @@ export function WoTableInlineRowCells({
|
|||
|
||||
<InlineTypeSeverityCell draft={draft} onPatch={onPatch} />
|
||||
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
<InlineFieldCell>
|
||||
<AssignedToCell
|
||||
dispatcherId={draft.dispatcherId}
|
||||
users={users}
|
||||
highlight={!draft.dispatcherId}
|
||||
onSave={(id) => {
|
||||
onPatch({ dispatcherId: id, status: draft.status || "Incomplete" });
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
</InlineFieldCell>
|
||||
<InlineScheduleOnCell draft={draft} weekDefault={weekDefault} onPatch={onPatch} />
|
||||
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
<InlineFieldCell>
|
||||
<DueDateCell
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
onSave={(date) => onPatch({ dueDate: date })}
|
||||
/>
|
||||
</td>
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
</InlineFieldCell>
|
||||
<InlineFieldCell>
|
||||
<PMTypeCell
|
||||
value={draft.pm}
|
||||
pmTypes={pmTypes}
|
||||
|
|
@ -221,8 +241,8 @@ export function WoTableInlineRowCells({
|
|||
})
|
||||
}
|
||||
/>
|
||||
</td>
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
</InlineFieldCell>
|
||||
<InlineFieldCell>
|
||||
<VendorCell
|
||||
vendorId={draft.vendorId}
|
||||
company={draft.company}
|
||||
|
|
@ -231,8 +251,8 @@ export function WoTableInlineRowCells({
|
|||
vendors={vendors}
|
||||
onSave={(p) => onPatch(toVendorTablePatch(p))}
|
||||
/>
|
||||
</td>
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
</InlineFieldCell>
|
||||
<InlineFieldCell>
|
||||
<ApptTimeCell
|
||||
apptTime={
|
||||
draft.apptStart ? `${draft.apptStart}${draft.apptEnd ? ` – ${draft.apptEnd}` : ""}` : ""
|
||||
|
|
@ -242,8 +262,8 @@ export function WoTableInlineRowCells({
|
|||
onPatch({ apptStart: start ?? "", apptEnd: end ?? "" });
|
||||
}}
|
||||
/>
|
||||
</td>
|
||||
<td className="group/cell" style={{ padding: "0 14px" }}>
|
||||
</InlineFieldCell>
|
||||
<InlineFieldCell>
|
||||
<StatusCell
|
||||
wo={draftRow as never}
|
||||
statusOptions={CREATION_INLINE_STATUSES}
|
||||
|
|
@ -251,7 +271,7 @@ export function WoTableInlineRowCells({
|
|||
onOpenSlideOver={() => {}}
|
||||
onRequestComplete={onRequestComplete}
|
||||
/>
|
||||
</td>
|
||||
</InlineFieldCell>
|
||||
|
||||
<InlineMutedDashCell />
|
||||
<InlineMutedDashCell />
|
||||
|
|
|
|||
|
|
@ -115,15 +115,17 @@ export function WoTableInlineRow({
|
|||
pointerEvents: saving ? "none" : undefined,
|
||||
}}
|
||||
>
|
||||
<td style={{ padding: "0 0 0 6px" }} />
|
||||
<td style={{ padding: "8px 0 0 6px", verticalAlign: "top" }} />
|
||||
|
||||
<td style={{ padding: "0 2px 0 8px" }}>
|
||||
<Flag
|
||||
size={14}
|
||||
strokeWidth={1.75}
|
||||
aria-hidden="true"
|
||||
style={{ color: "var(--color-border)" }}
|
||||
/>
|
||||
<td style={{ padding: "8px 2px 0 8px", verticalAlign: "top" }}>
|
||||
<div className="flex items-center" style={{ minHeight: 34 }}>
|
||||
<Flag
|
||||
size={14}
|
||||
strokeWidth={1.75}
|
||||
aria-hidden="true"
|
||||
style={{ color: "var(--color-border)" }}
|
||||
/>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<WoTableInlineRowCells
|
||||
|
|
@ -145,7 +147,7 @@ export function WoTableInlineRow({
|
|||
onRequestComplete={() => setConfirmComplete(true)}
|
||||
/>
|
||||
|
||||
<td style={{ padding: "0 4px" }}>
|
||||
<td style={{ padding: "8px 4px 0", verticalAlign: "top" }}>
|
||||
<WoTableInlineRowActions
|
||||
canSave={canSave}
|
||||
saving={saving}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { EditableWONumberCell } from "./cells/editable-wo-number-cell";
|
|||
import { SiteCell } from "./cells/site-cell";
|
||||
import { TypeCell } from "./cells/type-cell";
|
||||
import type { WoTableRowHandlers } from "./wo-table-row";
|
||||
import { resolveDueDateFloor } from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
type WoTableRowCellsProps = {
|
||||
row: WorkOrderTableRow;
|
||||
|
|
@ -146,9 +147,9 @@ export function WoTableRowCells({
|
|||
targetWeek={row.targetWeek}
|
||||
scheduleEnd={row.scheduleEnd}
|
||||
schedMode={row.schedMode}
|
||||
onSave={(date) => handlers.onScheduleDate(row.id, date)}
|
||||
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week)}
|
||||
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end)}
|
||||
onSave={(date) => handlers.onScheduleDate(row.id, date, row.dueDate)}
|
||||
onSaveWeek={(week) => handlers.onScheduleWeek(row.id, week, row.dueDate)}
|
||||
onSaveRange={(start, end) => handlers.onScheduleRange(row.id, start, end, row.dueDate)}
|
||||
onClear={hasSchedule && !viewOnly ? () => handlers.onScheduleWeek(row.id, "") : undefined}
|
||||
/>
|
||||
</td>
|
||||
|
|
@ -163,6 +164,7 @@ export function WoTableRowCells({
|
|||
q={search}
|
||||
highlight={forceDueDateHighlight || row.isPastDue}
|
||||
pastDue={row.isPastDue}
|
||||
minDate={resolveDueDateFloor(row)}
|
||||
onSave={(date) => onPatchRow({ dueDate: date })}
|
||||
/>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -36,9 +36,10 @@ export type WoTableRowHandlers = {
|
|||
patch: Partial<WorkOrderTableRow>,
|
||||
options?: WorkOrderTablePatchOptions,
|
||||
) => void;
|
||||
onScheduleDate: (id: string | number, date: string) => void;
|
||||
onScheduleWeek: (id: string | number, week: string) => void;
|
||||
onScheduleRange: (id: string | number, start: string, end: string) => void;
|
||||
/** `dueDate` is the row's current Due Date, cleared when the new schedule passes it (SH-356). */
|
||||
onScheduleDate: (id: string | number, date: string, dueDate?: string) => void;
|
||||
onScheduleWeek: (id: string | number, week: string, dueDate?: string) => void;
|
||||
onScheduleRange: (id: string | number, start: string, end: string, dueDate?: string) => void;
|
||||
onDuplicateFound?: (existing: WorkOrderTableRow) => void;
|
||||
onOpenSlideOver: (row: WorkOrderTableRow) => void;
|
||||
onRequestComplete?: (row: WorkOrderTableRow) => void;
|
||||
|
|
@ -77,17 +78,17 @@ function guardScheduleHandlers(
|
|||
if (!canApplyWorkOrderTablePatch(row.status, patch)) return;
|
||||
handlers.onPatch(id, patch, options);
|
||||
},
|
||||
onScheduleDate: (id, date) => {
|
||||
onScheduleDate: (id, date, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: date })) return;
|
||||
handlers.onScheduleDate(id, date);
|
||||
handlers.onScheduleDate(id, date, dueDate);
|
||||
},
|
||||
onScheduleWeek: (id, week) => {
|
||||
onScheduleWeek: (id, week, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { targetWeek: week })) return;
|
||||
handlers.onScheduleWeek(id, week);
|
||||
handlers.onScheduleWeek(id, week, dueDate);
|
||||
},
|
||||
onScheduleRange: (id, start, end) => {
|
||||
onScheduleRange: (id, start, end, dueDate) => {
|
||||
if (!canApplyWorkOrderTablePatch(row.status, { scheduledOn: start })) return;
|
||||
handlers.onScheduleRange(id, start, end);
|
||||
handlers.onScheduleRange(id, start, end, dueDate);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,31 +5,49 @@ import { ToolbarButton } from "@/components/ui/toolbar-button";
|
|||
|
||||
type WorkOrdersListHeaderProps = {
|
||||
search: string;
|
||||
/** Compact label of the active board week (e.g. "5/4–5/8"). */
|
||||
weekLabel: string;
|
||||
onSearchChange: (value: string) => void;
|
||||
/** Omit until Advanced Search slice mounts the sheet. */
|
||||
onOpenAdvancedFilters?: () => void;
|
||||
/** Omit until wizard shell slice mounts New WO. */
|
||||
onNewWorkOrder?: () => void;
|
||||
activeFilterCount: number;
|
||||
/** True while Advanced Filters are applied; results are global and the keyword box is inert. */
|
||||
advancedFiltersActive?: boolean;
|
||||
isFetching?: boolean;
|
||||
};
|
||||
|
||||
export function WorkOrdersListHeader({
|
||||
search,
|
||||
weekLabel,
|
||||
onSearchChange,
|
||||
onOpenAdvancedFilters,
|
||||
onNewWorkOrder,
|
||||
activeFilterCount,
|
||||
advancedFiltersActive = false,
|
||||
isFetching = false,
|
||||
}: WorkOrdersListHeaderProps) {
|
||||
return (
|
||||
<>
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={onSearchChange}
|
||||
placeholder="Search this week…"
|
||||
aria-label="Search work orders"
|
||||
/>
|
||||
<div className="relative">
|
||||
<SearchInput
|
||||
value={search}
|
||||
onChange={onSearchChange}
|
||||
placeholder="Search this week…"
|
||||
aria-label="Search work orders"
|
||||
/>
|
||||
{/* Keyword search is scoped to the active week; make that scope visible. */}
|
||||
{!advancedFiltersActive && search.trim() !== "" && Boolean(weekLabel) && (
|
||||
<span
|
||||
role="status"
|
||||
className="absolute left-0 whitespace-nowrap text-(length:--text-xs) text-muted-foreground"
|
||||
style={{ top: "calc(100% + 4px)" }}
|
||||
>
|
||||
Searching within {weekLabel}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{Boolean(onOpenAdvancedFilters) && (
|
||||
<ToolbarButton
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { useId } from "react";
|
||||
import { Plus, Trash2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Text } from "@/components/ui/text";
|
||||
|
|
@ -23,6 +24,8 @@ type PocContactFieldsProps = {
|
|||
onAdditionalContactsChange: (contacts: WorkOrderAdditionalContact[]) => void;
|
||||
helperText?: string;
|
||||
showPrimaryErrors?: boolean;
|
||||
/** Labels the primary name/phone inputs with a persistent required asterisk. */
|
||||
primaryRequired?: boolean;
|
||||
};
|
||||
|
||||
function extraNameMissing(contact: WorkOrderAdditionalContact): boolean {
|
||||
|
|
@ -135,7 +138,9 @@ export function PocContactFields({
|
|||
onAdditionalContactsChange,
|
||||
helperText,
|
||||
showPrimaryErrors = false,
|
||||
primaryRequired = false,
|
||||
}: PocContactFieldsProps) {
|
||||
const fieldId = useId();
|
||||
const nameMissing = showPrimaryErrors && !pocName.trim();
|
||||
const phoneMissing = showPrimaryErrors && !pocPhone.trim();
|
||||
|
||||
|
|
@ -153,7 +158,13 @@ export function PocContactFields({
|
|||
)}
|
||||
<div className="space-y-2">
|
||||
<div>
|
||||
{primaryRequired && (
|
||||
<FieldLabel required htmlFor={`${fieldId}-name`}>
|
||||
POC name
|
||||
</FieldLabel>
|
||||
)}
|
||||
<input
|
||||
id={`${fieldId}-name`}
|
||||
value={pocName}
|
||||
onChange={(event) => onPocNameChange(event.target.value)}
|
||||
placeholder="POC name"
|
||||
|
|
@ -168,7 +179,13 @@ export function PocContactFields({
|
|||
</Text>
|
||||
</div>
|
||||
<div>
|
||||
{primaryRequired && (
|
||||
<FieldLabel required htmlFor={`${fieldId}-phone`}>
|
||||
POC phone
|
||||
</FieldLabel>
|
||||
)}
|
||||
<input
|
||||
id={`${fieldId}-phone`}
|
||||
value={pocPhone}
|
||||
onChange={(event) => onPocPhoneChange(event.target.value)}
|
||||
placeholder="POC phone"
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ type MiniCalendarProps = {
|
|||
range?: boolean;
|
||||
rangeStart?: string;
|
||||
rangeEnd?: string;
|
||||
/** Days before this ISO date are disabled (SH-356 Due Date floor). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
export function MiniCalendar({
|
||||
|
|
@ -20,9 +22,11 @@ export function MiniCalendar({
|
|||
range,
|
||||
rangeStart = "",
|
||||
rangeEnd = "",
|
||||
minDate = "",
|
||||
}: MiniCalendarProps) {
|
||||
const initRaw = range ? rangeStart || value : value;
|
||||
const init = /^\d{4}-\d{2}-\d{2}$/.test(initRaw) ? initRaw : todayIso();
|
||||
const fallback = minDate > todayIso() ? minDate : todayIso();
|
||||
const init = /^\d{4}-\d{2}-\d{2}$/.test(initRaw) ? initRaw : fallback;
|
||||
const [iy, im] = init.split("-").map(Number);
|
||||
const [viewY, setViewY] = useState(iy);
|
||||
const [viewM, setViewM] = useState(im);
|
||||
|
|
@ -94,6 +98,7 @@ export function MiniCalendar({
|
|||
}
|
||||
const iso = `${viewY}-${pad2(viewM)}-${pad2(day)}`;
|
||||
const isToday = iso === today;
|
||||
const beforeMin = Boolean(minDate) && iso < minDate;
|
||||
const { bg, fg, radius, filled } = getMiniCalendarCellStyle({
|
||||
iso,
|
||||
value,
|
||||
|
|
@ -107,8 +112,9 @@ export function MiniCalendar({
|
|||
<button
|
||||
key={i}
|
||||
type="button"
|
||||
disabled={beforeMin}
|
||||
onClick={() => onChange(iso)}
|
||||
className="text-center text-[12px] transition-colors hover:bg-[var(--color-primary-tint)]"
|
||||
className="text-center text-[12px] transition-colors hover:bg-[var(--color-primary-tint)] disabled:cursor-not-allowed disabled:bg-transparent disabled:opacity-40"
|
||||
style={{
|
||||
height: 26,
|
||||
borderRadius: radius,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ type WizardDateFieldProps = {
|
|||
scheduleEnd?: string;
|
||||
schedMode?: WizardSchedMode;
|
||||
onChangeRange?: (start: string, end: string) => void;
|
||||
/** Earliest selectable day in the date calendar (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
function fieldLabel(args: {
|
||||
|
|
@ -49,6 +51,7 @@ export function WizardDateField({
|
|||
scheduleEnd = "",
|
||||
schedMode,
|
||||
onChangeRange,
|
||||
minDate,
|
||||
}: WizardDateFieldProps) {
|
||||
const { anchorEl, open, setAnchor, close } = useMenuAnchor();
|
||||
const allowRange = Boolean(allowWeekMode && onChangeRange);
|
||||
|
|
@ -127,6 +130,7 @@ export function WizardDateField({
|
|||
) : (
|
||||
<MiniCalendar
|
||||
value={value}
|
||||
minDate={minDate}
|
||||
onChange={(iso) => {
|
||||
onChange(iso);
|
||||
close();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ type WizardDueDateFieldProps = {
|
|||
value: string;
|
||||
placeholder: string;
|
||||
onChange: (iso: string) => void;
|
||||
/** Schedule On floor: earlier days are not selectable (SH-356). */
|
||||
minDate?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -21,11 +23,19 @@ export function WizardDueDateField({
|
|||
value,
|
||||
placeholder,
|
||||
onChange,
|
||||
minDate,
|
||||
}: WizardDueDateFieldProps) {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
if (type !== "Emergency") {
|
||||
return <WizardDateField value={value} placeholder={placeholder} onChange={onChange} />;
|
||||
return (
|
||||
<WizardDateField
|
||||
value={value}
|
||||
placeholder={placeholder}
|
||||
onChange={onChange}
|
||||
minDate={minDate}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
|
|
@ -63,7 +73,13 @@ export function WizardDueDateField({
|
|||
</span>
|
||||
<ChevronDown size={13} className="shrink-0" style={{ color: "var(--muted-foreground)" }} />
|
||||
</button>
|
||||
<DueDateCalendarDialog open={open} onOpenChange={setOpen} value={value} onSave={onChange} />
|
||||
<DueDateCalendarDialog
|
||||
open={open}
|
||||
onOpenChange={setOpen}
|
||||
value={value}
|
||||
onSave={onChange}
|
||||
minDate={minDate}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export function WizardStepLocationPocFields({
|
|||
onAdditionalContactsChange={(contacts) => onUpdate("additionalContacts", contacts)}
|
||||
helperText="Auto-filled from records — edit if outdated"
|
||||
showPrimaryErrors={showErrors && pocIncomplete}
|
||||
primaryRequired
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ import {
|
|||
import { WizardSeverityPicker } from "@/app/(protected)/workorders/_components/wizard/wizard-severity-picker";
|
||||
import { CheckCircle2, Clock, Flame, Users, Wrench, Zap } from "lucide-react";
|
||||
import type { ElementType } from "react";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
const WO_TYPE_ICONS: Record<WOType, ElementType> = {
|
||||
PM: Wrench,
|
||||
|
|
@ -165,6 +169,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChange={(iso) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, iso),
|
||||
scheduledOn: iso,
|
||||
scheduleWeekOnly: false,
|
||||
scheduleEnd: "",
|
||||
|
|
@ -177,6 +182,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChangeWeek={(w) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, w),
|
||||
scheduledOn: w,
|
||||
scheduleWeekOnly: Boolean(w),
|
||||
scheduleEnd: "",
|
||||
|
|
@ -189,6 +195,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
onChangeRange={(s, e) =>
|
||||
onPatch(
|
||||
withAutoScheduleStatus(draft, {
|
||||
...clearDueDateBeforeSchedule(draft.dueDate, s),
|
||||
scheduledOn: s,
|
||||
scheduleEnd: e,
|
||||
schedMode: "range",
|
||||
|
|
@ -211,6 +218,7 @@ function WizardTypeScheduleDates({ draft, onUpdate, onPatch }: WizardTypeSchedul
|
|||
<WizardDueDateField
|
||||
type={draft.type}
|
||||
value={draft.dueDate}
|
||||
minDate={resolveDueDateFloor(draft)}
|
||||
placeholder="No due date"
|
||||
onChange={(iso) => onUpdate("dueDate", iso)}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,8 @@ export function useWorkOrdersBoardSource(filters: FiltersReturn): WorkOrdersBoar
|
|||
() =>
|
||||
buildResolvedBoardSearchParams({
|
||||
advApplied: filters.advApplied,
|
||||
search: filters.search,
|
||||
// Advanced Filters are global by design; the week-scoped keyword box has no effect.
|
||||
search: "",
|
||||
page: filters.page,
|
||||
pageSize: filters.pageSize,
|
||||
sortBy: filters.sortBy,
|
||||
|
|
@ -43,7 +44,6 @@ export function useWorkOrdersBoardSource(filters: FiltersReturn): WorkOrdersBoar
|
|||
}),
|
||||
[
|
||||
filters.advApplied,
|
||||
filters.search,
|
||||
filters.page,
|
||||
filters.pageSize,
|
||||
filters.sortBy,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
} from "@/domain/work-orders/use-cases/use-work-order-detail";
|
||||
import { useWorkOrderUsers } from "@/domain/work-orders/use-cases/use-work-orders-list";
|
||||
import { useWorkOrderTableMutations } from "@/domain/work-orders/use-cases/use-work-order-table-mutations";
|
||||
import { shouldCompleteAfterCompletionDoc } from "@/domain/work-orders/utils/completion-doc-auto-complete";
|
||||
import {
|
||||
patchWorkOrderAsCanceled,
|
||||
patchWorkOrderAsCompleted,
|
||||
|
|
@ -112,7 +113,17 @@ export function useWorkOrdersListPage() {
|
|||
generatedAt: data.generatedAt,
|
||||
};
|
||||
setCompletionDocs((prev) => ({ ...prev, [String(row.id)]: nextData }));
|
||||
await patchFieldAsync(row.id, { docStatus: status });
|
||||
const saved = await patchFieldAsync(row.id, { docStatus: status });
|
||||
if (saved.kind !== "board" || !shouldCompleteAfterCompletionDoc(status, saved.row)) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Generation is the one automatic completion — no confirmation dialog.
|
||||
await patchFieldAsync(row.id, { status: "Completed" }, saved.row);
|
||||
} catch {
|
||||
// The document is saved; the table mutation already surfaced the status error and
|
||||
// refetched, so the WO stays in its prior status for a manual retry.
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -43,10 +43,12 @@ export default function WorkOrdersListPage() {
|
|||
actions={
|
||||
<WorkOrdersListHeader
|
||||
search={filters.search}
|
||||
weekLabel={filters.weekLabel}
|
||||
onSearchChange={filters.handleSearchChange}
|
||||
onOpenAdvancedFilters={() => filters.setAdvOpen(true)}
|
||||
onNewWorkOrder={() => page.setWizardOpen(true)}
|
||||
activeFilterCount={filters.activeFilterCount}
|
||||
advancedFiltersActive={filters.advApplied != null}
|
||||
isFetching={tableData.isFetching && !tableData.isLoading}
|
||||
/>
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,11 +134,17 @@ export function useWorkOrderTableMutations(
|
|||
mutationFn: ({
|
||||
id,
|
||||
persistPatch,
|
||||
baseRow,
|
||||
}: {
|
||||
id: string | number;
|
||||
patch: WorkOrderTablePatch;
|
||||
persistPatch: WorkOrderTablePatch;
|
||||
}) => enqueuePatch(id, () => runWorkOrderTablePatch(id, persistPatch, getRow)),
|
||||
/** Server row from a just-settled patch; its rowVersion is fresher than the table snapshot. */
|
||||
baseRow?: WorkOrderTableRow;
|
||||
}) =>
|
||||
enqueuePatch(id, () =>
|
||||
runWorkOrderTablePatch(id, persistPatch, baseRow ? () => baseRow : getRow),
|
||||
),
|
||||
onMutate: async ({ id, persistPatch }) => {
|
||||
onPatch(id, persistPatch);
|
||||
},
|
||||
|
|
@ -182,9 +188,13 @@ export function useWorkOrderTableMutations(
|
|||
);
|
||||
};
|
||||
|
||||
const patchFieldAsync = (id: string | number, patch: WorkOrderTablePatch) => {
|
||||
const persistPatch = resolvePatch(id, patch);
|
||||
return patchMutation.mutateAsync({ id, patch, persistPatch });
|
||||
const patchFieldAsync = (
|
||||
id: string | number,
|
||||
patch: WorkOrderTablePatch,
|
||||
baseRow?: WorkOrderTableRow,
|
||||
) => {
|
||||
const persistPatch = baseRow ? mergeAutoSchedulePatch(baseRow, patch) : resolvePatch(id, patch);
|
||||
return patchMutation.mutateAsync({ id, patch, persistPatch, baseRow });
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
|
|||
25
src/domain/work-orders/utils/completion-doc-auto-complete.ts
Normal file
25
src/domain/work-orders/utils/completion-doc-auto-complete.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import type { CompDocSaveStatus } from "@/domain/work-orders/types/completion-doc";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import {
|
||||
getClosabilityGaps,
|
||||
tableRowToClosabilityInput,
|
||||
} from "@/domain/work-orders/utils/wo-closability";
|
||||
|
||||
/**
|
||||
* Completion is manual with confirmation, except that generating the completion document
|
||||
* completes the WO — but only when the closability gate passes on the persisted row.
|
||||
* Not-required (NN) and drafts never complete; Past Due rows must be
|
||||
* rescheduled before any status change, so they are left for the dispatcher.
|
||||
*/
|
||||
export function shouldCompleteAfterCompletionDoc(
|
||||
status: CompDocSaveStatus,
|
||||
row: WorkOrderTableRow,
|
||||
): boolean {
|
||||
if (status !== "Yes" || row.docStatus !== "Yes") {
|
||||
return false;
|
||||
}
|
||||
if (row.status === "Completed" || row.status === "Canceled" || row.isPastDue) {
|
||||
return false;
|
||||
}
|
||||
return getClosabilityGaps(tableRowToClosabilityInput(row)).length === 0;
|
||||
}
|
||||
27
src/domain/work-orders/utils/due-date-floor.ts
Normal file
27
src/domain/work-orders/utils/due-date-floor.ts
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/**
|
||||
* SH-356: a Due Date can never be earlier than Schedule On.
|
||||
*
|
||||
* The floor is the concrete Schedule On day, the start of a date range, or — for a
|
||||
* week-only schedule (SH-110) — the first day of the target week.
|
||||
*/
|
||||
export function resolveDueDateFloor(schedule: {
|
||||
scheduledOn?: string | null;
|
||||
targetWeek?: string | null;
|
||||
}): string {
|
||||
return schedule.scheduledOn?.trim() || schedule.targetWeek?.trim() || "";
|
||||
}
|
||||
|
||||
export function isDueDateBeforeFloor(dueDate: string | null | undefined, floor: string): boolean {
|
||||
return Boolean(dueDate && floor && dueDate < floor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch fragment for a Schedule On change: clears an existing Due Date that the new
|
||||
* schedule would leave in the past. Never bumps it to a guessed value.
|
||||
*/
|
||||
export function clearDueDateBeforeSchedule(
|
||||
dueDate: string | null | undefined,
|
||||
nextFloor: string,
|
||||
): { dueDate?: string } {
|
||||
return isDueDateBeforeFloor(dueDate, nextFloor) ? { dueDate: "" } : {};
|
||||
}
|
||||
|
|
@ -12,6 +12,11 @@ const EMPTY_OWNERSHIP: MediaSurfaceOwnership = {
|
|||
extraOwnedIds: new Set(),
|
||||
};
|
||||
|
||||
/** Only Reactive and Emergency work orders render a media gallery on the Completion tab. */
|
||||
export function hasCompletionMediaGallery(type: string | null | undefined): boolean {
|
||||
return type === "Emergency" || type === "Reactive";
|
||||
}
|
||||
|
||||
function isPhotoOrVideo(item: MediaFile): boolean {
|
||||
return item.fileType === "image" || item.fileType === "video";
|
||||
}
|
||||
|
|
@ -24,20 +29,25 @@ function isInFlight(item: MediaFile): boolean {
|
|||
export function isCompletionSurfaceMedia(
|
||||
item: MediaFile,
|
||||
ownership: MediaSurfaceOwnership = EMPTY_OWNERSHIP,
|
||||
completionHasGallery = true,
|
||||
): boolean {
|
||||
if (isInFlight(item)) return true;
|
||||
if (COMPLETION_PURPOSES.has(item.purpose ?? "")) return true;
|
||||
if (!completionHasGallery && item.purpose === "Extra") return false;
|
||||
if (ownership.completionOwnedIds.has(item.id)) return true;
|
||||
if (ownership.extraOwnedIds.has(item.id)) return false;
|
||||
return item.purpose === "Extra" && isPhotoOrVideo(item);
|
||||
}
|
||||
|
||||
/** Without a Completion gallery, every Extra item (including photos/videos) belongs to Extras. */
|
||||
export function isExtrasSurfaceMedia(
|
||||
item: MediaFile,
|
||||
ownership: MediaSurfaceOwnership = EMPTY_OWNERSHIP,
|
||||
completionHasGallery = true,
|
||||
): boolean {
|
||||
if (item.purpose === "Aveta") return true;
|
||||
if (item.purpose !== "Extra") return false;
|
||||
if (!completionHasGallery) return true;
|
||||
if (ownership.completionOwnedIds.has(item.id)) return false;
|
||||
if (ownership.extraOwnedIds.has(item.id)) return true;
|
||||
return !isPhotoOrVideo(item);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,194 @@
|
|||
import { fireEvent, render, renderHook, screen, within } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { SlideOverInfoTabEditView } from "@/app/(protected)/workorders/_components/detail/tabs/slide-over-info-tab-edit-view";
|
||||
import { WoTableInlineRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-inline-row";
|
||||
import { useWoTableRowHandlers } from "@/app/(protected)/workorders/_components/list/table/use-wo-table-row-handlers";
|
||||
import { MiniCalendar } from "@/app/(protected)/workorders/_components/wizard/mini-calendar";
|
||||
import { WizardStepTypeSchedule } from "@/app/(protected)/workorders/_components/wizard/wizard-step-type-schedule";
|
||||
import { EMPTY_TABLE_DRAFT } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { EMPTY_WIZARD_DRAFT } from "@/domain/work-orders/types/work-order-wizard";
|
||||
import { pad2, todayIso } from "@/domain/work-orders/utils/wizard-date-utils";
|
||||
import { renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/site-cell", () => ({
|
||||
SiteCell: () => null,
|
||||
}));
|
||||
vi.mock(
|
||||
"@/app/(protected)/workorders/_components/list/table/cells/editable-wo-number-cell",
|
||||
() => ({ EditableWONumberCell: () => null }),
|
||||
);
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/type-cell", () => ({
|
||||
TypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/assigned-to-cell", () => ({
|
||||
AssignedToCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/appt-time-cell", () => ({
|
||||
ApptTimeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/pm-type-cell", () => ({
|
||||
PMTypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/vendor-cell", () => ({
|
||||
VendorCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/status-cell", () => ({
|
||||
StatusCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/reschedule-notify", () => ({
|
||||
rescheduleNotify: vi.fn(),
|
||||
weekMoveNotify: vi.fn(),
|
||||
}));
|
||||
|
||||
function day(n: number): string {
|
||||
const [y, m] = todayIso().split("-").map(Number);
|
||||
return `${y}-${pad2(m)}-${pad2(n)}`;
|
||||
}
|
||||
|
||||
function rowByLabel(label: string) {
|
||||
return screen.getByText(label, { selector: "span,label,div" }).closest("div")!;
|
||||
}
|
||||
|
||||
describe("Due Date cannot be before Schedule On (SH-356)", () => {
|
||||
it("disables calendar days before the floor", () => {
|
||||
render(<MiniCalendar value={day(12)} minDate={day(10)} onChange={vi.fn()} />);
|
||||
|
||||
expect(screen.getByRole("button", { name: "9" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "10" })).toBeEnabled();
|
||||
expect(screen.getByRole("button", { name: "11" })).toBeEnabled();
|
||||
});
|
||||
|
||||
describe("slide-over edit", () => {
|
||||
const draft = { scheduledOn: day(10), dueDate: day(12) } as Partial<WorkOrderTableRow>;
|
||||
|
||||
function renderSlideOver(onDraftChange = vi.fn()) {
|
||||
renderWithProviders(
|
||||
<SlideOverInfoTabEditView
|
||||
draft={{ ...EMPTY_TABLE_DRAFT, id: 42, targetWeek: "", ...draft } as WorkOrderTableRow}
|
||||
users={[]}
|
||||
sites={[]}
|
||||
vendors={[]}
|
||||
pmTypes={[]}
|
||||
allOrders={[]}
|
||||
onDraftChange={onDraftChange}
|
||||
/>,
|
||||
);
|
||||
return onDraftChange;
|
||||
}
|
||||
|
||||
it("disables Due Date days before Schedule On", async () => {
|
||||
renderSlideOver();
|
||||
fireEvent.click(within(rowByLabel("Due Date")).getByRole("button"));
|
||||
|
||||
expect(await screen.findByRole("button", { name: "9" })).toBeDisabled();
|
||||
expect(screen.getByRole("button", { name: "10" })).toBeEnabled();
|
||||
});
|
||||
|
||||
it("clears the Due Date when Schedule On moves past it", async () => {
|
||||
const onDraftChange = renderSlideOver();
|
||||
fireEvent.click(within(rowByLabel("Schedule On")).getAllByRole("button")[0]);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "15" }));
|
||||
|
||||
expect(onDraftChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("wizard: clears Due Date on a later Schedule On and floors the Due Date picker", async () => {
|
||||
const onPatch = vi.fn();
|
||||
render(
|
||||
<WizardStepTypeSchedule
|
||||
draft={{ ...EMPTY_WIZARD_DRAFT, scheduledOn: day(10), schedMode: "date", dueDate: day(12) }}
|
||||
users={[]}
|
||||
onUpdate={vi.fn()}
|
||||
onPatch={onPatch}
|
||||
/>,
|
||||
);
|
||||
|
||||
const dueDateButtons = within(rowByLabel("Due Date").parentElement!).getAllByRole("button");
|
||||
fireEvent.click(dueDateButtons[dueDateButtons.length - 1]);
|
||||
expect(await screen.findByRole("button", { name: "9" })).toBeDisabled();
|
||||
fireEvent.keyDown(document.activeElement ?? document.body, { key: "Escape" });
|
||||
|
||||
const scheduleBlock = rowByLabel("Schedule On").parentElement!;
|
||||
const scheduleButtons = within(scheduleBlock).getAllByRole("button");
|
||||
fireEvent.click(scheduleButtons[scheduleButtons.length - 1]);
|
||||
const calendars = await screen.findAllByRole("button", { name: "15" });
|
||||
fireEvent.click(calendars[calendars.length - 1]);
|
||||
|
||||
expect(onPatch).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("inline creation row: clears Due Date on a later Schedule On", async () => {
|
||||
const onChange = vi.fn();
|
||||
renderWithProviders(
|
||||
<table>
|
||||
<tbody>
|
||||
<WoTableInlineRow
|
||||
draft={{ ...EMPTY_TABLE_DRAFT, scheduledOn: day(10), dueDate: day(12) }}
|
||||
draftDayKey={day(10)}
|
||||
users={[]}
|
||||
sites={[]}
|
||||
vendors={[]}
|
||||
pmTypes={[]}
|
||||
allRows={[]}
|
||||
onChange={onChange}
|
||||
onSave={vi.fn()}
|
||||
onCancel={vi.fn()}
|
||||
/>
|
||||
</tbody>
|
||||
</table>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
const cells = screen.getAllByRole("cell");
|
||||
const dateButtons = cells.flatMap((cell) => within(cell).queryAllByRole("button"));
|
||||
const scheduleButton = dateButtons.find(
|
||||
(b) => b.textContent?.includes(day(10).slice(5).replace("-", "/")) ?? false,
|
||||
);
|
||||
fireEvent.click(scheduleButton ?? dateButtons[0]);
|
||||
fireEvent.click(await screen.findByRole("button", { name: "15" }));
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ scheduledOn: day(15), dueDate: "" }),
|
||||
);
|
||||
});
|
||||
|
||||
it("board row: sends the Due Date clear in the same schedule patch", () => {
|
||||
const onPatch = vi.fn();
|
||||
const { result } = renderHook(() =>
|
||||
useWoTableRowHandlers({
|
||||
tableData: {
|
||||
dragState: { current: { dragId: null, overId: null } },
|
||||
setDragViz: vi.fn(),
|
||||
reorderRows: vi.fn(),
|
||||
endDrag: vi.fn(),
|
||||
revealScheduledRow: vi.fn(),
|
||||
setSelectedId: vi.fn(),
|
||||
} as never,
|
||||
weekMonday: "2026-05-18",
|
||||
onNavigateToDay: vi.fn(),
|
||||
onOpenSlideOver: vi.fn(),
|
||||
onOpenMedia: vi.fn(),
|
||||
onPatch,
|
||||
onScheduleHighlight: vi.fn(),
|
||||
}),
|
||||
);
|
||||
|
||||
result.current.onScheduleDate("wo-1", "2026-05-21", "2026-05-20");
|
||||
expect(onPatch).toHaveBeenLastCalledWith("wo-1", expect.objectContaining({ dueDate: "" }));
|
||||
|
||||
result.current.onScheduleRange("wo-1", "2026-05-19", "2026-05-22", "2026-05-20");
|
||||
expect(onPatch.mock.lastCall?.[1]).not.toHaveProperty("dueDate");
|
||||
|
||||
result.current.onScheduleWeek("wo-1", "2026-05-25", "2026-05-20");
|
||||
expect(onPatch).toHaveBeenLastCalledWith(
|
||||
"wo-1",
|
||||
expect.objectContaining({ targetWeek: "2026-05-25", dueDate: "" }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
@ -42,6 +42,16 @@ describe("saveExistingRowType", () => {
|
|||
expect(onPatch.mock.calls[0]![2]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not warn when moving between SEV 3–5", () => {
|
||||
const onPatch = vi.fn();
|
||||
|
||||
saveExistingRowType(onPatch, { ...row, severity: 5 }, "Reactive", 3);
|
||||
|
||||
expect(toastWarn).not.toHaveBeenCalled();
|
||||
expect(onPatch).toHaveBeenCalledWith(7, { type: "Reactive", severity: 3 });
|
||||
expect(onPatch.mock.calls[0]![2]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not warn when clearing severity on a PM correction", () => {
|
||||
const onPatch = vi.fn();
|
||||
|
||||
|
|
|
|||
47
src/test/app/(protected)/workorders/severity-badge.test.tsx
Normal file
47
src/test/app/(protected)/workorders/severity-badge.test.tsx
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { SeverityBadge } from "@/app/(protected)/workorders/_components/list/table/cells/severity-badge";
|
||||
|
||||
describe("SeverityBadge", () => {
|
||||
it("shows description, Accept/Respond deadline, and after-hours on hover", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<SeverityBadge severity={1} />);
|
||||
|
||||
await user.hover(screen.getByText("SEV 1"));
|
||||
|
||||
const tooltip = await screen.findByRole("tooltip");
|
||||
expect(tooltip).toHaveTextContent(
|
||||
"Business Critical Function Down · Accept: 15 min · Respond: 2 hrs · After hours: Yes",
|
||||
);
|
||||
expect(tooltip).not.toHaveTextContent(/Quote|Tech Notes|Invoice|Turnaround/i);
|
||||
|
||||
await user.unhover(screen.getByText("SEV 1"));
|
||||
await waitFor(() => expect(screen.queryByRole("tooltip")).not.toBeInTheDocument());
|
||||
});
|
||||
|
||||
it("transcribes the SEV table row for the given severity", async () => {
|
||||
const user = userEvent.setup();
|
||||
render(<SeverityBadge severity={3} />);
|
||||
|
||||
await user.hover(screen.getByText("SEV 3"));
|
||||
|
||||
expect(await screen.findByRole("tooltip")).toHaveTextContent(
|
||||
"Group Productivity Impaired · Accept: 2 hrs · Respond: 8 hrs (next day if after hours) · After hours: Approval required",
|
||||
);
|
||||
});
|
||||
|
||||
it("is a button only when it can reopen the severity control", async () => {
|
||||
const onClick = vi.fn();
|
||||
const user = userEvent.setup();
|
||||
const { rerender } = render(<SeverityBadge severity={2} />);
|
||||
expect(screen.queryByRole("button")).not.toBeInTheDocument();
|
||||
|
||||
rerender(<SeverityBadge severity={2} onClick={onClick} />);
|
||||
const badge = screen.getByRole("button");
|
||||
expect(badge).toHaveTextContent("SEV 2");
|
||||
await user.click(badge);
|
||||
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
|
@ -161,4 +161,40 @@ describe("SlideOverExtrasTab Aveta", () => {
|
|||
|
||||
expect(screen.getByRole("button", { name: "safety-form.pdf" })).toBeDisabled();
|
||||
});
|
||||
|
||||
it("labels each extra item with its type and category", () => {
|
||||
const sitePhoto: MediaFile = {
|
||||
id: "m3",
|
||||
name: "site.jpg",
|
||||
fileType: "image",
|
||||
url: "blob:3",
|
||||
category: "Photo",
|
||||
purpose: "Extra",
|
||||
};
|
||||
const walkthrough: MediaFile = {
|
||||
id: "m4",
|
||||
name: "walkthrough.mp4",
|
||||
fileType: "video",
|
||||
url: "blob:4",
|
||||
category: "Video",
|
||||
purpose: "Extra",
|
||||
};
|
||||
|
||||
renderWithProviders(
|
||||
<SlideOverExtrasTab
|
||||
uploads={[sitePhoto, walkthrough, avetaDoc]}
|
||||
isReadOnly
|
||||
onUpload={vi.fn()}
|
||||
onRemove={vi.fn()}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByRole("group", { name: "Photo, Extra: site.jpg" })).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("group", { name: "Video, Extra: walkthrough.mp4" }),
|
||||
).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByRole("group", { name: "PDF, Aveta: aveta-clearance.pdf" }),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -278,4 +278,53 @@ describe("useSlideOverMediaState completion filter", () => {
|
|||
expect(remounted.result.current.completionMedia).toHaveLength(0);
|
||||
expect(remounted.result.current.extrasUploads.map((item) => item.id)).toEqual(["10"]);
|
||||
});
|
||||
|
||||
it("shows Extra photos and videos in Extra Docs on PM work orders", () => {
|
||||
const detail = detailWithMedia(
|
||||
[
|
||||
{
|
||||
id: "10",
|
||||
category: "Extra",
|
||||
url: "https://cdn.example.com/site.jpg",
|
||||
fileName: "site.jpg",
|
||||
uploadedAt: "2026-07-15T18:00:00.0000000Z",
|
||||
isLegacy: false,
|
||||
},
|
||||
{
|
||||
id: "11",
|
||||
category: "Extra",
|
||||
url: "https://cdn.example.com/walkthrough.mp4",
|
||||
fileName: "walkthrough.mp4",
|
||||
uploadedAt: "2026-07-15T18:00:00.0000000Z",
|
||||
isLegacy: false,
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
category: "Extra",
|
||||
url: "https://cdn.example.com/extra.pdf",
|
||||
fileName: "extra.pdf",
|
||||
uploadedAt: "2026-07-15T18:00:00.0000000Z",
|
||||
isLegacy: false,
|
||||
},
|
||||
],
|
||||
{ id: 200, type: "PM" },
|
||||
);
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
useSlideOverMediaState({
|
||||
detailForRow: detail,
|
||||
uploadMediaMutation: idleMutation(),
|
||||
deleteMediaMutation: idleMutation(),
|
||||
categorizeMediaMutation: idleMutation(),
|
||||
}),
|
||||
);
|
||||
|
||||
expect(result.current.completionMedia).toHaveLength(0);
|
||||
expect(result.current.extrasUploads.map((item) => item.id)).toEqual(["10", "11", "4"]);
|
||||
expect(result.current.extrasUploads.map((item) => item.fileType)).toEqual([
|
||||
"image",
|
||||
"video",
|
||||
"pdf",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,162 @@
|
|||
import { renderHook } from "@testing-library/react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { EMPTY_ADVANCED_FILTERS } from "@/domain/work-orders/types/work-order-advanced-filters";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
|
||||
const patchField = vi.hoisted(() => vi.fn());
|
||||
const patchFieldAsync = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("react-toastify", () => ({
|
||||
toast: {
|
||||
warning: vi.fn(),
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/app/(protected)/workorders/_hooks/use-work-orders-list-filters", () => ({
|
||||
useWorkOrdersListFilters: () => ({
|
||||
search: "",
|
||||
handleSearchChange: vi.fn(),
|
||||
advOpen: false,
|
||||
setAdvOpen: vi.fn(),
|
||||
advApplied: null,
|
||||
advInitial: EMPTY_ADVANCED_FILTERS,
|
||||
applyAdvancedFilters: vi.fn(),
|
||||
clearAdvancedFilters: vi.fn(),
|
||||
clearAdvancedFilterChip: vi.fn(),
|
||||
activeFilterCount: 0,
|
||||
weekMonday: "2026-07-20",
|
||||
selectedDayIso: "2026-07-20",
|
||||
setWeekMonday: vi.fn(),
|
||||
setSelectedDayIso: vi.fn(),
|
||||
navigateToDay: vi.fn(),
|
||||
dispatcherIds: new Set<string>(),
|
||||
setDispatcherIds: vi.fn(),
|
||||
types: new Set(),
|
||||
setTypes: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/app/(protected)/workorders/_hooks/use-work-orders-table-data", () => ({
|
||||
useWorkOrdersTableData: () => ({
|
||||
rows: [],
|
||||
totalCount: 0,
|
||||
scopeTotalCount: 0,
|
||||
isFetching: false,
|
||||
isLoading: false,
|
||||
setSelectedId: vi.fn(),
|
||||
patchRow: vi.fn(),
|
||||
clearRowPatch: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/use-cases/use-work-order-table-mutations", () => ({
|
||||
useWorkOrderTableMutations: () => ({
|
||||
patchField,
|
||||
patchFieldAsync,
|
||||
isPending: false,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/use-cases/use-work-orders-list", () => ({
|
||||
useWorkOrderUsers: () => ({ data: [], isLoading: false }),
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/use-cases/use-work-order-detail", () => ({
|
||||
useWorkOrderLocations: () => ({ data: [] }),
|
||||
useWorkOrderVendors: () => ({ data: [] }),
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/settings/dropdown-options/use-cases/use-dropdown-options-by-category", () => ({
|
||||
useDropdownOptionsByCategory: () => ({ data: [] }),
|
||||
}));
|
||||
|
||||
import { useWorkOrdersListPage } from "@/app/(protected)/workorders/_hooks/use-work-orders-list-page";
|
||||
|
||||
function closableRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
||||
return {
|
||||
id: 77,
|
||||
woNumber: "24866",
|
||||
type: "PM",
|
||||
dispatcherId: "u1",
|
||||
dispatcherName: "Dispatcher",
|
||||
company: "Vendor Co",
|
||||
vendorId: "7",
|
||||
tech: "Tech One",
|
||||
completedDate: "2026-09-15",
|
||||
pm: "HVAC",
|
||||
status: "In Progress",
|
||||
docStatus: "No",
|
||||
mediaCount: 0,
|
||||
isPastDue: false,
|
||||
rowVersion: "v1",
|
||||
upliftSummary: { hasUplift: false, pendingCount: 0 },
|
||||
...overrides,
|
||||
} as WorkOrderTableRow;
|
||||
}
|
||||
|
||||
describe("useWorkOrdersListPage completion document (SH-341)", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("completes the WO without confirmation once Generate persists the document", async () => {
|
||||
const saved = closableRow({ docStatus: "Yes", rowVersion: "v2" });
|
||||
patchFieldAsync.mockResolvedValueOnce({ kind: "board", row: saved });
|
||||
patchFieldAsync.mockResolvedValueOnce({
|
||||
kind: "board",
|
||||
row: { ...saved, status: "Completed" },
|
||||
});
|
||||
const { result } = renderHook(() => useWorkOrdersListPage());
|
||||
|
||||
await result.current.saveCompletionDoc(closableRow(), { notes: "", generatedAt: "now" }, "Yes");
|
||||
|
||||
expect(patchFieldAsync).toHaveBeenNthCalledWith(1, 77, { docStatus: "Yes" });
|
||||
expect(patchFieldAsync).toHaveBeenNthCalledWith(2, 77, { status: "Completed" }, saved);
|
||||
expect(patchField).not.toHaveBeenCalled();
|
||||
expect(result.current.confirmComplete).toBeNull();
|
||||
});
|
||||
|
||||
it("does not complete on Save draft or Not required", async () => {
|
||||
const { result } = renderHook(() => useWorkOrdersListPage());
|
||||
|
||||
patchFieldAsync.mockResolvedValueOnce({ kind: "board", row: closableRow({ docStatus: "No" }) });
|
||||
await result.current.saveCompletionDoc(closableRow(), { notes: "", generatedAt: "" }, "No");
|
||||
patchFieldAsync.mockResolvedValueOnce({ kind: "board", row: closableRow({ docStatus: "NN" }) });
|
||||
await result.current.saveCompletionDoc(closableRow(), { notes: "", generatedAt: "" }, "NN");
|
||||
|
||||
expect(patchFieldAsync).toHaveBeenCalledTimes(2);
|
||||
expect(patchFieldAsync).not.toHaveBeenCalledWith(
|
||||
77,
|
||||
{ status: "Completed" },
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps the closability gate: a missing service leaves the status unchanged", async () => {
|
||||
patchFieldAsync.mockResolvedValueOnce({
|
||||
kind: "board",
|
||||
row: closableRow({ docStatus: "Yes", pm: "" }),
|
||||
});
|
||||
const { result } = renderHook(() => useWorkOrdersListPage());
|
||||
|
||||
await result.current.saveCompletionDoc(closableRow(), { notes: "", generatedAt: "now" }, "Yes");
|
||||
|
||||
expect(patchFieldAsync).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("keeps the generated document when the automatic completion is rejected", async () => {
|
||||
patchFieldAsync.mockResolvedValueOnce({
|
||||
kind: "board",
|
||||
row: closableRow({ docStatus: "Yes" }),
|
||||
});
|
||||
patchFieldAsync.mockRejectedValueOnce(new Error("Work order was modified."));
|
||||
const { result } = renderHook(() => useWorkOrdersListPage());
|
||||
|
||||
await expect(
|
||||
result.current.saveCompletionDoc(closableRow(), { notes: "", generatedAt: "now" }, "Yes"),
|
||||
).resolves.toBeUndefined();
|
||||
expect(patchFieldAsync).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,121 @@
|
|||
import { fireEvent, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { PocContactFields } from "@/app/(protected)/workorders/_components/poc/poc-contact-fields";
|
||||
import { WoTableInlineRow } from "@/app/(protected)/workorders/_components/list/table/wo-table-inline-row";
|
||||
import {
|
||||
EMPTY_TABLE_DRAFT,
|
||||
type WorkOrderTableDraft,
|
||||
} from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/type-cell", () => ({
|
||||
TypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/assigned-to-cell", () => ({
|
||||
AssignedToCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/date-cell", () => ({
|
||||
DateCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/due-date-cell", () => ({
|
||||
DueDateCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/pm-type-cell", () => ({
|
||||
PMTypeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/vendor-cell", () => ({
|
||||
VendorCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/appt-time-cell", () => ({
|
||||
ApptTimeCell: () => null,
|
||||
}));
|
||||
vi.mock("@/app/(protected)/workorders/_components/list/table/cells/status-cell", () => ({
|
||||
StatusCell: () => null,
|
||||
}));
|
||||
|
||||
function renderInlineRow(draft: WorkOrderTableDraft, onSave = vi.fn()) {
|
||||
const ui = (d: WorkOrderTableDraft) => (
|
||||
<table>
|
||||
<tbody>
|
||||
<WoTableInlineRow
|
||||
draft={d}
|
||||
draftDayKey="2026-06-01"
|
||||
users={[]}
|
||||
sites={[]}
|
||||
vendors={[]}
|
||||
pmTypes={[]}
|
||||
allRows={[]}
|
||||
onChange={vi.fn()}
|
||||
onSave={onSave}
|
||||
onCancel={vi.fn()}
|
||||
/>
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
const view = renderWithProviders(ui(draft), { withAuth: false });
|
||||
return { ...view, rerenderDraft: (d: WorkOrderTableDraft) => view.rerender(ui(d)) };
|
||||
}
|
||||
|
||||
const COMPLETE_DRAFT: WorkOrderTableDraft = {
|
||||
...EMPTY_TABLE_DRAFT,
|
||||
site: "BK5",
|
||||
locationId: 9,
|
||||
woNumber: "12345678901",
|
||||
pocName: "Dana",
|
||||
pocPhone: "555-0100",
|
||||
};
|
||||
|
||||
describe("WoTableInlineRow required fields", () => {
|
||||
it("marks Site and WO # as required without showing errors before a Save attempt", () => {
|
||||
renderInlineRow(EMPTY_TABLE_DRAFT);
|
||||
|
||||
expect(screen.getByRole("button", { name: /^Site \*$/ })).toBeInTheDocument();
|
||||
expect(screen.getByText("Insert WO #")).toHaveTextContent("Insert WO # *");
|
||||
expect(screen.queryByText("Site is required")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Work order number is required")).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("reveals field errors only after Save is attempted, then clears them once corrected", () => {
|
||||
const onSave = vi.fn();
|
||||
const { rerenderDraft } = renderInlineRow(EMPTY_TABLE_DRAFT, onSave);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save work order" }));
|
||||
|
||||
expect(onSave).not.toHaveBeenCalled();
|
||||
expect(screen.getByText("Site is required")).toBeInTheDocument();
|
||||
expect(screen.getByText("Work order number is required")).toBeInTheDocument();
|
||||
|
||||
rerenderDraft(COMPLETE_DRAFT);
|
||||
|
||||
expect(screen.queryByText("Site is required")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("Work order number is required")).not.toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "Save work order" }));
|
||||
expect(onSave).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("PocContactFields required primary contact", () => {
|
||||
it("labels POC name and phone with a required asterisk when the contact is required", () => {
|
||||
renderWithProviders(
|
||||
<PocContactFields
|
||||
pocName=""
|
||||
pocPhone=""
|
||||
pocNotes=""
|
||||
additionalContacts={[]}
|
||||
primaryRequired
|
||||
onPocNameChange={vi.fn()}
|
||||
onPocPhoneChange={vi.fn()}
|
||||
onPocNotesChange={vi.fn()}
|
||||
onAdditionalContactsChange={vi.fn()}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.getByLabelText(/POC name/)).toHaveAttribute("placeholder", "POC name");
|
||||
expect(screen.getByLabelText(/POC phone/)).toHaveAttribute("placeholder", "POC phone");
|
||||
expect(screen.getByText("POC name").closest("label")).toHaveTextContent("POC name*");
|
||||
expect(screen.getByText("POC phone").closest("label")).toHaveTextContent("POC phone*");
|
||||
expect(screen.queryByText("Contact name is required")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
@ -189,7 +189,12 @@ vi.mock("@/app/(protected)/workorders/_components/list/table/wo-table", () => ({
|
|||
describe("WorkOrdersListHeader slice affordances", () => {
|
||||
it("hides New WO and Advanced Filters when callbacks are omitted", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader search="" onSearchChange={vi.fn()} activeFilterCount={0} />,
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
|
|
@ -202,6 +207,7 @@ describe("WorkOrdersListHeader slice affordances", () => {
|
|||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
onNewWorkOrder={vi.fn()}
|
||||
onOpenAdvancedFilters={vi.fn()}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,130 @@
|
|||
import { act, renderHook, screen, waitFor } from "@testing-library/react";
|
||||
import { QueryClientProvider } from "@tanstack/react-query";
|
||||
import type { ReactNode } from "react";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { EMPTY_ADVANCED_FILTERS } from "@/domain/work-orders/types/work-order-advanced-filters";
|
||||
import { createTestQueryClient, renderWithProviders } from "@/test/test-utils";
|
||||
|
||||
const { searchBoard, getBoard, emptyList } = vi.hoisted(() => ({
|
||||
searchBoard: vi.fn(),
|
||||
getBoard: vi.fn(),
|
||||
emptyList: [] as const,
|
||||
}));
|
||||
|
||||
vi.mock("@/hooks/use-debounce", () => ({
|
||||
useDebounce: <T,>(value: T) => value,
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/api/work-orders-api", () => ({
|
||||
workOrdersApi: {
|
||||
searchBoard: (...args: unknown[]) => searchBoard(...args),
|
||||
getBoard: (...args: unknown[]) => getBoard(...args),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("@/domain/work-orders/use-cases/use-work-order-detail", () => ({
|
||||
useWorkOrderLocations: () => ({ data: emptyList }),
|
||||
useWorkOrderVendors: () => ({ data: emptyList }),
|
||||
}));
|
||||
|
||||
import { WorkOrdersListHeader } from "@/app/(protected)/workorders/_components/list/work-orders-list-header";
|
||||
import { useWorkOrdersBoardSource } from "@/app/(protected)/workorders/_hooks/use-work-orders-board-source";
|
||||
import { useWorkOrdersListFilters } from "@/app/(protected)/workorders/_hooks/use-work-orders-list-filters";
|
||||
|
||||
const EMPTY_RESULT = { items: [], totalCount: 0, page: 0, pageSize: 25 };
|
||||
|
||||
function useBoardWithFilters() {
|
||||
const filters = useWorkOrdersListFilters();
|
||||
useWorkOrdersBoardSource(filters);
|
||||
return filters;
|
||||
}
|
||||
|
||||
function renderBoardSource() {
|
||||
const client = createTestQueryClient();
|
||||
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||
<QueryClientProvider client={client}>{children}</QueryClientProvider>
|
||||
);
|
||||
return renderHook(() => useBoardWithFilters(), { wrapper });
|
||||
}
|
||||
|
||||
describe("keyword search scope indicator", () => {
|
||||
it("shows no scope badge while the search box is empty", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search=""
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/searching within/i)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("names the active week while a keyword is typed", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search="hvac"
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={0}
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.getByText("Searching within 5/4–5/8")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("hides the scope label while Advanced Filters are active", () => {
|
||||
renderWithProviders(
|
||||
<WorkOrdersListHeader
|
||||
search="hvac"
|
||||
weekLabel="5/4–5/8"
|
||||
onSearchChange={vi.fn()}
|
||||
activeFilterCount={1}
|
||||
advancedFiltersActive
|
||||
/>,
|
||||
{ withAuth: false },
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/searching within/i)).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("keyword search vs Advanced Filters scope", () => {
|
||||
beforeEach(() => {
|
||||
searchBoard.mockReset().mockResolvedValue(EMPTY_RESULT);
|
||||
getBoard.mockReset().mockResolvedValue(EMPTY_RESULT);
|
||||
});
|
||||
|
||||
it("scopes keyword search to the active week", async () => {
|
||||
const { result } = renderBoardSource();
|
||||
|
||||
act(() => {
|
||||
result.current.setWeekMonday("2026-05-04");
|
||||
result.current.handleSearchChange("hvac");
|
||||
});
|
||||
|
||||
await waitFor(() =>
|
||||
expect(getBoard).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ weekStart: "2026-05-04", weekEnd: "2026-05-08", search: "hvac" }),
|
||||
),
|
||||
);
|
||||
expect(searchBoard).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps Advanced Filters global and ignores the week-scoped keyword", async () => {
|
||||
const { result } = renderBoardSource();
|
||||
|
||||
act(() => {
|
||||
result.current.handleSearchChange("hvac");
|
||||
result.current.applyAdvancedFilters({ ...EMPTY_ADVANCED_FILTERS, rescheduled: true });
|
||||
});
|
||||
|
||||
await waitFor(() => expect(searchBoard).toHaveBeenCalled());
|
||||
const params = searchBoard.mock.lastCall?.[0] as Record<string, unknown>;
|
||||
expect(params.search).toBeUndefined();
|
||||
expect(params).not.toHaveProperty("weekStart");
|
||||
});
|
||||
});
|
||||
|
|
@ -224,6 +224,35 @@ describe("useWorkOrderTableMutations completion-doc persistence", () => {
|
|||
expect(serverState.scheduledDate).toBe(BASE_SERVER.scheduledDate);
|
||||
expect(serverState.status).toBe(BASE_SERVER.status);
|
||||
});
|
||||
it("sends the follow-up status patch with the rowVersion of the just-saved row (SH-341)", async () => {
|
||||
const staleTableRow = { ...BASE_ROW };
|
||||
const { result } = renderHook(
|
||||
() =>
|
||||
useWorkOrderTableMutations({
|
||||
onPatch: vi.fn(),
|
||||
clearPatch: () => undefined,
|
||||
getRow: () => staleTableRow,
|
||||
}),
|
||||
{ wrapper: makeWrapper() },
|
||||
);
|
||||
|
||||
let saved: Awaited<ReturnType<typeof result.current.patchFieldAsync>> | undefined;
|
||||
await act(async () => {
|
||||
saved = await result.current.patchFieldAsync(42, { docStatus: "Yes" });
|
||||
});
|
||||
expect(saved?.kind).toBe("board");
|
||||
const savedRow = saved?.kind === "board" ? saved.row : undefined;
|
||||
|
||||
await act(async () => {
|
||||
await result.current.patchFieldAsync(42, { status: "Completed" }, savedRow);
|
||||
});
|
||||
|
||||
expect(patchBoardField).toHaveBeenLastCalledWith(42, {
|
||||
field: "lifecycleStatus",
|
||||
value: "Completed",
|
||||
workOrderVersion: "AAAAAAA=-next",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("maybeAutoSchedule on board patch", () => {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import type { WorkOrderTableRow } from "@/domain/work-orders/types/work-order-table-row";
|
||||
import { shouldCompleteAfterCompletionDoc } from "@/domain/work-orders/utils/completion-doc-auto-complete";
|
||||
|
||||
function closablePmRow(overrides: Partial<WorkOrderTableRow> = {}): WorkOrderTableRow {
|
||||
return {
|
||||
id: 42,
|
||||
woNumber: "24866",
|
||||
type: "PM",
|
||||
dispatcherId: "u1",
|
||||
dispatcherName: "Dispatcher",
|
||||
company: "Vendor Co",
|
||||
vendorId: "7",
|
||||
tech: "Tech One",
|
||||
completedDate: "2026-09-15",
|
||||
pm: "HVAC",
|
||||
status: "In Progress",
|
||||
docStatus: "Yes",
|
||||
mediaCount: 0,
|
||||
isPastDue: false,
|
||||
upliftSummary: { hasUplift: false, pendingCount: 0 },
|
||||
...overrides,
|
||||
} as WorkOrderTableRow;
|
||||
}
|
||||
|
||||
describe("shouldCompleteAfterCompletionDoc (SH-341)", () => {
|
||||
it("completes a closable PM once the generated document is persisted", () => {
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow())).toBe(true);
|
||||
});
|
||||
|
||||
it("never completes on Save draft or Not required", () => {
|
||||
expect(shouldCompleteAfterCompletionDoc("No", closablePmRow({ docStatus: "No" }))).toBe(false);
|
||||
expect(shouldCompleteAfterCompletionDoc("NN", closablePmRow({ docStatus: "NN" }))).toBe(false);
|
||||
});
|
||||
|
||||
it("does not complete when the server did not persist the document as generated", () => {
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow({ docStatus: "No" }))).toBe(false);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["dispatcher", { dispatcherId: "", dispatcherName: "" }],
|
||||
["vendor", { company: "", vendorId: "" }],
|
||||
["completed date", { completedDate: "" }],
|
||||
["real WO number", { woNumber: "SH02137" }],
|
||||
["service", { pm: "" }],
|
||||
["pending uplift", { upliftSummary: { hasUplift: true, pendingCount: 1 } }],
|
||||
["photo on a Reactive WO", { type: "Reactive" as const, mediaCount: 0 }],
|
||||
])("keeps the SH-114 closability gate: missing %s blocks completion", (_label, overrides) => {
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow(overrides))).toBe(false);
|
||||
});
|
||||
|
||||
it("completes a Reactive WO that has its completion photo", () => {
|
||||
expect(
|
||||
shouldCompleteAfterCompletionDoc("Yes", closablePmRow({ type: "Reactive", mediaCount: 1 })),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("leaves Completed, Canceled, and Past Due rows unchanged", () => {
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow({ status: "Completed" }))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow({ status: "Canceled" }))).toBe(
|
||||
false,
|
||||
);
|
||||
expect(shouldCompleteAfterCompletionDoc("Yes", closablePmRow({ isPastDue: true }))).toBe(false);
|
||||
});
|
||||
});
|
||||
29
src/test/domain/work-orders/utils/due-date-floor.test.ts
Normal file
29
src/test/domain/work-orders/utils/due-date-floor.test.ts
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
clearDueDateBeforeSchedule,
|
||||
isDueDateBeforeFloor,
|
||||
resolveDueDateFloor,
|
||||
} from "@/domain/work-orders/utils/due-date-floor";
|
||||
|
||||
describe("due date floor (SH-356)", () => {
|
||||
it("uses the concrete or range-start Schedule On, else the target week's first day", () => {
|
||||
expect(resolveDueDateFloor({ scheduledOn: "2026-09-10", targetWeek: "" })).toBe("2026-09-10");
|
||||
expect(resolveDueDateFloor({ scheduledOn: "", targetWeek: "2026-09-14" })).toBe("2026-09-14");
|
||||
expect(resolveDueDateFloor({ scheduledOn: "", targetWeek: "" })).toBe("");
|
||||
expect(resolveDueDateFloor({ scheduledOn: null, targetWeek: undefined })).toBe("");
|
||||
});
|
||||
|
||||
it("flags only a Due Date strictly before the floor", () => {
|
||||
expect(isDueDateBeforeFloor("2026-09-09", "2026-09-10")).toBe(true);
|
||||
expect(isDueDateBeforeFloor("2026-09-10", "2026-09-10")).toBe(false);
|
||||
expect(isDueDateBeforeFloor("", "2026-09-10")).toBe(false);
|
||||
expect(isDueDateBeforeFloor("2026-09-09", "")).toBe(false);
|
||||
});
|
||||
|
||||
it("clears (never bumps) a Due Date the new schedule passes", () => {
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "2026-09-15")).toEqual({ dueDate: "" });
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "2026-09-12")).toEqual({});
|
||||
expect(clearDueDateBeforeSchedule("2026-09-20", "2026-09-15")).toEqual({});
|
||||
expect(clearDueDateBeforeSchedule("2026-09-12", "")).toEqual({});
|
||||
});
|
||||
});
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import type { MediaFile } from "@/domain/work-orders/types/work-order-media";
|
||||
import {
|
||||
hasCompletionMediaGallery,
|
||||
isCompletionSurfaceMedia,
|
||||
isExtrasSurfaceMedia,
|
||||
} from "@/domain/work-orders/utils/partition-slide-over-media";
|
||||
|
|
@ -76,4 +77,33 @@ describe("partition-slide-over-media", () => {
|
|||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("renders a Completion gallery only for Reactive and Emergency work orders", () => {
|
||||
expect(hasCompletionMediaGallery("Reactive")).toBe(true);
|
||||
expect(hasCompletionMediaGallery("Emergency")).toBe(true);
|
||||
expect(hasCompletionMediaGallery("PM")).toBe(false);
|
||||
expect(hasCompletionMediaGallery("Overdue")).toBe(false);
|
||||
expect(hasCompletionMediaGallery("")).toBe(false);
|
||||
});
|
||||
|
||||
it("puts Extra photos and videos on Extra Docs when Completion has no gallery", () => {
|
||||
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
|
||||
const video = file({ id: "11", fileType: "video", purpose: "Extra", category: "Video" });
|
||||
|
||||
for (const item of [photo, video]) {
|
||||
expect(isCompletionSurfaceMedia(item, undefined, false)).toBe(false);
|
||||
expect(isExtrasSurfaceMedia(item, undefined, false)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
it("ignores stale completion ownership when Completion has no gallery", () => {
|
||||
const photo = file({ id: "10", fileType: "image", purpose: "Extra" });
|
||||
const ownership = {
|
||||
completionOwnedIds: new Set(["10"]),
|
||||
extraOwnedIds: new Set<string>(),
|
||||
};
|
||||
|
||||
expect(isCompletionSurfaceMedia(photo, ownership, false)).toBe(false);
|
||||
expect(isExtrasSurfaceMedia(photo, ownership, false)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,6 +18,21 @@ describe("shouldAnnounceSeverityEscalation", () => {
|
|||
expect(shouldAnnounceSeverityEscalation(2, 3)).toBe(false);
|
||||
});
|
||||
|
||||
it("announces when severity rises from SEV 3–5 into SEV 2", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(5, 2)).toBe(true);
|
||||
expect(shouldAnnounceSeverityEscalation(4, 2)).toBe(true);
|
||||
});
|
||||
|
||||
it("does not announce moves between SEV 3–5", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(5, 3)).toBe(false);
|
||||
expect(shouldAnnounceSeverityEscalation(4, 3)).toBe(false);
|
||||
expect(shouldAnnounceSeverityEscalation(3, 5)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not announce SEV 1 to SEV 2 (already critical)", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(1, 2)).toBe(false);
|
||||
});
|
||||
|
||||
it("does not announce SEV 2 to SEV 1 (already critical)", () => {
|
||||
expect(shouldAnnounceSeverityEscalation(2, 1)).toBe(false);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue