/** * What the server said about an invitation's email: queued, refused by the queue (not-queued), or unanswered * (unknown). Queued is never delivered. A missing or unrecognised answer, from a new account or an older server, * says nothing, so it is read as unconfirmed rather than as queued. */ export type InvitationMail = 'queued' | 'not-queued' | 'unknown'; export const INVITATION_MAIL_HEADER = 'X-Invitation-Notice'; export const invitationMailOf = (said: unknown): InvitationMail | undefined => said === 'queued' || said === 'not-queued' || said === 'unknown' ? said : undefined; /** * The line shown once an invitation is saved. The invitation itself is saved either way; only the email differs, so * an unsent or unconfirmed email is a warning beside a saved invitation, never a failure of it. */ export const invitationMailNotice = (mail: InvitationMail | undefined, to: string): { tone: 'success' | 'warning'; text: string } => { if (mail === 'queued') return { tone: 'success', text: `Invitation saved for ${to}, and its email is queued to send.` }; if (mail === 'not-queued') { return { tone: 'warning', text: `Invitation saved for ${to}, but its email was not sent. They can accept it when they next sign in.` }; } return { tone: 'warning', text: `Invitation saved for ${to}. We couldn't confirm its email was sent.` }; };