"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import * as React from "react"; import { Button, Card, CardHint, CardTitle, ErrorState, Field } from "@agy/ui"; import { ApiError } from "@/lib/api"; import { useSession } from "@/lib/session"; /** * Where to land after signing up. Only same-origin paths are honoured, so a * crafted `?next=https://evil.example` cannot turn the form into an open * redirect. */ function nextDestination(fallback: string): string { if (typeof window === "undefined") return fallback; const next = new URLSearchParams(window.location.search).get("next"); return next && next.startsWith("/") && !next.startsWith("//") ? next : fallback; } export default function SignupPage() { const router = useRouter(); const { signup } = useSession(); const [name, setName] = React.useState(""); const [email, setEmail] = React.useState(""); const [password, setPassword] = React.useState(""); const [error, setError] = React.useState(null); const [submitting, setSubmitting] = React.useState(false); // Read once on mount so the "already registered?" link carries the invite token. const [nextPath, setNextPath] = React.useState(null); React.useEffect(() => { const next = new URLSearchParams(window.location.search).get("next"); setNextPath(next && next.startsWith("/") && !next.startsWith("//") ? next : null); }, []); const onSubmit = async (event: React.FormEvent) => { event.preventDefault(); setError(null); setSubmitting(true); try { await signup(email, password, name); router.replace(nextDestination("/onboarding")); } catch (err) { setError(err instanceof ApiError ? err.message : "ثبت‌نام ناموفق بود."); } finally { setSubmitting(false); } }; return (
ساخت حساب پس از ثبت‌نام، اولین سازمان خود را می‌سازید.
setName(e.target.value)} placeholder="نام شما" /> setEmail(e.target.value)} /> setPassword(e.target.value)} /> {error && }

قبلاً ثبت‌نام کرده‌اید؟{" "} ورود

); }