'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import authAxios from '@/utils/axios'; const EditProfile = () => { const [profile, setProfile] = useState({ email: '', first_name: '', last_name: '', phone: '', accepts_marketing: '', birth_day: '', gender: '', profile_pic: null, }); const router = useRouter(); useEffect(() => { const fetchProfileData = async () => { const response = await authAxios.get('/account/profile'); console.log(response) setProfile(response.data); }; fetchProfileData(); }, []); const handleChange = (e) => { const { name, value } = e.target; setProfile((prevProfile) => ({ ...prevProfile, [name]: value, })); }; const handleCheckboxChange = (e) => { setProfile((prevProfile) => ({ ...prevProfile, accepts_marketing: e.target.checked ? 'Yes' : 'No', })); }; const handleSubmit = async (e) => { e.preventDefault(); console.log(profile); const formData = new FormData(); formData.append('email', profile.email); formData.append('first_name', profile.first_name); formData.append('last_name', profile.last_name); formData.append('phone', profile.phone); formData.append('accepts_marketing', profile.accepts_marketing); formData.append('birth_day', profile.birth_day); formData.append('gender', profile.gender); if (profile.profile_pic && profile.profile_pic instanceof File) { console.log('hello') formData.append('profile_pic', profile.profile_pic); } try { const response = await authAxios.patch('/account/profile-update/', formData, { headers: { 'Content-Type': 'multipart/form-data', }, }); console.log(response) if (response.status === 200) { router.push('/accounts/profile'); } else { alert('Failed to update profile'); } } catch (error) { console.error('Error updating profile:', error); alert('An error occurred while updating the profile.'); } }; return (