mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 18:33:12 +00:00
AccountId is resolved from Location on the server. Create UI matches AAP: required Site, optional Service, no Account picker.
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
/** Required fields for board inline create (Schedule On is optional — SH-109). */
|
|
export type InlineCreateReqField = "site" | "woNumber" | "pocName" | "pocPhone";
|
|
|
|
export const INLINE_CREATE_REQ_LABELS: Record<InlineCreateReqField, string> = {
|
|
site: "Site",
|
|
woNumber: "WO #",
|
|
pocName: "POC name",
|
|
pocPhone: "POC phone",
|
|
};
|
|
|
|
export type InlineCreateDraftFields = {
|
|
site?: string;
|
|
locationId?: string | number;
|
|
woNumber?: string;
|
|
pocName?: string;
|
|
pocPhone?: string;
|
|
};
|
|
|
|
export function getInlineCreateMissing(d: InlineCreateDraftFields): InlineCreateReqField[] {
|
|
const miss: InlineCreateReqField[] = [];
|
|
const hasSite = Boolean(d.site?.trim()) || Boolean(String(d.locationId ?? "").trim());
|
|
if (!hasSite) {
|
|
miss.push("site");
|
|
}
|
|
if (!d.woNumber?.trim()) {
|
|
miss.push("woNumber");
|
|
}
|
|
if (!d.pocName?.trim()) {
|
|
miss.push("pocName");
|
|
}
|
|
if (!d.pocPhone?.trim()) {
|
|
miss.push("pocPhone");
|
|
}
|
|
return miss;
|
|
}
|
|
|
|
/** Tooltip for Save: "Missing: Site, WO #" or "Save" when ready. */
|
|
export function inlineCreateSaveHint(miss: InlineCreateReqField[]): string {
|
|
if (miss.length === 0) {
|
|
return "Save";
|
|
}
|
|
return `Missing: ${miss.map((m) => INLINE_CREATE_REQ_LABELS[m]).join(", ")}`;
|
|
}
|
|
|
|
export function inlineCreateSiteError(miss: InlineCreateReqField[]): string {
|
|
if (miss.includes("site")) {
|
|
return "Site is required";
|
|
}
|
|
return "Contact name and phone are required";
|
|
}
|
|
|
|
/** Concrete calendar day/range — week-only does not count (design hasScheduleDate). */
|
|
export function draftHasScheduleDate(d: {
|
|
scheduledOn?: string;
|
|
scheduleWeekOnly?: boolean;
|
|
schedMode?: string;
|
|
}): boolean {
|
|
if (d.scheduleWeekOnly || d.schedMode === "week") {
|
|
return false;
|
|
}
|
|
return Boolean(d.scheduledOn?.trim());
|
|
}
|