'use client' import { useState, useEffect } from 'react'; import { useParams, useRouter } from 'next/navigation'; import authAxios from '@/utils/axios'; const EditAddress = () => { const { id } = useParams(); const router = useRouter(); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const [formData, setFormData] = useState({ first_name: '', last_name: '', company: '', address: '', apartment: '', city: '', country: '', zipcode: '', phone: '' }); useEffect(() => { const fetchAddress = async () => { try { const response = await authAxios.get(`/account/addresses/${id}/`); setFormData(response.data); } catch (err) { setError('Failed to fetch address details'); console.error(err); } }; if (id) { fetchAddress(); } }, [id]); const handleChange = (e) => { const { name, value } = e.target; setFormData(prev => ({ ...prev, [name]: value })); }; const handleSubmit = async (e) => { e.preventDefault(); setLoading(true); setError(''); try { await authAxios.put(`/account/addresses/${id}/`, formData); router.push('/accounts/profile/addresses'); } catch (err) { setError(err.response?.data?.message || 'Failed to update address'); } finally { setLoading(false); } }; return (

Edit Address

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