g1t/apps/web/app/routes/workspace/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.
| Agents as a team: lifecycle, merge queue, billing and a new shell | 1 | import { Form, data, redirect } from "react-router"; |
| 2 | ||
| 3 | import type { Route } from "./+types/settings"; | |
| Social cards for every page: og.g1t.sh | 4 | import { page } from "../../lib/meta"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 5 | import { Button, ErrorText, Field, Input } from "../../components/ui"; |
| 6 | import { identity } from "../../lib/services.server"; | |
| 7 | import { assertSameOrigin, getViewer, requireUser, roleIn } from "../../lib/session.server"; | |
| 8 | ||
| Social cards for every page: og.g1t.sh | 9 | export function meta({ params, ...args }: Route.MetaArgs) { |
| 10 | return page(args, { title: `Settings · ${params.owner} · g1t` }); | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 11 | } |
| 12 | ||
| 13 | export async function loader({ params, context }: Route.LoaderArgs) { | |
| 14 | // Owners only; to anyone else the page does not exist. | |
| 15 | if (roleIn(getViewer(context), params.owner) !== "owner") { | |
| 16 | throw data(null, { status: 404 }); | |
| 17 | } | |
| 18 | const workspace = await identity.getWorkspace(params.owner); | |
| 19 | if (!workspace) throw data(null, { status: 404 }); | |
| 20 | return { workspace }; | |
| 21 | } | |
| 22 | ||
| 23 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 24 | assertSameOrigin(request); | |
| 25 | const user = requireUser(context, request); | |
| 26 | const form = await request.formData(); | |
| 27 | const result = await identity.updateWorkspace(user, params.owner, { | |
| 28 | name: String(form.get("displayName") ?? ""), | |
| 29 | description: String(form.get("description") ?? ""), | |
| 30 | }); | |
| 31 | if (!result.ok) return { error: result.error.message }; | |
| 32 | throw redirect(`/${result.value.slug}`); | |
| 33 | } | |
| 34 | ||
| 35 | export default function WorkspaceSettings({ loaderData, actionData }: Route.ComponentProps) { | |
| 36 | const { workspace } = loaderData; | |
| 37 | return ( | |
| 38 | <div className="max-w-lg"> | |
| 39 | <h2 className="font-medium">Workspace details</h2> | |
| 40 | <Form method="post" className="mt-5 space-y-4"> | |
| 41 | <Field label="Display name"> | |
| 42 | <Input name="displayName" maxLength={80} defaultValue={workspace.name} /> | |
| 43 | </Field> | |
| 44 | <Field label="Description" hint="One line, shown at the top of the workspace's page."> | |
| 45 | <Input | |
| 46 | name="description" | |
| 47 | maxLength={160} | |
| 48 | defaultValue={workspace.description ?? ""} | |
| 49 | /> | |
| 50 | </Field> | |
| 51 | <Field | |
| 52 | label="Name in URLs" | |
| 53 | hint="This cannot be changed: repository addresses and clones depend on it." | |
| 54 | > | |
| 55 | <p className="font-mono text-sm text-muted">g1t.sh/{workspace.slug}</p> | |
| 56 | </Field> | |
| 57 | <ErrorText>{actionData?.error}</ErrorText> | |
| 58 | <Button type="submit">Save</Button> | |
| 59 | </Form> | |
| 60 | </div> | |
| 61 | ); | |
| 62 | } |