peppa/apps/web/components/SubscriptionSetup.tsx
2026-11-15 15:56:55 +05:00

92 lines
5.7 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 { ExternalLink } from "lucide-react";
import type { OwnLogin } from "@peppa/runner";
import { cancelOwnLoginAction, connectOwnSubscriptionAction, finishOwnClaudeLoginAction } from "@/app/(app)/actions";
import { Hidden } from "@/components/cards";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { getT } from "@/lib/i18n";
const step = "flex gap-2.5";
const num = "grid size-5.5 shrink-0 place-items-center rounded-full bg-primary/15 text-xs font-semibold text-primary";
/**
* PEP-82: connecting the owner's own subscription without a terminal, in plain steps, right on
* the project page — «Подключить Claude» / «Подключить ChatGPT», then the link and the code.
*/
export async function SubscriptionSetup({ projectId, back, logins }: { projectId: number; back: string; logins: OwnLogin[] }) {
const t = await getT();
if (logins.length) {
return (
<div className="mb-4 flex flex-col gap-4">
{logins.map((l) => (
<section key={l.subscriptionId} className="flex flex-col gap-3 rounded-lg border border-primary/40 bg-card px-4 py-4 text-sm" data-own-login={l.subscriptionId} aria-label={t("Подключение {provider}", { provider: l.provider === "claude" ? "Claude" : "ChatGPT" })}>
<h2 className="m-0 text-base font-semibold">{l.provider === "claude" ? t("Подключаем Claude — осталось три шага") : t("Подключаем ChatGPT — осталось два шага")}</h2>
<div className={step}>
<span className={num}>1</span>
<div className="flex flex-col items-start gap-1.5">
<span>{l.provider === "claude" ? t("Откройте страницу входа и войдите в свой аккаунт Claude, затем нажмите «Authorize».") : t("Откройте страницу входа и войдите в свой аккаунт ChatGPT.")}</span>
<Button asChild size="sm" variant="default">
<a href={l.url} target="_blank" rel="noreferrer">
{t("Открыть страницу входа")} <ExternalLink />
</a>
</Button>
</div>
</div>
{l.provider === "claude" ? (
<>
<div className={step}>
<span className={num}>2</span>
<span>{t("Claude покажет длинный код — нажмите «Copy code».")}</span>
</div>
<div className={step}>
<span className={num}>3</span>
<form action={finishOwnClaudeLoginAction} className="flex min-w-0 flex-1 flex-wrap items-center gap-2">
<Hidden fields={{ projectId, subscriptionId: l.subscriptionId, back }} />
<Input name="code" required autoComplete="off" placeholder={t("Вставьте код сюда")} aria-label={t("Код от Claude")} className="h-9 min-w-48 flex-1 font-mono" />
<Button variant="default">{t("Готово")}</Button>
</form>
</div>
</>
) : (
<div className={step}>
<span className={num}>2</span>
<div className="flex flex-col items-start gap-1.5">
<span>
{t("На той странице введите код")} <span className="rounded bg-muted px-2 py-0.5 font-mono text-base tracking-wider">{l.code}</span> {t("и подтвердите вход.")}
</span>
<Button asChild size="sm" variant="default">
<a href={back}>{t("Я вошёл — проверить")}</a>
</Button>
</div>
</div>
)}
<form action={cancelOwnLoginAction}>
<Hidden fields={{ projectId, subscriptionId: l.subscriptionId, back }} />
<Button size="xs" variant="ghost" className="text-muted-foreground">{t("Отменить и начать заново")}</Button>
</form>
</section>
))}
</div>
);
}
return (
<section className="mb-4 flex flex-col gap-3 rounded-lg border border-warn/50 bg-warn/10 px-4 py-4 text-sm" aria-label={t("Подключение подписки")}>
<h2 className="m-0 text-base font-semibold">{t("Подключите подписку — и агенты начнут работать")}</h2>
<p className="m-0">
{t("Агенты пишут код на вашей подписке Claude или ChatGPT — подойдёт обычная платная (Claude Pro или Max, ChatGPT Plus или Pro). Это одна минута: вы входите в свой аккаунт, как на любом сайте. Пароль Peppa FACTORY не видит.")}
</p>
<div className="flex flex-wrap gap-2">
<form action={connectOwnSubscriptionAction}>
<Hidden fields={{ projectId, kind: "claude_login", back }} />
<Button variant="default" size="lg">{t("Подключить Claude")}</Button>
</form>
<form action={connectOwnSubscriptionAction}>
<Hidden fields={{ projectId, kind: "codex_login", back }} />
<Button variant="outline" size="lg">{t("Подключить ChatGPT")}</Button>
</form>
</div>
<p className="m-0 text-xs text-muted-foreground">{t("Нет подписки? Оформите её на claude.ai или chatgpt.com и вернитесь сюда. Другие способы (готовый токен, ключ API) — в «⋯ Настройки проекта → Подписки».")}</p>
</section>
);
}