g1t/apps/web/app/lib/emails.ts

25 lines1,078 bytesCodeBlame

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Invite-only launch: sign in with GitHub, repository access and lifecycle, many emails, a new look1import type { AccountEmail } from "@g1t/contracts";
2
3/** The fields to send again once the person has confirmed their password. */
4export 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. */
13export 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. */
23export function backupChoices(all: AccountEmail[]): AccountEmail[] {
24 return all.filter((email) => email.verified && !email.primary);
25}