import Area from '@components/common/Area.js'; import { EmailField } from '@components/common/form/EmailField.js'; import { PasswordField } from '@components/common/form/PasswordField.js'; import { Button } from '@components/common/ui/Button.js'; import { Card, CardContent, CardHeader, CardTitle } from '@components/common/ui/Card.js'; import { Item, ItemActions, ItemContent, ItemDescription, ItemTitle } from '@components/common/ui/Item.js'; import { useCartState } from '@components/frontStore/cart/CartContext.js'; import { useCheckout, useCheckoutDispatch } from '@components/frontStore/checkout/CheckoutContext.js'; import { useCustomer, useCustomerDispatch } from '@components/frontStore/customer/CustomerContext.jsx'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import { CircleUser } from 'lucide-react'; import React, { useEffect, useState } from 'react'; import { toast } from 'react-toastify'; const LoggedIn: React.FC<{ fullName: string; email: string; uuid: string; }> = ({ uuid, fullName, email }) => { const [isLoggingOut, setIsLoggingOut] = useState(false); const { logout } = useCustomerDispatch(); const { updateCheckoutData } = useCheckoutDispatch(); useEffect(() => { updateCheckoutData({ customer: { id: uuid, email: email, fullName: fullName } }); }, [fullName, email]); const handleLogout = async () => { if (isLoggingOut) return; try { setIsLoggingOut(true); await logout(); toast.success(_('Successfully logged out')); } catch (error) { const errorMessage = error instanceof Error ? error.message : _('Logout failed'); toast.error(errorMessage); } finally { setIsLoggingOut(false); } }; return (
{_('Logged in as')} {fullName}
{email}
); }; const Guest: React.FC<{ email: string; }> = ({ email }) => { const [showLogin, setShowLogin] = useState(false); const [isLogging, setIsLogging] = useState(false); const { login } = useCustomerDispatch(); const { form } = useCheckout(); const { updateCheckoutData } = useCheckoutDispatch(); const contactEmail = form.watch('contact.email', email); const handleLoginClick = (e: React.MouseEvent) => { e.preventDefault(); setShowLogin(true); }; useEffect(() => { updateCheckoutData({ customer: { email: contactEmail } }); }, [contactEmail]); const handleLogin = async () => { if (isLogging) return; try { setIsLogging(true); const isValid = await form.trigger(['contact.email', 'contact.password']); if (!isValid) { return; } const formData = form.getValues(); const loginEmail = formData?.contact?.email; const password = formData?.contact?.password; await login( { email: loginEmail, password: password }, window.location.href ); toast.success(_('Successfully logged in')); setShowLogin(false); } catch (error) { const errorMessage = error instanceof Error ? error.message : _('Login failed'); toast.error(errorMessage); } finally { setIsLogging(false); } }; const handleCancelLogin = () => { setShowLogin(false); // Clear password field form.setValue('contact.password', ''); }; return (
{showLogin && (
)} {!showLogin && (

{_('Already have an account?')}{' '}

)}
); }; export function ContactInformation() { const { customer } = useCustomer(); const { data: cart } = useCartState(); return ( <>
{_('Contact Information')}
{customer ? ( ) : ( )}
); }