{mismatched.length} selected attendee(s) have a notification preference that doesn't include{" "}
{channel === "email" ? "email" : "WhatsApp"}. They will still receive the message, but it may not be their preferred channel.
{" "}Use the dropdown to filter by preference.
);
}
function toLocalInputValue(d: Date) {
const pad = (n: number) => String(n).padStart(2, '0');
const y = d.getFullYear();
const m = pad(d.getMonth() + 1);
const day = pad(d.getDate());
const hh = pad(d.getHours());
const mm = pad(d.getMinutes());
return `${y}-${m}-${day}T${hh}:${mm}`;
}
function AutomationsPanel({ events, token, onInfo, onError }:{ events: any[]; token?: string | null; onInfo: (s: string) => void; onError: (s: string) => void }) {
const [autoEventId, setAutoEventId] = React.useState('');
const currentEvent = React.useMemo(() => (events || []).find((e:any) => e.id === autoEventId), [events, autoEventId]);
// Defaults builders
const preWeekDefault = React.useMemo(() => ({
subject: `1 Week to Go: {{event.title}}!`,
body: `Hi {{name}}\n\nJust a friendly reminder that {{event.title}} is one week away.\n\nVenue: [add venue]\nTime: {{event.start}}\nParking: [add parking info]\nPacking list: [add items if needed]\n\nMore details: {{event.link}}`,
}), []);
const finalDefault = React.useMemo(() => ({
subject: `We’ll See You Tomorrow at {{event.title}}!`,
body: `Hi {{name}}\n\nFinal reminder for {{event.title}}.\nArrival instructions: [add arrival info]\nPlease have your QR code/ticket ready at entry.\n\nEvent details: {{event.link}}`,
}), []);
const thanksDefault = React.useMemo(() => ({
subject: `Thanks for Joining {{event.title}}!`,
body: `Hi {{name}}\n\nThank you for joining us at {{event.title}}!\nHighlights: [add highlights]\nPhotos/recordings: [add links]\nSponsor shoutouts: [add sponsors]\n\nSee you next time!`,
}), []);
const promoDefault = React.useMemo(() => ({
subject: `Don’t Miss Our Next Event: {{promo.title}}`,
body: `Hi {{name}}\n\nWe’d love to see you at our next event: {{promo.title}}.\nFind out more and register here: {{promo.link}}`,
}), []);
// Enable toggles
const [enablePre, setEnablePre] = React.useState(true);
const [enableFinal, setEnableFinal] = React.useState(true);
const [enableThanks, setEnableThanks] = React.useState(true);
// Sponsors of "sponsor a spot" events get their own thank-you.
const [enableSponsors, setEnableSponsors] = React.useState(true);
const [sponsorSubject, setSponsorSubject] = React.useState('Thank you for sponsoring a spot at {{event.title}}');
const [sponsorBody, setSponsorBody] = React.useState(`Hi {{name}}
Thank you for sponsoring a spot at {{event.title}}. Because of you, someone was able to be there who otherwise couldn't.
[add a highlight or two]
With gratitude`);
const [enablePromo, setEnablePromo] = React.useState(false);
// Subjects/Bodies
const [preSubject, setPreSubject] = React.useState(preWeekDefault.subject);
const [preBody, setPreBody] = React.useState(preWeekDefault.body);
const [finalSubject, setFinalSubject] = React.useState(finalDefault.subject);
const [finalBody, setFinalBody] = React.useState(finalDefault.body);
const [thanksSubject, setThanksSubject] = React.useState(thanksDefault.subject);
const [thanksBody, setThanksBody] = React.useState(thanksDefault.body);
const [promoSubject, setPromoSubject] = React.useState(promoDefault.subject);
const [promoBody, setPromoBody] = React.useState(promoDefault.body);
// Timing
const [finalHours, setFinalHours] = React.useState<'24'|'48'>('24');
const [preWhen, setPreWhen] = React.useState('');
const [finalWhen, setFinalWhen] = React.useState('');
const [thanksWhen, setThanksWhen] = React.useState('');
const [promoWhen, setPromoWhen] = React.useState('');
const [promoEventId, setPromoEventId] = React.useState('');
// Compute defaults when event changes or finalHours change
React.useEffect(() => {
if (!currentEvent) { setPreWhen(''); setFinalWhen(''); setThanksWhen(''); setPromoWhen(''); return; }
try {
const start = new Date(currentEvent.startDate);
const end = new Date(currentEvent.endDate || currentEvent.startDate);
// Pre-event: 7 days before start at 09:00
const pre = new Date(start);
pre.setDate(pre.getDate() - 7);
pre.setHours(9, 0, 0, 0);
setPreWhen(toLocalInputValue(pre));
// Final reminder: hours before start
const fin = new Date(start);
fin.setHours(fin.getHours() - (finalHours === '48' ? 48 : 24));
setFinalWhen(toLocalInputValue(fin));
// Thanks: day after end at 09:00
const ty = new Date(end);
ty.setDate(ty.getDate() + 1);
ty.setHours(9, 0, 0, 0);
setThanksWhen(toLocalInputValue(ty));
// Promo: 3 days after end at 09:00
const pr = new Date(end);
pr.setDate(pr.getDate() + 3);
pr.setHours(9, 0, 0, 0);
setPromoWhen(toLocalInputValue(pr));
// Prefill subjects again using event title (user can edit afterward)
const title = currentEvent.title || 'the event';
setPreSubject(`1 Week to Go: ${title}!`);
setFinalSubject(`We’ll See You Tomorrow at ${title}!`);
setThanksSubject(`Thanks for Joining ${title}!`);
setPromoSubject(`Don’t Miss Our Next Event: {{promo.title}`);
} catch {}
}, [currentEvent, finalHours]);
const onSchedule = async () => {
try {
onError(null as any); onInfo(null as any);
if (!token) { onError('Not authenticated'); return; }
if (!autoEventId) { onError('Please select an event'); return; }
const jobs: any[] = [];
if (enablePre && preSubject.trim() && preBody.trim() && preWhen) {
const payload: any = { subject: preSubject, scheduledAt: new Date(preWhen).toISOString() };
if (preBody.trim().startsWith('<')) payload.html = preBody; else payload.text = preBody;
jobs.push(payload);
}
if (enableFinal && finalSubject.trim() && finalBody.trim() && finalWhen) {
const payload: any = { subject: finalSubject, scheduledAt: new Date(finalWhen).toISOString() };
if (finalBody.trim().startsWith('<')) payload.html = finalBody; else payload.text = finalBody;
jobs.push(payload);
}
if (enableThanks && thanksSubject.trim() && thanksBody.trim() && thanksWhen) {
const payload: any = { subject: thanksSubject, scheduledAt: new Date(thanksWhen).toISOString() };
if (thanksBody.trim().startsWith('<')) payload.html = thanksBody; else payload.text = thanksBody;
jobs.push(payload);
}
if (currentEvent?.allowSponsorships && enableSponsors && sponsorSubject.trim() && sponsorBody.trim() && thanksWhen) {
const payload: any = { subject: sponsorSubject, scheduledAt: new Date(thanksWhen).toISOString(), audience: 'sponsors' };
if (sponsorBody.trim().startsWith('<')) payload.html = sponsorBody; else payload.text = sponsorBody;
jobs.push(payload);
}
if (enablePromo && promoSubject.trim() && promoBody.trim() && promoWhen) {
const payload: any = { subject: promoSubject, scheduledAt: new Date(promoWhen).toISOString(), promoEventId: promoEventId || undefined };
if (promoBody.trim().startsWith('<')) payload.html = promoBody; else payload.text = promoBody;
jobs.push(payload);
}
if (jobs.length === 0) { onError('Please enable at least one automation and fill in details'); return; }
const res = await apiFetch(`/api/automations/schedule`, { method: 'POST', authToken: token, body: { eventId: autoEventId, jobs } });
onInfo(res?.message || `Scheduled ${jobs.length} automation(s).`);
// Reset to defaults (keep event selection)
setEnablePre(true); setEnableFinal(true); setEnableThanks(true); setEnablePromo(false);
setPreSubject(preWeekDefault.subject); setPreBody(preWeekDefault.body);
setFinalSubject(finalDefault.subject); setFinalBody(finalDefault.body); setFinalHours('24');
setThanksSubject(thanksDefault.subject); setThanksBody(thanksDefault.body);
setPromoSubject(promoDefault.subject); setPromoBody(promoDefault.body); setPromoEventId('');
} catch (e:any) {
onError(e?.message || 'Failed to schedule automations');
}
};
return (
{currentEvent?.allowSponsorships && (
)}
Placeholders supported: {'{{name}}'}, {'{{event.title}}'}, {'{{event.start}}'}, {'{{event.link}}'}, {'{{promo.title}}'}, {'{{promo.link}}'}. Start body with <html> or <div> to send HTML.