33 lines
1.3 KiB
TypeScript
33 lines
1.3 KiB
TypeScript
/** Shared display helpers for admin screens (browser-safe). */
|
||
export const money = (cents: number, currency = "CAD") =>
|
||
new Intl.NumberFormat("en-CA", { style: "currency", currency }).format(cents / 100);
|
||
|
||
export const niceDate = (d: string | null | undefined, long = false) =>
|
||
d
|
||
? new Date(`${d}T12:00:00Z`).toLocaleDateString("en-CA", {
|
||
weekday: long ? "long" : "short",
|
||
month: long ? "long" : "short",
|
||
day: "numeric",
|
||
timeZone: "UTC",
|
||
})
|
||
: "—";
|
||
|
||
export const t12 = (hhmm?: string | null) => {
|
||
if (!hhmm) return "";
|
||
const [h, m] = hhmm.split(":").map(Number);
|
||
return `${h % 12 || 12}${m ? `:${String(m).padStart(2, "0")}` : ""} ${h >= 12 ? "PM" : "AM"}`;
|
||
};
|
||
|
||
export const slotLabel = (s?: string | null, e?: string | null) => (s && e ? `${t12(s)} – ${t12(e)}` : "—");
|
||
|
||
export const STATUS_TONE: Record<string, "success" | "critical" | "neutral" | "info" | "warning"> = {
|
||
confirmed: "success",
|
||
needs_review: "critical",
|
||
cancelled: "neutral",
|
||
fulfilled: "info",
|
||
};
|
||
|
||
export const METHOD_LABEL: Record<string, string> = { pickup: "Pickup", delivery: "Delivery", shipping: "Shipping" };
|
||
|
||
export const rangesToText = (r?: { start: string; end: string }[]) => (r ?? []).map((x) => `${x.start}-${x.end}`).join(", ");
|