peppa/apps/web/app/(app)/projects/new/page.tsx
Асель c03b679a1d PEP-38: all pages on the console components, globals.css removed
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 16:21:44 +05:00

87 lines
4.8 KiB
TypeScript
Raw Permalink 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, 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?:\/\//, "");
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>
<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="private" checked>Приватный — только те, кому выдан доступ</Choice>
<Choice name="visibility" value="public">Публичный — все, у кого есть доступ к Gitea</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>
);
}