wacrm/src/app/(auth)/signup/page.tsx
Arnas Donauskas 4bb157c705
Merge remote-tracking branch 'origin/main' into chore/hostinger-accent-palette
# Conflicts:
#	src/app/icon.tsx
#	src/components/docs/shell.tsx
#	src/components/landing/footer.tsx
#	src/components/landing/nav.tsx
2026-05-06 13:35:46 +03:00

199 lines
6.7 KiB
TypeScript

"use client";
import { useState } from "react";
import Link from "next/link";
import { createClient } from "@/lib/supabase/client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { MessageSquare, CheckCircle } from "lucide-react";
export default function SignupPage() {
const [fullName, setFullName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [confirmPassword, setConfirmPassword] = useState("");
const [error, setError] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [success, setSuccess] = useState(false);
const supabase = createClient();
const handleSignup = async (e: React.FormEvent) => {
e.preventDefault();
setError(null);
if (password !== confirmPassword) {
setError("Passwords do not match");
return;
}
if (password.length < 6) {
setError("Password must be at least 6 characters");
return;
}
setLoading(true);
const { error } = await supabase.auth.signUp({
email,
password,
options: {
data: {
full_name: fullName,
},
},
});
if (error) {
setError(error.message);
setLoading(false);
return;
}
setSuccess(true);
setLoading(false);
};
if (success) {
return (
<div className="flex min-h-screen items-center justify-center bg-slate-950 px-4">
<Card className="w-full max-w-md border-slate-800 bg-slate-900">
<CardHeader className="items-center text-center">
<div className="mb-2 flex h-12 w-12 items-center justify-center rounded-xl bg-violet-500/10">
<CheckCircle className="h-6 w-6 text-violet-500" />
</div>
<CardTitle className="text-xl text-white">
Check your email
</CardTitle>
<CardDescription className="text-slate-400">
We&apos;ve sent a confirmation link to{" "}
<span className="text-white">{email}</span>. Please check your
inbox and click the link to verify your account.
</CardDescription>
</CardHeader>
<CardContent>
<Link href="/login">
<Button
variant="outline"
className="w-full border-slate-700 text-slate-300 hover:bg-slate-800 hover:text-white"
>
Back to sign in
</Button>
</Link>
</CardContent>
</Card>
</div>
);
}
return (
<div className="flex min-h-screen items-center justify-center bg-slate-950 px-4">
<Card className="w-full max-w-md border-slate-800 bg-slate-900">
<CardHeader className="items-center text-center">
<div className="mb-2 flex h-12 w-12 items-center justify-center rounded-xl bg-violet-500/10">
<MessageSquare className="h-6 w-6 text-violet-500" />
</div>
<CardTitle className="text-xl text-white">Create account</CardTitle>
<CardDescription className="text-slate-400">
Get started with CRM Template for WhatsApp
</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={handleSignup} className="flex flex-col gap-4">
{error && (
<div className="rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-3 text-sm text-red-400">
{error}
</div>
)}
<div className="flex flex-col gap-2">
<Label htmlFor="fullName" className="text-slate-300">
Full name
</Label>
<Input
id="fullName"
type="text"
placeholder="John Doe"
value={fullName}
onChange={(e) => setFullName(e.target.value)}
required
className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-violet-500 focus-visible:ring-violet-500/20"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="email" className="text-slate-300">
Email
</Label>
<Input
id="email"
type="email"
placeholder="you@example.com"
value={email}
onChange={(e) => setEmail(e.target.value)}
required
className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-violet-500 focus-visible:ring-violet-500/20"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="password" className="text-slate-300">
Password
</Label>
<Input
id="password"
type="password"
placeholder="At least 6 characters"
value={password}
onChange={(e) => setPassword(e.target.value)}
required
className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-violet-500 focus-visible:ring-violet-500/20"
/>
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="confirmPassword" className="text-slate-300">
Confirm password
</Label>
<Input
id="confirmPassword"
type="password"
placeholder="Repeat your password"
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)}
required
className="border-slate-700 bg-slate-800 text-white placeholder:text-slate-500 focus-visible:border-violet-500 focus-visible:ring-violet-500/20"
/>
</div>
<Button
type="submit"
disabled={loading}
className="mt-2 h-10 w-full bg-violet-600 text-white hover:bg-violet-500 disabled:opacity-50"
>
{loading ? "Creating account..." : "Create account"}
</Button>
</form>
<p className="mt-6 text-center text-sm text-slate-400">
Already have an account?{" "}
<Link
href="/login"
className="text-violet-500 hover:text-violet-400"
>
Sign in
</Link>
</p>
</CardContent>
</Card>
</div>
);
}