flagon-io/g1t

public

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t/apps/web/app/lib/invites.server.ts

32 lines1,411 bytesCodeBlame
1import type { Invite, InvitesOverview, User } from "@g1t/contracts";
2
3import { identity } from "./services.server";
4
5/** What the Invites section's forms answer. */
6export type InviteActionData = { inviteCreated?: Invite; inviteError?: string; inviteRevoked?: boolean } | null;
7
8/** A person's invites, or null when they cannot make any yet (email unconfirmed). */
9export async function loadInvites(user: User): Promise<InvitesOverview | null> {
10 if (!user.verified) return null;
11 return identity.listInvites(user).catch(() => null);
12}
13
14/** Handles the Invites section's intents; null for any other intent. */
15export async function inviteAction(user: User, form: FormData): Promise<InviteActionData | undefined> {
16 switch (form.get("intent")) {
17 case "create-invite": {
18 const email = String(form.get("email") ?? "").trim();
19 const workspace = String(form.get("charge") ?? "").trim();
20 const result = await identity.createInvite(user, {
21 email: email || null,
22 workspace: workspace && workspace !== "mine" ? workspace : null,
23 });
24 return result.ok ? { inviteCreated: result.value } : { inviteError: result.error.message };
25 }
26 case "revoke-invite": {
27 const result = await identity.revokeInvite(user, String(form.get("id") ?? ""));
28 return result.ok ? { inviteRevoked: true } : { inviteError: result.error.message };
29 }
30 }
31 return undefined;
32}