"use client"; import { useEffect, useMemo, useState } from "react"; import { copyRichEmail, downloadHtml, downloadOutlookDraft } from "@/lib/email-client"; import { buildGeneralEmail, type EmailBrand, type GeneralEmailContent } from "@/lib/email-templates"; export function EmailCreator({ brand }: { brand: EmailBrand }) { const [baseUrl, setBaseUrl] = useState(""); const [form, setForm] = useState({ subject: `Actualités de ${brand.associationName}`, kicker: brand.associationName, title: "Votre titre ici", body: "Bonjour,\n\nRédigez ici votre message. Créez plusieurs paragraphes en laissant une ligne vide.\n\nLe gabarit conserve automatiquement l'identité visuelle Plein R.", buttonLabel: "Découvrir", buttonUrl: "", signature: `À très bientôt,\nL'équipe de ${brand.associationName}`, }); const [flash, setFlash] = useState(""); const [error, setError] = useState(""); useEffect(() => { setBaseUrl(window.location.origin); setForm((current) => ({ ...current, buttonUrl: `${window.location.origin}/association` })); }, []); const email = useMemo( () => (baseUrl ? buildGeneralEmail(form, baseUrl, brand) : null), [baseUrl, brand, form], ); function change(name: keyof GeneralEmailContent, value: string) { setForm((current) => ({ ...current, [name]: value })); } function success(key: string) { setFlash(key); setTimeout(() => setFlash(""), 1800); } async function action(key: string, task: () => Promise | void) { try { setError(""); await task(); success(key); } catch (cause) { setError(cause instanceof Error ? cause.message : "Action impossible dans ce navigateur."); } } return (
Studio de communication

Composer un e-mail

Logo, couleurs Plein R et coordonnées ajoutés automatiquement.

change("subject", value)} /> change("kicker", value)} /> change("title", value)} /> change("body", value)} />
Bouton facultatif
change("buttonLabel", value)} /> change("buttonUrl", value)} />
change("signature", value)} />
{error &&
{error}
}

Ouvrez fichier .eml pour obtenir un brouillon Outlook prêt à compléter avec destinataires.

Objet : {form.subject}
{email ?