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"; |
| Workspace names and icons, and a component kit for every control | 5 | import { AvatarField } from "../../components/avatar-field"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 6 | import { Button, ErrorText, Field, Input } from "../../components/ui"; |
| Workspace names and icons, and a component kit for every control | 7 | import { readAvatarUpload } from "../../lib/avatar-upload"; |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 8 | import { identity } from "../../lib/services.server"; |
| 9 | import { assertSameOrigin, getViewer, requireUser, roleIn } from "../../lib/session.server"; | |
| 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} · 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 | // Owners only; to anyone else the page does not exist. | |
| 17 | if (roleIn(getViewer(context), params.owner) !== "owner") { | |
| 18 | throw data(null, { status: 404 }); | |
| 19 | } | |
| 20 | const workspace = await identity.getWorkspace(params.owner); | |
| 21 | if (!workspace) throw data(null, { status: 404 }); | |
| 22 | return { workspace }; | |
| 23 | } | |
| 24 | ||
| 25 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 26 | assertSameOrigin(request); | |
| 27 | const user = requireUser(context, request); | |
| 28 | const form = await request.formData(); | |
| Workspace names and icons, and a component kit for every control | 29 | const intent = form.get("intent"); |
| 30 | // The icon: identity checks the owner and the image's bytes again. | |
| 31 | if (intent === "avatar" || intent === "remove-avatar") { | |
| 32 | let image: string | null = null; | |
| 33 | if (intent === "avatar") { | |
| 34 | const upload = await readAvatarUpload(form); | |
| 35 | if ("error" in upload) return { avatarError: upload.error }; | |
| 36 | image = upload.image; | |
| 37 | } | |
| 38 | const result = await identity.setWorkspaceAvatar(user, params.owner, image); | |
| 39 | if (!result.ok) return { avatarError: result.error.message }; | |
| 40 | return { saved: "avatar" as const }; | |
| 41 | } | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 42 | const result = await identity.updateWorkspace(user, params.owner, { |
| 43 | name: String(form.get("displayName") ?? ""), | |
| 44 | description: String(form.get("description") ?? ""), | |
| 45 | }); | |
| 46 | if (!result.ok) return { error: result.error.message }; | |
| 47 | throw redirect(`/${result.value.slug}`); | |
| 48 | } | |
| 49 | ||
| 50 | export default function WorkspaceSettings({ loaderData, actionData }: Route.ComponentProps) { | |
| 51 | const { workspace } = loaderData; | |
| 52 | return ( | |
| Workspace names and icons, and a component kit for every control | 53 | <div className="max-w-lg space-y-10"> |
| 54 | <section> | |
| 55 | <h2 className="font-medium">Icon</h2> | |
| 56 | <div className="mt-4"> | |
| 57 | <AvatarField | |
| 58 | name={workspace.slug} | |
| 59 | image={workspace.avatar} | |
| 60 | square | |
| 61 | error={actionData && "avatarError" in actionData ? actionData.avatarError : undefined} | |
| 62 | about="Shown beside the workspace's name everywhere on g1t, and on its link previews. Without one, g1t draws its first letter." | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 63 | /> |
| Workspace names and icons, and a component kit for every control | 64 | </div> |
| 65 | </section> | |
| 66 | ||
| 67 | <section> | |
| 68 | <h2 className="font-medium">Workspace details</h2> | |
| 69 | <Form method="post" className="mt-5 space-y-4"> | |
| 70 | <Field | |
| 71 | label="Display name" | |
| 72 | hint="How people see the workspace: in the sidebar, at the top of its page and in link previews. Up to 80 characters; spaces and capitals are fine." | |
| 73 | > | |
| 74 | <Input name="displayName" maxLength={80} defaultValue={workspace.name} placeholder={workspace.slug} /> | |
| 75 | </Field> | |
| 76 | <Field label="Description" hint="One line, shown at the top of the workspace's page."> | |
| 77 | <Input name="description" maxLength={160} defaultValue={workspace.description ?? ""} /> | |
| 78 | </Field> | |
| 79 | <ErrorText>{actionData && "error" in actionData ? actionData.error : undefined}</ErrorText> | |
| 80 | <Button type="submit">Save</Button> | |
| 81 | </Form> | |
| 82 | </section> | |
| 83 | ||
| 84 | <section> | |
| 85 | <h2 className="font-medium">Address</h2> | |
| 86 | <p className="mt-3 font-mono text-sm text-fg">g1t.sh/{workspace.slug}</p> | |
| 87 | <p className="mt-1.5 text-xs text-faint"> | |
| 88 | The workspace's slug: lowercase, in every repository's address and every clone URL. It cannot be | |
| 89 | changed, so links and clones keep working. Change the display name instead. | |
| 90 | </p> | |
| 91 | </section> | |
| Agents as a team: lifecycle, merge queue, billing and a new shell | 92 | </div> |
| 93 | ); | |
| 94 | } |