'use client' import { useState } from 'react'; import authAxios from '@/utils/axios'; import toast from 'react-hot-toast'; import { useRouter } from 'next/navigation'; const AddNewAddress = () => { const [formData, setFormData] = useState({ first_name: '', last_name: '', company: '', address: '', apartment: '', city: '', country: '', zipcode: '', phone: '' }); const router = useRouter(); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleChange = (e) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value })); }; const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(''); try { const response = await authAxios.post('/account/addresses/', formData); toast.success('Address added successfully') router.push('/accounts/profile/addresses') // Handle success (e.g., redirect or show success message) console.log('Address added successfully:', response.data); } catch (err) { setError(err.response?.data?.message || 'Failed to add address'); } finally { setLoading(false); } }; return (

Add a new address

{error &&
{error}
}
); }; export default AddNewAddress;