Skip to content

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

36 linesCodeBlameRaw
1import type { Route } from "./+types/invites";
2import { page } from "../../lib/meta";
3import { assertSameOrigin, requireUser } from "../../lib/session.server";
4import { InvitesSection } from "../../components/invites-section";
5import { inviteAction, loadBringInto, loadInvites } from "../../lib/invites.server";
6
7export function meta(args: Route.MetaArgs) {
8 return page(args, { title: "Invites to g1t · Settings · g1t" });
9}
10
11/** Invite a friend: your invites to g1t, how many are left, and who joined. */
12export async function loader({ request, context }: Route.LoaderArgs) {
13 const user = requireUser(context, request);
14 const url = new URL(request.url);
15 const [invites, bringInto] = await Promise.all([loadInvites(user), loadBringInto(user).catch(() => [])]);
16 // `?new` comes from the account menu's Invite a friend: the dialog opens at once.
17 return { invites, bringInto, origin: url.origin, openOnLoad: url.searchParams.has("new") };
18}
19
20export async function action({ request, context }: Route.ActionArgs) {
21 assertSameOrigin(request);
22 const user = requireUser(context, request);
23 // Making, revoking and resending invites (lib/invites.server.ts).
24 return inviteAction(user, await request.formData());
25}
26
27export default function InviteSettings({ loaderData }: Route.ComponentProps) {
28 return (
29 <InvitesSection
30 overview={loaderData.invites}
31 bringInto={loaderData.bringInto}
32 origin={loaderData.origin}
33 openOnLoad={loaderData.openOnLoad}
34 />
35 );
36}