pr_01m47d24b0e6n91zwymwxg0vpx/apps/web/app/lib/emails.ts
| 1 | import type { AccountEmail } from "@g1t/contracts"; |
| 2 | |
| 3 | /** The fields to send again once the person has confirmed their password. */ |
| 4 | export function pendingFields(form: FormData): Record<string, string> { |
| 5 | const fields: Record<string, string> = {}; |
| 6 | for (const [name, value] of form.entries()) { |
| 7 | if (name !== "intent" && name !== "password" && typeof value === "string") fields[name] = value; |
| 8 | } |
| 9 | return fields; |
| 10 | } |
| 11 | |
| 12 | /** What can be done to one address, by the same rules identity applies. */ |
| 13 | export function addressActions(email: AccountEmail, all: AccountEmail[]): { makePrimary: boolean; remove: boolean; resend: boolean } { |
| 14 | const confirmed = all.filter((other) => other.verified).length; |
| 15 | return { |
| 16 | makePrimary: email.verified && !email.primary, |
| 17 | remove: !email.primary && !(email.verified && confirmed <= 1), |
| 18 | resend: !email.verified, |
| 19 | }; |
| 20 | } |
| 21 | |
| 22 | /** The addresses that can be the backup: confirmed, and not the primary. */ |
| 23 | export function backupChoices(all: AccountEmail[]): AccountEmail[] { |
| 24 | return all.filter((email) => email.verified && !email.primary); |
| 25 | } |