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.
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 1 | import { ArrowLeft } from "lucide-react"; |
| 2 | import { useState } from "react"; | |
| 3 | import { Form, Link, data, redirect } from "react-router"; | |
| 4 | ||
| Merge branch 'worktree-agent-ad7c6d88d93adc817' | 5 | import { TEAM_VISIBILITY_SUMMARIES, mayCreateTeams, teamSlug } from "@g1t/contracts"; |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 6 | |
| 7 | import type { Route } from "./+types/team-new"; | |
| 8 | import { page } from "../../lib/meta"; | |
| 9 | import { ErrorText, Field, Input, SubmitButton } from "../../components/ui"; | |
| 10 | import { Textarea } from "../../components/ui/textarea"; | |
| 11 | import { RadioGroup, RadioOption } from "../../components/ui/radio-group"; | |
| 12 | import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../components/ui/select"; | |
| 13 | import { newTeamFromForm, parentChoices, teamPath } from "../../lib/teams"; | |
| 14 | import { identity } from "../../lib/services.server"; | |
| Previews build from any branch; Agent in place of Ask AI; pin from the sidebar | 15 | import { assertSameOrigin, requireUser, roleIn, unwrap } from "../../lib/session.server"; |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 16 | |
| 17 | /** The parent select's value for "no parent": Radix selects have no empty value. */ | |
| 18 | const NO_PARENT = "-"; | |
| 19 | ||
| 20 | export function meta({ params, ...args }: Route.MetaArgs) { | |
| 21 | return page(args, { title: `New team · ${params.owner} · g1t` }); | |
| 22 | } | |
| 23 | ||
| 24 | export async function loader({ params, context, request }: Route.LoaderArgs) { | |
| 25 | const viewer = requireUser(context, request); | |
| Merge branch 'worktree-agent-ad7c6d88d93adc817' | 26 | const role = roleIn(viewer, params.owner); |
| 27 | if (!role) throw data(null, { status: 404 }); | |
| 28 | const [teams, workspace] = await Promise.all([ | |
| 29 | identity.listTeams(viewer, params.owner).then(unwrap), | |
| 30 | identity.getWorkspace(params.owner).catch(() => null), | |
| 31 | ]); | |
| 32 | // Owners only, when the workspace says so: the Teams page says why. | |
| 33 | if (!mayCreateTeams(workspace?.teamCreation, role)) throw redirect(`/${params.owner}/-/teams`); | |
| Teams and CODEOWNERS, labels and milestones, dependency updates, the security suite, and a clearer top bar | 34 | // A new team goes under a team its creator may manage. |
| 35 | const parents = parentChoices(teams, null).filter((team) => team.can_manage); | |
| 36 | const wanted = new URL(request.url).searchParams.get("parent"); | |
| 37 | return { parents, parent: parents.some((team) => team.slug === wanted) ? wanted : null }; | |
| 38 | } | |
| 39 | ||
| 40 | export async function action({ request, params, context }: Route.ActionArgs) { | |
| 41 | assertSameOrigin(request); | |
| 42 | const user = requireUser(context, request); | |
| 43 | const form = await request.formData(); | |
| 44 | const team = newTeamFromForm(form); | |
| 45 | if (team.parent === NO_PARENT) team.parent = null; | |
| 46 | const made = await identity.createTeam(user, params.owner, team); | |
| 47 | if (!made.ok) return { error: made.error.message }; | |
| 48 | throw redirect(teamPath(made.value.workspace, made.value.slug)); | |
| 49 | } | |
| 50 | ||
| 51 | export default function NewTeam({ loaderData, actionData, params }: Route.ComponentProps) { | |
| 52 | const { parents, parent } = loaderData; | |
| 53 | const [name, setName] = useState(""); | |
| 54 | const [slug, setSlug] = useState(""); | |
| 55 | const [visibility, setVisibility] = useState("visible"); | |
| 56 | const handle = slug || teamSlug(name) || "team"; | |
| 57 | return ( | |
| 58 | <div className="max-w-2xl"> | |
| 59 | <Link to={`/${params.owner}/-/teams`} className="inline-flex items-center gap-1.5 text-sm text-muted hover:text-fg"> | |
| 60 | <ArrowLeft size={14} /> | |
| 61 | Teams | |
| 62 | </Link> | |
| 63 | <h1 className="mt-4 text-2xl font-semibold tracking-tight">New team</h1> | |
| 64 | <p className="mt-1.5 text-sm text-muted"> | |
| 65 | A group of {params.owner}'s members, given roles on repositories together. You become its maintainer. | |
| 66 | </p> | |
| 67 | ||
| 68 | <Form method="post" className="mt-8 space-y-6"> | |
| 69 | <Field label="Name"> | |
| 70 | <Input name="name" required maxLength={80} value={name} onChange={(event) => setName(event.target.value)} placeholder="Backend" /> | |
| 71 | </Field> | |
| 72 | <Field label="Slug" hint={`Mentioned as @${params.owner}/${handle}. Made from the name unless you choose one.`}> | |
| 73 | <Input | |
| 74 | name="slug" | |
| 75 | maxLength={60} | |
| 76 | value={slug} | |
| 77 | onChange={(event) => setSlug(event.target.value.toLowerCase())} | |
| 78 | placeholder={teamSlug(name) ?? "backend"} | |
| 79 | pattern="[a-z0-9]+(-[a-z0-9]+)*" | |
| 80 | /> | |
| 81 | </Field> | |
| 82 | <Field label="Description" hint="What the team does, in a line."> | |
| 83 | <Textarea name="description" rows={2} maxLength={280} /> | |
| 84 | </Field> | |
| 85 | ||
| 86 | <fieldset> | |
| 87 | <legend className="mb-2 text-sm font-medium text-muted">Visibility</legend> | |
| 88 | <RadioGroup name="visibility" value={visibility} onValueChange={setVisibility} className="space-y-3"> | |
| 89 | <RadioOption value="visible" label="Visible" description={TEAM_VISIBILITY_SUMMARIES.visible} /> | |
| 90 | <RadioOption value="secret" label="Secret" description={TEAM_VISIBILITY_SUMMARIES.secret} /> | |
| 91 | </RadioGroup> | |
| 92 | </fieldset> | |
| 93 | ||
| 94 | {visibility === "visible" && parents.length > 0 && ( | |
| 95 | <div> | |
| 96 | <span className="mb-1.5 block text-sm font-medium text-muted">Parent team</span> | |
| 97 | <Select name="parent" defaultValue={parent ?? NO_PARENT}> | |
| 98 | <SelectTrigger aria-label="Parent team" className="sm:max-w-72"> | |
| 99 | <SelectValue /> | |
| 100 | </SelectTrigger> | |
| 101 | <SelectContent> | |
| 102 | <SelectItem value={NO_PARENT}>No parent</SelectItem> | |
| 103 | {parents.map((team) => ( | |
| 104 | <SelectItem key={team.slug} value={team.slug}> | |
| 105 | {team.name} | |
| 106 | </SelectItem> | |
| 107 | ))} | |
| 108 | </SelectContent> | |
| 109 | </Select> | |
| 110 | <span className="mt-1.5 block text-xs text-faint"> | |
| 111 | A child team has its parent's roles on repositories, and hears what is asked of its parent. | |
| 112 | </span> | |
| 113 | </div> | |
| 114 | )} | |
| 115 | ||
| 116 | <Field label="Members" hint="Usernames of members of the workspace, separated by spaces or commas. You can add more later."> | |
| 117 | <Input name="members" placeholder="ana bo" /> | |
| 118 | </Field> | |
| 119 | ||
| 120 | <ErrorText>{actionData?.error ?? null}</ErrorText> | |
| 121 | <SubmitButton pending="Creating…">Create team</SubmitButton> | |
| 122 | </Form> | |
| 123 | </div> | |
| 124 | ); | |
| 125 | } |
This file's history is long; its oldest lines are credited to the oldest commit read.