peppa/apps/web/app/(app)/projects/new/page.tsx
Асель efeac4500b PEP-64: public by default, change visibility (runner, web, MCP, CLI), tests
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 03:39:17 +05:00

101 lines
5.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { giteaForUser, isLocalUser, type GiteaOrg } from "@peppa/core";
import { loadEnv } from "@peppa/shared";
import { Flash, PageHeader } from "@/components/common";
import { Hidden } from "@/components/cards";
import { Button } from "@/components/ui/button";
import { Input, Label, NativeSelect } from "@/components/ui/input";
import { Workspace } from "@/components/Workspace";
import { requireUser } from "@/lib/auth";
import { db } from "@/lib/db";
import { createProjectAction } from "../../actions";
function Choice({ name, value, checked, children }: { name: string; value: string; checked?: boolean; children: React.ReactNode }) {
return (
<label className="flex cursor-pointer items-start gap-2.5 rounded-md border bg-background/40 px-3 py-2 text-sm has-checked:border-primary/60 has-checked:bg-primary/5">
<input type="radio" name={name} value={value} defaultChecked={checked} className="mt-1 accent-primary" />
<span>{children}</span>
</label>
);
}
export default async function NewProject({ searchParams }: { searchParams: Promise<{ error?: string }> }) {
const user = await requireUser();
const { error } = await searchParams;
let orgs: GiteaOrg[] = [];
let giteaError: string | undefined;
const giteaUrl = loadEnv().GITEA_URL.replace(/^https?:\/\//, "");
// PEP-68: a local user has no Gitea account — the repo is created in peppa-bot's namespace.
const local = isLocalUser(user);
const botLogin = process.env.GITEA_BOT_USER ?? "peppa-bot";
if (!local) {
try {
orgs = await (await giteaForUser(db, user)).orgsWithRepoCreate(user.login);
} catch (e) {
giteaError = (e as Error).message;
}
}
return (
<Workspace>
<div className="max-w-xl">
<PageHeader title="Новый проект" />
<Flash error={error ?? giteaError} />
<form action={createProjectAction} className="flex flex-col gap-4">
<Hidden fields={{ back: "/projects/new" }} />
<Label>
Название
<Input name="name" required placeholder="Платёжный сервис" />
</Label>
<div className="flex gap-3">
<Label className="flex-1">
Репозиторий (slug)
<Input name="slug" required pattern="[a-z0-9][a-z0-9-]*" placeholder="payments" className="font-mono" />
</Label>
<Label className="w-32">
Ключ стори
<Input name="key" required pattern="[A-Za-z][A-Za-z0-9]{1,9}" placeholder="PAY" className="font-mono uppercase" />
</Label>
</div>
{local ? (
<p className="m-0 rounded-md border bg-muted/40 px-3 py-2 text-sm text-muted-foreground">
У вас нет аккаунта Gitea — репозиторий будет <span className="font-mono">{giteaUrl}/{botLogin}/&lt;slug&gt;</span>. Доступ к коду — только через
Пеппу (агенты, PR, проверки); соавтором в Gitea вас добавить нельзя.
</p>
) : (
<>
<Label>
Пространство в Gitea
<NativeSelect name="owner" defaultValue={user.login}>
<option value={user.login}>{user.login} — личное</option>
{orgs.map((o) => (
<option key={o.id} value={o.username}>{o.username} — организация</option>
))}
</NativeSelect>
</Label>
<p className="m-0 text-sm text-muted-foreground">
Репозиторий будет <span className="font-mono">{giteaUrl}/&lt;пространство&gt;/&lt;slug&gt;</span>. В личном пространстве приватный репозиторий видите
только вы, <span className="font-mono">peppa-bot</span> и участники проекта; в организации — ещё её участники с доступом к репозиториям.
{orgs.length === 0 && " Организаций, где вы можете создавать репозитории, нет."}
</p>
</>
)}
<fieldset className="m-0 flex flex-col gap-2 border-0 p-0">
<legend className="mb-2 text-sm font-medium">Видимость</legend>
<Choice name="visibility" value="public" checked>Публичный — все, у кого есть доступ к Gitea</Choice>
<Choice name="visibility" value="private">Приватный — только те, кому выдан доступ</Choice>
</fieldset>
<fieldset className="m-0 flex flex-col gap-2 border-0 p-0">
<legend className="mb-2 text-sm font-medium">Репозиторий</legend>
<Choice name="mode" value="new" checked>Создать новый</Choice>
<Choice name="mode" value="existing">Подключить существующий (нужны права админа; видимость не меняется)</Choice>
</fieldset>
<p className="m-0 text-sm text-muted-foreground">
Пеппа добавит <span className="font-mono">peppa-bot</span> соавтором, положит AGENTS.md, .mcp.json и .peppa/project.json из шаблона и запустит
openspec init. Занимает до ~15 секунд.
</p>
<Button variant="default" className="self-start">Создать проект</Button>
</form>
</div>
</Workspace>
);
}