g1t/apps/web/app/routes/repo/settings.tsx
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.
| Projects: what a workspace builds and runs, first on every page | 1 | import { Box, Code2, GitBranch } from "lucide-react"; |
| 2 | import { Form, Link, data, useNavigation } from "react-router"; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 3 | |
| 4 | import type { Route } from "./+types/settings"; | |
| Social cards for every page: og.g1t.sh | 5 | import { page } from "../../lib/meta"; |
| Project settings move into the sidebar, grouped, with a heading per page | 6 | import { RepoSettingsHeading } from "../../components/repo-settings-heading"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 7 | import { Button, ErrorText, Field, Input, TimeAgo } from "../../components/ui"; |
| Projects: what a workspace builds and runs, first on every page | 8 | import { projects } from "../../lib/services.server"; |
| 9 | import { assertSameOrigin, getViewer, requireUser, roleIn, unwrap } from "../../lib/session.server"; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 10 | |
| Social cards for every page: og.g1t.sh | 11 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 12 | return page(args, { title: `Settings · ${params.owner}/${params.repo} · g1t` }); | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 13 | } |
| 14 | ||
| 15 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 16 | const viewer = getViewer(context); | |
| 17 | // Members only; to anyone else the page does not exist. | |
| 18 | if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 }); | |
| Projects: what a workspace builds and runs, first on every page | 19 | return { project: unwrap(await projects.get(params.owner, params.repo, viewer)) }; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 20 | } |
| 21 | ||
| 22 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 23 | assertSameOrigin(request); | |
| 24 | const user = requireUser(context, request); | |
| 25 | const form = await request.formData(); | |
| Projects: what a workspace builds and runs, first on every page | 26 | const saved = await projects.update(user, params.owner, params.repo, { |
| 27 | name: String(form.get("name") ?? ""), | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 28 | description: String(form.get("description") ?? ""), |
| Projects: what a workspace builds and runs, first on every page | 29 | rootDir: String(form.get("rootDir") ?? ""), |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 30 | }); |
| Projects: what a workspace builds and runs, first on every page | 31 | return saved.ok ? { saved: true as const } : { error: saved.error.message }; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 32 | } |
| 33 | ||
| Projects: what a workspace builds and runs, first on every page | 34 | export default function ProjectSettings({ loaderData, actionData, params }: Route.ComponentProps) { |
| 35 | const { project } = loaderData; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 36 | const saving = useNavigation().state === "submitting"; |
| Projects: what a workspace builds and runs, first on every page | 37 | const base = `/${params.owner}/${params.repo}`; |
| 38 | const source = project.source.kind === "hosted" ? project.source : null; | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 39 | return ( |
| Projects: what a workspace builds and runs, first on every page | 40 | <div className="max-w-4xl"> |
| Project settings move into the sidebar, grouped, with a heading per page | 41 | <RepoSettingsHeading base={base} /> |
| Projects: what a workspace builds and runs, first on every page | 42 | <Form method="post" className="space-y-8"> |
| 43 | <section className="space-y-4"> | |
| 44 | <h2 className="flex items-center gap-2 text-sm font-medium"> | |
| 45 | <Box size={15} className="text-accent" /> | |
| 46 | Project | |
| 47 | </h2> | |
| 48 | <div className="grid gap-4 md:grid-cols-2"> | |
| 49 | <Field label="Name" hint={`Its address stays g1t.sh/${project.workspace}/${project.slug}.`}> | |
| 50 | <Input name="name" defaultValue={project.name} required maxLength={100} /> | |
| 51 | </Field> | |
| 52 | <Field label="Description"> | |
| 53 | <Input name="description" defaultValue={project.description ?? ""} maxLength={200} placeholder="What it is, in a line" /> | |
| 54 | </Field> | |
| 55 | </div> | |
| 56 | </section> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 57 | |
| Projects: what a workspace builds and runs, first on every page | 58 | <section className="space-y-4"> |
| 59 | <h2 className="flex items-center gap-2 text-sm font-medium"> | |
| 60 | <Code2 size={15} className="text-accent" /> | |
| 61 | Source | |
| 62 | </h2> | |
| 63 | {source && ( | |
| 64 | <div className="rounded-xl border border-line bg-surface p-4 text-sm"> | |
| 65 | <div className="flex flex-wrap items-center justify-between gap-3"> | |
| 66 | <div> | |
| 67 | <Link to={`${base}/code`} className="font-mono hover:text-accent"> | |
| 68 | {source.repo.namespace}/{source.repo.name} | |
| 69 | </Link> | |
| 70 | <p className="mt-0.5 text-xs text-muted"> | |
| 71 | Hosted on g1t · <GitBranch size={11} className="inline" /> {source.defaultBranch} | |
| 72 | </p> | |
| 73 | </div> | |
| 74 | <Link to={`${base}/settings/repository`} className="text-xs text-muted hover:text-fg"> | |
| 75 | Repository settings | |
| 76 | </Link> | |
| 77 | </div> | |
| 78 | <p className="mt-3 text-xs text-faint"> | |
| 79 | Mirroring a repository from GitHub, GitLab or Bitbucket as a project's source is coming next. | |
| 80 | </p> | |
| 81 | </div> | |
| 82 | )} | |
| 83 | <Field | |
| 84 | label="Root directory" | |
| 85 | hint="Where in the repository this project lives, such as apps/web. Builds run there. Empty for the whole repository." | |
| Webhooks: every event, to your own addresses, signed and retried | 86 | > |
| Projects: what a workspace builds and runs, first on every page | 87 | <Input name="rootDir" defaultValue={source?.rootDir ?? ""} placeholder="apps/web" className="font-mono" /> |
| 88 | </Field> | |
| 89 | </section> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 90 | |
| Projects: what a workspace builds and runs, first on every page | 91 | <div className="flex items-center gap-3"> |
| Webhooks: every event, to your own addresses, signed and retried | 92 | <Button type="submit" disabled={saving}> |
| Projects: what a workspace builds and runs, first on every page | 93 | Save |
| Webhooks: every event, to your own addresses, signed and retried | 94 | </Button> |
| Projects: what a workspace builds and runs, first on every page | 95 | {actionData && "saved" in actionData && <span className="text-sm text-accent">Saved.</span>} |
| 96 | <span className="ml-auto text-xs text-faint"> | |
| 97 | Created by {project.createdBy} <TimeAgo at={project.createdAt} /> | |
| 98 | </span> | |
| Webhooks: every event, to your own addresses, signed and retried | 99 | </div> |
| Projects: what a workspace builds and runs, first on every page | 100 | <ErrorText>{actionData && "error" in actionData ? actionData.error : null}</ErrorText> |
| Webhooks: every event, to your own addresses, signed and retried | 101 | </Form> |
| Projects: what a workspace builds and runs, first on every page | 102 | </div> |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 103 | ); |
| 104 | } |