| 46 | }; |
| 47 | |
| 48 | const validateForm = (): boolean => { |
| 49 | const errors: Record<string, string> = {}; |
| 50 | |
| 51 | if (!formData.username.trim()) { |
| 52 | errors.username = 'Username is required'; |
| 53 | } |
| 54 | |
| 55 | if (!formData.password) { |
| 56 | errors.password = 'Password is required'; |
| 57 | } else if (formData.password.length < 6) { |
| 58 | errors.password = 'Password must be at least 6 characters long'; |
| 59 | } |
| 60 | |
| 61 | if (!formData.confirmPassword) { |
| 62 | errors.confirmPassword = 'Please confirm your password'; |
| 63 | } else if (formData.password !== formData.confirmPassword) { |
| 64 | errors.confirmPassword = 'Passwords do not match'; |
| 65 | } |
| 66 | |
| 67 | setFormErrors(errors); |
| 68 | return Object.keys(errors).length === 0; |
| 69 | }; |
| 70 | |
| 71 | const handleSubmit = async (e: React.FormEvent) => { |
| 72 | e.preventDefault(); |