import { useState } from 'react' import { Link } from 'react-router-dom' import { StoreIcon } from '../components/StoreIcon.tsx' interface StoreConfig { id: string name: string description: string fields: { key: string; label: string; type: string }[] } const availableStores: StoreConfig[] = [ { id: 'meijer', name: 'Meijer', description: 'Connect your mPerks account to import purchase history.', fields: [ { key: 'email', label: 'mPerks Email', type: 'email' }, { key: 'password', label: 'mPerks Password', type: 'password' }, ], }, { id: 'kroger', name: 'Kroger', description: 'Connect your Kroger Plus account for receipts and digital coupons.', fields: [ { key: 'email', label: 'Kroger Email', type: 'email' }, { key: 'password', label: 'Kroger Password', type: 'password' }, ], }, { id: 'target', name: 'Target', description: 'Connect Target Circle for purchase history and deals.', fields: [ { key: 'email', label: 'Target Email', type: 'email' }, { key: 'password', label: 'Target Password', type: 'password' }, ], }, ] export function AccountLinking() { const [linking, setLinking] = useState(null) const [connected, setConnected] = useState(['meijer', 'kroger']) const [status, setStatus] = useState<'idle' | 'connecting' | 'success' | 'error'>('idle') function handleConnect(storeId: string) { setStatus('connecting') // Simulate connection — fields will be sent to API when available setTimeout(() => { setConnected((prev) => [...prev, storeId]) setStatus('success') setTimeout(() => { setLinking(null) setStatus('idle') }, 1500) }, 2000) } function handleDisconnect(storeId: string) { setConnected((prev) => prev.filter((s) => s !== storeId)) } return (
Settings

Connect a Store

Link your store loyalty accounts to automatically import purchases and track prices.

{availableStores.map((store) => { const isConnected = connected.includes(store.id) const isLinking = linking === store.id return (

{store.name}

{isConnected ? 'Connected' : store.description}

{isConnected ? ( ) : null}
{isConnected && !isLinking && ( )} {!isConnected && !isLinking && ( )} {isLinking && ( handleConnect(store.id)} onCancel={() => { setLinking(null) setStatus('idle') }} /> )}
) })}

Your credentials are encrypted and stored securely. CartSnitch never shares your login information with third parties.

) } function LinkForm({ store, status, onSubmit, onCancel, }: { store: StoreConfig status: string onSubmit: () => void onCancel: () => void }) { const [values, setValues] = useState>(() => Object.fromEntries(store.fields.map((f) => [f.key, ''])), ) return (
{store.fields.map((field) => ( setValues((prev) => ({ ...prev, [field.key]: e.target.value }))} autoComplete={field.type === 'password' ? 'current-password' : field.type} className="min-h-12 w-full rounded-xl border border-gray-200 px-4 text-base focus:border-brand-blue focus:outline-none focus:ring-1 focus:ring-brand-blue" /> ))} {status === 'connecting' && (
Connecting to {store.name}...
)} {status === 'success' && (
Connected successfully!
)} {status === 'error' && (
Connection failed. Please check your credentials and try again.
)} {status === 'idle' && (
)}
) }