wacrm/src/lib/broadcast-status.ts
Arnas Donauskas 43b842efb6
fix(theme): keep status-badge token contract green (CI test)
The sweep over-tokenized the neutral status badges in the three status
data modules to bg-muted/border-border, which broke
broadcast-status.test.ts ("each variant has the dark-theme class
triple") — it asserts every badge is bg-*/10 + text-* + border-*/20.

The badge system intentionally uses fixed palette colors at low opacity
(translucent fills are mode-tolerant). Restore the original slate fills
(so dark is identical and the triple contract holds) but keep
text-muted-foreground for the label, so neutral statuses stay legible in
light mode where a solid slate-400 would be too faint on white.

- broadcast-status: draft / recipient pending
- template-status: DRAFT / PENDING_DELETION
- trigger-meta: time_based / fallback

All 400 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-17 13:08:32 +03:00

95 lines
2.6 KiB
TypeScript

/**
* Shared status badge config for broadcasts + recipients.
*
* Previously `statusConfig` was defined inline in both
* /broadcasts/page.tsx and /broadcasts/[id]/page.tsx with slight
* drift risk. One source of truth now.
*
* Badge shape: bg-*-500/10 + text-*-400 + border-*-500/20. The
* translucent fills sit fine on both light and dark surfaces; neutral
* statuses use text-muted-foreground so the label stays legible in
* light mode (a solid slate-400 would be too faint on white).
*/
import type { BroadcastStatus, RecipientStatus } from "@/types";
export interface StatusDisplay {
label: string;
classes: string;
/**
* Set true for statuses that should pulse in the UI to convey
* "live / in-flight" — currently only `sending`.
*/
pulse?: boolean;
}
export const broadcastStatusConfig: Record<BroadcastStatus, StatusDisplay> = {
draft: {
label: "Draft",
classes: "bg-slate-500/10 text-muted-foreground border-slate-500/20",
},
scheduled: {
label: "Scheduled",
classes: "bg-blue-500/10 text-blue-400 border-blue-500/20",
},
sending: {
label: "Sending",
classes: "bg-yellow-500/10 text-yellow-400 border-yellow-500/20",
pulse: true,
},
sent: {
label: "Sent",
classes: "bg-primary/10 text-primary border-primary/20",
},
failed: {
label: "Failed",
classes: "bg-red-500/10 text-red-400 border-red-500/20",
},
};
export const recipientStatusConfig: Record<RecipientStatus, StatusDisplay> = {
pending: {
label: "Pending",
classes: "bg-slate-500/10 text-muted-foreground border-slate-500/20",
},
sent: {
label: "Sent",
classes: "bg-blue-500/10 text-blue-400 border-blue-500/20",
},
delivered: {
label: "Delivered",
classes: "bg-primary/10 text-primary border-primary/20",
},
read: {
label: "Read",
classes: "bg-primary/10 text-primary border-primary/20",
},
replied: {
label: "Replied",
classes: "bg-purple-500/10 text-purple-400 border-purple-500/20",
},
failed: {
label: "Failed",
classes: "bg-red-500/10 text-red-400 border-red-500/20",
},
};
/**
* Tolerant lookup — callers often have a generic string status
* coming from Supabase. Falls back to the "draft" / "pending"
* entry so the UI never crashes on an unknown value.
*/
export function getBroadcastStatus(status: string): StatusDisplay {
return (
broadcastStatusConfig[status as BroadcastStatus] ??
broadcastStatusConfig.draft
);
}
export function getRecipientStatus(status: string): StatusDisplay {
return (
recipientStatusConfig[status as RecipientStatus] ??
recipientStatusConfig.pending
);
}