'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useAuth } from '@/components/shared/AuthContext'; import { useNotification } from '@/components/shared/NotificationContext'; export default function SignupPage() { const router = useRouter(); const { showNotification } = useNotification(); const { signup, isAuthenticated } = useAuth(); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [error, setError] = useState(''); const [isLoading, setIsLoading] = useState(false); useEffect(() => { // Redirect if already authenticated if (isAuthenticated) { router.push('/dashboard'); } }, [isAuthenticated, router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); // Validate passwords match if (password !== confirmPassword) { setError('Passwords do not match'); return; } setIsLoading(true); try { await signup(name, email, password); // Show success notification showNotification('success', `Welcome to Finance Management, ${name}! Your account has been successfully created.`); // Redirect to login after successful signup with a slight delay to see the notification setTimeout(() => { router.push('/login?signup=success'); }, 1500); } catch (err: Error | unknown) { const errorMessage = err instanceof Error ? err.message : 'Signup failed'; setError(errorMessage); } finally { setIsLoading(false); } }; return (