'use client'; import IconLockDots from '@/components/icon/icon-lock-dots'; import IconMail from '@/components/icon/icon-mail'; import IconUser from '@/components/icon/icon-user'; import { useRouter } from 'next/navigation'; import React, { useState } from 'react'; import axios from 'axios'; const ComponentsAuthRegisterForm = () => { const router = useRouter(); const [form, setForm] = useState({ name: '', email: '', password: '', subscribe: false, }); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleChange = (e: React.ChangeEvent) => { const { name, value, type, checked } = e.target; setForm((prev) => ({ ...prev, [name]: type === 'checkbox' ? checked : value, })); }; const submitForm = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { // ✅ Send POST request via Axios const response = await axios.post('https://api.crawlerx.co/api/auth/signup', { name: form.name, email: form.email, password: form.password, subscribe: form.subscribe, }); alert('Signup successful!'); router.push('/login'); } catch (err: any) { // ✅ Axios error handling if (err.response) { // Server responded with status code out of 2xx setError(err.response.data.error || 'Signup failed'); } else if (err.request) { // Request was made but no response setError('No response from server'); } else { setError(err.message); } } finally { setLoading(false); } }; return (
{error &&

{error}

}
); }; export default ComponentsAuthRegisterForm;