"use client"; import { useMemo, useState } from "react"; import { Modal } from "@/components/Modal"; import { copyRichEmail, downloadHtml, downloadOutlookDraft } from "@/lib/email-client"; import { buildMeetingEmail, defaultMeetingEmailTexts, type EmailBrand, type MeetingEmailData, type MeetingEmailTexts } from "@/lib/email-templates"; export function MeetingEmailComposer({ meeting, brand }: { meeting: MeetingEmailData; brand: EmailBrand }) { const [open, setOpen] = useState(false); const [baseUrl, setBaseUrl] = useState(""); const [texts, setTexts] = useState(() => defaultMeetingEmailTexts(brand)); const [flash, setFlash] = useState(""); const [error, setError] = useState(""); const email = useMemo(() => (baseUrl ? buildMeetingEmail(meeting, texts, baseUrl, brand) : null), [baseUrl, brand, meeting, texts]); function show() { setBaseUrl(window.location.origin); setOpen(true); } function change(name: keyof MeetingEmailTexts, value: string) { setTexts((current) => ({ ...current, [name]: value })); } async function action(key: string, task: () => Promise | void) { try { setError(""); await task(); setFlash(key); setTimeout(() => setFlash(""), 1800); } catch (cause) { setError(cause instanceof Error ? cause.message : "Action impossible dans ce navigateur."); } } return ( <> setOpen(false)} title={`Invitation — ${meeting.title}`} maxWidth={1100}>
change("greeting", value)} /> change("intro", value)} /> change("outro", value)} /> change("signature", value)} />

Date, lieu, description, places et lien d'inscription repris automatiquement.

{error &&
{error}
}
Objet : {email?.subject}
{email &&