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/routes/workspace/layout.tsx

132 lines5,494 bytesCodeBlame
1import { CreditCard, KeyRound, LayoutGrid, Plug, Plus, Settings, Users } from "lucide-react";
2import { Outlet, data, useLocation, useRouteLoaderData } from "react-router";
3
4import type { Route } from "./+types/layout";
5import { page } from "../../lib/meta";
6import { Avatar, ButtonLink, Pill, TabLink } from "../../components/ui";
7import { identity } from "../../lib/services.server";
8import { getViewer, roleIn } from "../../lib/session.server";
9
10export function meta({ loaderData, params, ...args }: Route.MetaArgs) {
11 return page(args, { title: `${loaderData?.workspace.name ?? params.owner} · g1t` });
12}
13
14export async function loader({ params, context }: Route.LoaderArgs) {
15 const workspace = await identity.getWorkspace(params.owner);
16 if (!workspace) throw data(null, { status: 404 });
17 return { workspace, role: roleIn(getViewer(context), workspace.slug) };
18}
19
20/** A workspace's own pages, each with its title and what it is for. */
21const PAGES: Record<string, { title: string; about: string }> = {
22 settings: { title: "General", about: "The workspace's name, icon, address and description." },
23 people: {
24 title: "Members",
25 about: "Members create repositories, push, manage issues and merge pull requests. Owners also manage members, tokens, billing and integrations.",
26 },
27 tokens: {
28 title: "Access tokens",
29 about: "Tokens that belong to the workspace, not a person: for CI, integrations and agents that work for the whole team.",
30 },
31 usage: { title: "Usage", about: "What the workspace's agents cost, run by run, by repository, pull request and model." },
32 billing: { title: "Billing and plans", about: "Paid plans, agent credit, and every charge against it." },
33 webhooks: {
34 title: "Webhooks",
35 about: "Every repository's events, sent to your own addresses as they happen. A repository can also have its own, under its settings.",
36 },
37 secrets: {
38 title: "Secrets and variables",
39 about: "Shared with every repository, or the ones you link: read by workflows, deployments, or both. A repository's own row of the same key wins.",
40 },
41 integrations: {
42 title: "Integrations",
43 about: "Model providers, alerts and trackers. Secrets are sealed when saved, and agents never see them.",
44 },
45};
46
47export default function WorkspaceLayout({ loaderData }: Route.ComponentProps) {
48 const { workspace, role } = loaderData;
49 const base = `/${workspace.slug}`;
50 const signedIn = useRouteLoaderData("root")?.user != null;
51 // The sidebar finds the workspace's pages for someone signed in, so its
52 // pages need a title, not the workspace's whole header again.
53 const page = PAGES[useLocation().pathname.split("/-/")[1]?.split("/")[0] ?? ""];
54 if (signedIn && page) {
55 return (
56 <div className="mx-auto max-w-5xl px-4 py-10 sm:px-8">
57 <header className="mb-8 border-b border-line pb-6">
58 <h1 className="text-2xl font-semibold tracking-tight">{page.title}</h1>
59 <p className="mt-1.5 text-sm text-muted">{page.about}</p>
60 </header>
61 <Outlet />
62 </div>
63 );
64 }
65 return (
66 <>
67 {/* The workspace's own header band, under the site header. */}
68 <div className="border-b border-line bg-surface/60">
69 <div className="mx-auto max-w-6xl px-4 pt-8">
70 <div className="flex flex-wrap items-center gap-4">
71 <Avatar name={workspace.slug} image={workspace.avatar} size={52} square />
72 <div className="min-w-0 grow">
73 <div className="flex flex-wrap items-center gap-2.5">
74 <h1 className="truncate text-2xl font-semibold tracking-tight">
75 {workspace.name}
76 </h1>
77 {role && <Pill>{role}</Pill>}
78 </div>
79 <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p>
80 </div>
81 {role && (
82 <ButtonLink to={`/new?workspace=${workspace.slug}`}>
83 <Plus size={15} />
84 New project
85 </ButtonLink>
86 )}
87 </div>
88 {workspace.description && (
89 <p className="mt-4 max-w-2xl text-sm text-muted">{workspace.description}</p>
90 )}
91 {signedIn ? (
92 <div className="pb-8" />
93 ) : (
94 <nav className="mt-6 flex flex-wrap gap-x-6">
95 <TabLink to={base} end icon={<LayoutGrid size={15} />}>
96 Overview
97 </TabLink>
98 {role && (
99 <>
100 <TabLink
101 to={`${base}/-/people`}
102 icon={<Users size={15} />}
103 count={workspace.memberCount}
104 >
105 Members
106 </TabLink>
107 <TabLink to={`${base}/-/tokens`} icon={<KeyRound size={15} />}>
108 Access tokens
109 </TabLink>
110 <TabLink to={`${base}/-/billing`} icon={<CreditCard size={15} />}>
111 Billing
112 </TabLink>
113 <TabLink to={`${base}/-/integrations`} icon={<Plug size={15} />}>
114 Integrations
115 </TabLink>
116 </>
117 )}
118 {role === "owner" && (
119 <TabLink to={`${base}/-/settings`} icon={<Settings size={15} />}>
120 Settings
121 </TabLink>
122 )}
123 </nav>
124 )}
125 </div>
126 </div>
127 <div className="mx-auto max-w-6xl px-4 py-8">
128 <Outlet />
129 </div>
130 </>
131 );
132}