import { useEffect, useRef, useState } from 'react'; import { adminApi } from './adminApi.js'; const TYPES = [ { id: 'invitation', label: 'Invitation email', detail: 'Sent to every imported doctor.', }, { id: 'reminder', label: 'Reminder email', detail: 'Sent to imported doctors who still have Login, Consent, Agreement, Approval, or Survey pending.', }, ]; /** * @param {{ status?: string, sentCount?: number, recipientCount?: number, error?: string | null, from?: string }} queued */ function sendResult(queued) { if ((queued.recipientCount ?? 0) === 0) { return 'No emails were sent.'; } if (queued.status === 'sent') { const from = queued.from ? ` from ${queued.from}` : ''; return `${queued.sentCount} emails were sent${from}.`; } if (queued.status === 'logged') { return `Saved ${queued.recipientCount} emails. SendGrid is not configured.`; } if (queued.error) { return queued.error; } return `Sent ${queued.sentCount ?? 0} of ${queued.recipientCount ?? 0} emails.`; } /** * @param {{ sentCount?: number, recipientCount?: number }} queued */ function sendingProgress(queued) { return `Sent ${queued.sentCount ?? 0} of ${queued.recipientCount ?? 0} emails.`; } /** * @param {{ onClose: () => void }} props */ function useEscapeClose(onClose) { useEffect(() => { function onKey(event) { if (event.key === 'Escape') { onClose(); } } window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [onClose]); } /** * @param {{ * subject: string, * body: string, * onSubject: (value: string) => void, * onBody: (value: string) => void, * onClose: () => void, * }} props */ function LetterScreen({ subject, body, onSubject, onBody, onClose }) { useEscapeClose(onClose); return (

Edit the letter