// app/account/profile/ProfileForm.tsx 'use client'; import { useState } from 'react'; interface Customer { id: string; email: string; first_name?: string; last_name?: string; phone?: string; } interface ProfileFormProps { customer: Customer; onCancel: () => void; } export default function ProfileForm({ customer, onCancel }: ProfileFormProps) { const [firstName, setFirstName] = useState(customer.first_name || ''); const [lastName, setLastName] = useState(customer.last_name || ''); const [phone, setPhone] = useState(customer.phone || ''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(null); try { const res = await fetch(`${process.env.NEXT_PUBLIC_STORE_URL}/store/customers/me`, { method: 'PUT', headers: { 'Content-Type': 'application/json', }, credentials: 'include', body: JSON.stringify({ first_name: firstName, last_name: lastName, phone: phone, }), }); if (!res.ok) { // handle error const errorData = await res.json(); setError(errorData?.message || 'Failed to update profile'); } else { // success - you might want to refresh the page or re-fetch data // For simplicity, let's just call onCancel to go back onCancel(); } } catch (err: any) { console.error(err); setError('An error occurred while updating.'); } finally { setLoading(false); } }; return (
{error &&

{error}

}
); }