import Area from '@components/common/Area.js'; import { EmailField } from '@components/common/form/EmailField.js'; import { Form, useFormContext } from '@components/common/form/Form.js'; import { InputField } from '@components/common/form/InputField.js'; import { Button } from '@components/common/ui/Button.js'; import { toast } from '@components/common/ui/Sonner.js'; import { useCustomer, useCustomerDispatch } from '@components/frontStore/customer/CustomerContext.jsx'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { Mail, Pencil, User } from 'lucide-react'; import React from 'react'; interface AccountInfoProps { title?: string; showLogout?: boolean; } /** * Save + Cancel on one row, inside the
so the submit button drives the * form's own onSubmit. Reads `isSubmitting` from the form context to keep the * Save spinner. Cancel uses the destructive variant. */ function AccountInfoActions({ onCancel }: { onCancel: () => void }) { const { formState: { isSubmitting } } = useFormContext(); return (
); } export default function AccountInfo({ title, showLogout }: AccountInfoProps) { const { customer: account } = useCustomer(); const { logout, updateProfile } = useCustomerDispatch(); const [isEditing, setIsEditing] = React.useState(false); return (
{(title || showLogout) && (
{title &&

{title}

} {showLogout && ( { e.preventDefault(); try { await logout(); window.location.href = '/'; } catch (error) { toast.error(error.message); } }} > {_('Logout')} )}
)} {isEditing ? (
{ try { await updateProfile({ full_name: data.full_name, email: data.email }); toast.success(_('Your profile has been updated')); setIsEditing(false); } catch (error) { toast.error(error.message); } }} >
} name="full_name" label={_('Full Name')} defaultValue={account?.fullName || ''} required validation={{ required: _('Full Name is required') }} /> } name="email" label={_('Email')} defaultValue={account?.email || ''} required validation={{ required: _('Email is required') }} />
setIsEditing(false)} />
) : (
{account?.fullName}
) }, sortOrder: 10 }, { component: { default: () => (
{account?.email}
) }, sortOrder: 15 } ]} />
)} ); } export const layout = { areaId: 'content', sortOrder: 10 };