import { useState } from 'react'; import { Modal, Form, Input, Button, Checkbox, Tabs, Alert } from 'antd'; import { registerCustomer, loginCustomer } from './customerApi'; import { useCustomerAuth } from './CustomerAuthContext'; interface Props { open: boolean; onClose: () => void; onSuccess: () => void; } export default function AuthPromptModal({ open, onClose, onSuccess }: Props) { const [tab, setTab] = useState<'register' | 'login'>('register'); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [form] = Form.useForm(); const { refresh } = useCustomerAuth(); async function handleRegister(values: any) { setLoading(true); setError(null); try { await registerCustomer(values.email, values.password, values.name, !!values.marketingConsent); refresh(); onSuccess(); } catch (err) { setError((err as Error).message); } finally { setLoading(false); } } async function handleLogin(values: any) { setLoading(true); setError(null); try { await loginCustomer(values.email, values.password); refresh(); onSuccess(); } catch (err) { setError((err as Error).message); } finally { setLoading(false); } } return ( {error && } setTab(k as 'register' | 'login')} items={[ { key: 'register', label: 'Create Account', children: (
Send me occasional emails about new one-of-a-kind items.
) }, { key: 'login', label: 'Log In', children: (
) } ]} />
); }