import { useCallback, useEffect, useState } from 'react'; import { Link } from 'react-router-dom'; import { api } from '../api'; import { CampaignSender } from './CampaignSender'; type Value = string | number | boolean; export type FieldDef = | { key: string; type: 'boolean'; label: string; help?: string; default: boolean } | { key: string; type: 'int' | 'hour'; label: string; help?: string; default: number; min: number; max: number; unit?: string } | { key: string; type: 'text' | 'textarea' | 'url'; label: string; help?: string; default: string; maxLength: number; variables?: string[] }; export interface ModuleInfo { id: string; name: string; tagline: string; description: string; fields: FieldDef[]; inPlan: boolean; override: boolean | null; available: boolean; config: Record & { enabled: boolean }; stats?: Record | null; } /** Pictogramme de chaque module (mĂȘme que dans l'app). */ const ICON: Record = { campaigns: '📣', reminders: '⏰', birthday: '🎂', reviews: '⭐', referral: 'đŸ€', stats: '📊', whiteLabel: 'đŸ·ïž' }; const isMessage = (f: FieldDef) => f.type === 'text' || f.type === 'textarea'; /** Origine du module pour ce magasin. */ function Origin({ m }: { m: ModuleInfo }) { const [label, tone] = m.override === true ? ['AjoutĂ© sur mesure', 'ACTIVE'] : m.override === false ? ['RetirĂ©', 'CLOSED'] : m.inPlan ? ['Inclus dans la formule', 'ACTIVE'] : ['Non inclus', 'DRAFT']; return {label}; } /** Champ de rĂ©glage gĂ©nĂ©rique, construit depuis la dĂ©finition du module (API). */ function Field({ f, value, onChange }: { f: FieldDef; value: Value; onChange: (v: Value) => void }) { const id = `f-${f.key}`; const help = ( <> {f.help && {f.help} } {'variables' in f && f.variables?.length ? ( Variables : {f.variables.map((v) => {v})} ) : null} ); if (f.type === 'boolean') { return ( ); } if (f.type === 'int' || f.type === 'hour') { return (
onChange(Math.floor(Number(e.target.value) || 0))} /> {f.type === 'hour' ? 'h' : f.unit}
{help}
); } const t = f as Extract; const text = String(value ?? ''); return (
{t.type === 'textarea' ? (