'use client'; import { useState } from 'react'; import { Box, TextField, Button, Typography, Paper, InputAdornment, IconButton, Alert, CircularProgress, Link as MuiLink, Checkbox, FormControlLabel, } from '@mui/material'; import { Visibility, VisibilityOff } from '@mui/icons-material'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { motion } from 'framer-motion'; import * as z from 'zod'; import { useAuth } from '@/lib/auth/AuthContext'; import Link from 'next/link'; const registerSchema = z.object({ name: z.string().min(2, 'Name must be at least 2 characters'), email: z.string().email('Invalid email address'), password: z.string() .min(8, 'Password must be at least 8 characters') .regex(/[A-Z]/, 'Password must contain at least one uppercase letter') .regex(/[a-z]/, 'Password must contain at least one lowercase letter') .regex(/[0-9]/, 'Password must contain at least one number'), confirmPassword: z.string(), agreeToTerms: z.boolean().refine(val => val === true, { message: 'You must agree to the terms and conditions', }), }).refine((data) => data.password === data.confirmPassword, { message: 'Passwords do not match', path: ['confirmPassword'], }); type RegisterFormData = z.infer; export default function RegisterPage() { const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(false); const { register: registerUser } = useAuth(); const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(registerSchema), }); const onSubmit = async (data: RegisterFormData) => { setError(null); setIsLoading(true); try { await registerUser({ name: data.name, email: data.email, password: data.password, }); // Navigation to onboarding is handled in the register function } catch (err: any) { setError(err.message || 'Failed to register. Please try again.'); } finally { setIsLoading(false); } }; return ( Create Account ✨ Start your journey to organized parenting {error && ( {error} )} setShowPassword(!showPassword)} edge="end" disabled={isLoading} > {showPassword ? : } ), }} /> setShowConfirmPassword(!showConfirmPassword)} edge="end" disabled={isLoading} > {showConfirmPassword ? : } ), }} /> } label={ I agree to the{' '} Terms of Service {' '} and{' '} Privacy Policy } sx={{ mt: 2 }} /> {errors.agreeToTerms && ( {errors.agreeToTerms.message} )} Already have an account?{' '} Sign in ); }