mirror of
https://github.com/Luchexx/wacrm.git
synced 2026-11-02 17:29:45 +00:00
Switches message_templates.status from the local TitleCase set
(Draft|Pending|Approved|Rejected) to Meta's raw enum (DRAFT|PENDING|
APPROVED|REJECTED|PAUSED|DISABLED|IN_APPEAL|PENDING_DELETION) and
adds the columns the upcoming submit / edit / resubmit / webhook
flows need. No new user-facing behavior — this is groundwork.
Migration 014 also adds:
* sample_values JSONB Meta requires these for variable templates
* meta_template_id TEXT hsm_id for scoped edit/delete (avoids
nuking sibling-language variants)
* rejection_reason TEXT surfaced from webhook on REJECTED
* quality_score TEXT GREEN | YELLOW | RED, from webhook
* header_handle TEXT from Resumable Upload (media headers)
* header_media_url TEXT URL fallback for media headers (v1 path)
* submission_error TEXT last 4xx from Meta, for retry surface
* last_submitted_at rate-limit awareness (100 creates/hour)
* buttons JSONB shape CHECK permissive array-of-typed-objects guard
(strict per-type validation lives in API)
* UNIQUE (user_id, name, language)
so sync upsert is atomic and prevents
duplicate language variants
* idx on meta_template_id fast webhook lookup
Sync route now:
* persists Meta's status verbatim (PAUSED no longer collapses to
REJECTED — these are different states with different recoverability)
* parses BUTTONS components into the new discriminated-union shape
* extracts sample_values from body.example.body_text + header.example
* persists meta_template_id, quality_score, header_handle
Shared template-status.ts gives the manager / inbox picker / broadcast
picker one source of truth for labels + dark-theme badge classes.
Part of the Issue #147 overhaul plan (PR 2 of 6 in the sequence).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
/**
|
|
* Shared display config for message_templates.status.
|
|
*
|
|
* The DB stores Meta's raw enum (DRAFT / APPROVED / PENDING / REJECTED /
|
|
* PAUSED / DISABLED / IN_APPEAL / PENDING_DELETION) — the UI maps it to
|
|
* a human label + dark-theme badge classes here so the template manager,
|
|
* inbox picker, and broadcast picker stay aligned.
|
|
*/
|
|
|
|
import type { MessageTemplateStatus } from '@/types';
|
|
|
|
export interface TemplateStatusDisplay {
|
|
label: string;
|
|
classes: string;
|
|
}
|
|
|
|
export const templateStatusConfig: Record<
|
|
MessageTemplateStatus,
|
|
TemplateStatusDisplay
|
|
> = {
|
|
DRAFT: {
|
|
label: 'Draft',
|
|
classes: 'bg-slate-600/20 text-slate-400 border-slate-600/30',
|
|
},
|
|
PENDING: {
|
|
label: 'Pending',
|
|
classes: 'bg-yellow-600/20 text-yellow-400 border-yellow-600/30',
|
|
},
|
|
APPROVED: {
|
|
label: 'Approved',
|
|
classes: 'bg-primary/20 text-primary border-primary/30',
|
|
},
|
|
REJECTED: {
|
|
label: 'Rejected',
|
|
classes: 'bg-red-600/20 text-red-400 border-red-600/30',
|
|
},
|
|
PAUSED: {
|
|
label: 'Paused',
|
|
classes: 'bg-orange-600/20 text-orange-400 border-orange-600/30',
|
|
},
|
|
DISABLED: {
|
|
label: 'Disabled',
|
|
classes: 'bg-red-900/30 text-red-500 border-red-900/40',
|
|
},
|
|
IN_APPEAL: {
|
|
label: 'In Appeal',
|
|
classes: 'bg-blue-600/20 text-blue-400 border-blue-600/30',
|
|
},
|
|
PENDING_DELETION: {
|
|
label: 'Pending Deletion',
|
|
classes: 'bg-slate-700/30 text-slate-500 border-slate-700/40',
|
|
},
|
|
};
|