import { useState } from 'react'; import { Button } from '../ui/button'; import { Card, CardContent } from '../ui/card'; import { Input } from '../ui/input'; import { Label } from '../ui/label'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter, } from '../ui/dialog'; import { signUp, sendVerificationEmail } from '../../lib/auth-client'; import { validateEmail } from '../../lib/validators'; import { useEffect } from 'react'; const logo = '/logo.png'; interface Props { onLogin: () => void; onVerify: () => void; } export function SignUpForm({ onLogin }: Props) { const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const [showVerifyDialog, setShowVerifyDialog] = useState(false); const [resendCooldown, setResendCooldown] = useState(0); const [resendLoading, setResendLoading] = useState(false); useEffect(() => { if (resendCooldown <= 0) return; const t = setTimeout(() => setResendCooldown(c => c - 1), 1000); return () => clearTimeout(t); }, [resendCooldown]); async function handleResend() { setResendLoading(true); await sendVerificationEmail({ email, callbackURL: window.location.origin }); setResendLoading(false); setResendCooldown(60); } async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); const trimmedName = name.trim(); const trimmedEmail = email.trim(); if (trimmedName.length < 2) { setError('Please enter your full name.'); return; } if (!validateEmail(trimmedEmail)) { setError('Please enter a valid email address.'); return; } if (password.length < 8) { setError('Password must be at least 8 characters'); return; } if (password !== confirm) { setError('Passwords do not match'); return; } setLoading(true); const res = await signUp.email({ name: trimmedName, email: trimmedEmail, password, callbackURL: window.location.origin, }); setLoading(false); if (res.error) { setError(res.error.message || 'Failed to create account'); } else { setShowVerifyDialog(true); } } return ( <>
Create your LabWise account.
Already have an account?{' '}