'use client'; import { useState } from 'react'; import { signIn } from 'next-auth/react'; import Link from 'next/link'; import { authService, AuthService, RegisterRequest } from '@/services'; type UserType = 'USER' | 'AGENT'; interface ValidationError { field: string; errors: string[]; } export default function SignUpPage() { const [userType, setUserType] = useState('USER'); const [firstName, setFirstName] = useState(''); const [lastName, setLastName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [showPassword, setShowPassword] = useState(false); const [error, setError] = useState(''); const [fieldErrors, setFieldErrors] = useState([]); const [loading, setLoading] = useState(false); const [registrationSuccess, setRegistrationSuccess] = useState(false); const getFieldError = (fieldName: string): string | null => { const fieldError = fieldErrors.find((e) => e.field === fieldName); return fieldError ? fieldError.errors[0] : null; }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); setFieldErrors([]); try { const registerData: RegisterRequest = { firstName, lastName, email, password, role: userType, }; await authService.register(registerData); // Show success message - user must verify email before logging in setRegistrationSuccess(true); } catch (err) { // Get field errors const errors = AuthService.getFieldErrors(err); if (errors.length > 0) { setFieldErrors(errors); setError('Please fix the errors below'); } else { setError(AuthService.getErrorMessage(err)); } } finally { setLoading(false); } }; const handleSocialLogin = (provider: 'google' | 'facebook' | 'twitter') => { signIn(provider, { callbackUrl: '/' }); }; // Registration Success Message if (registrationSuccess) { return (

Check Your Email

We've sent a verification link to {email}. Please check your inbox and click the link to verify your account before logging in.

Go to Login

Didn't receive the email? Check your spam folder or contact support.

); } return ( <> {/* Sign Up Heading */}

Sign Up

Sign in or create an account to showcase your skills & expertise to millions of people starting their real estate journey today"

{/* User Type Toggle */}
{/* Sign Up Form */}
{error && (
{error}
)} {/* First Name & Last Name */}
setFirstName(e.target.value)} required className={`w-full px-6 py-6 bg-[#f0f5fc] rounded-[20px] text-[#00293d] text-sm font-light placeholder:text-[#00293d] focus:outline-none focus:ring-2 focus:ring-[#00293d]/20 transition-all ${ getFieldError('firstName') ? 'ring-2 ring-red-400' : '' }`} /> {getFieldError('firstName') && (

{getFieldError('firstName')}

)}
setLastName(e.target.value)} className={`w-full px-6 py-6 bg-[#f0f5fc] rounded-[20px] text-[#00293d] text-sm font-light placeholder:text-[#00293d] focus:outline-none focus:ring-2 focus:ring-[#00293d]/20 transition-all ${ getFieldError('lastName') ? 'ring-2 ring-red-400' : '' }`} /> {getFieldError('lastName') && (

{getFieldError('lastName')}

)}
{/* Email Input */}
setEmail(e.target.value)} required className={`w-full px-6 py-6 bg-[#f0f5fc] rounded-[20px] text-[#00293d] text-sm font-light placeholder:text-[#00293d] focus:outline-none focus:ring-2 focus:ring-[#00293d]/20 transition-all ${ getFieldError('email') ? 'ring-2 ring-red-400' : '' }`} /> {getFieldError('email') && (

{getFieldError('email')}

)}
{/* Password Input */}
setPassword(e.target.value)} required className={`w-full px-6 py-6 bg-[#f0f5fc] rounded-[20px] text-[#00293d] text-sm font-light placeholder:text-[#00293d] focus:outline-none focus:ring-2 focus:ring-[#00293d]/20 transition-all pr-14 ${ getFieldError('password') ? 'ring-2 ring-red-400' : '' }`} />
{getFieldError('password') && (

{getFieldError('password')}

)}

Min 8 chars, 1 uppercase, 1 lowercase, 1 number, 1 special character

{/* Sign Up Button */}
{/* Already Have Account */}
Already Have An Account ? Login
{/* Divider */}
Or
{/* Social Login Icons */}
{/* Google */} {/* X (Twitter) */} {/* Facebook */}
); }