import { useState, useEffect } from 'react' import { Link, useNavigate } from 'react-router-dom' import { authClient } from '../lib/auth-client.ts' import { useAuthStore } from '../stores/auth.ts' import { useThemeStore } from '../stores/theme.ts' import { StoreIcon } from '../components/StoreIcon.tsx' export function Settings() { const { data: session } = authClient.useSession() const setAuthenticated = useAuthStore((s) => s.setAuthenticated) const navigate = useNavigate() const { theme, setTheme } = useThemeStore() const [emailInAddress, setEmailInAddress] = useState(null) const [copied, setCopied] = useState(false) useEffect(() => { if (!session?.user) return fetch('/api/v1/me/email-in-address', { credentials: 'include', }) .then((res) => res.json()) .then((data) => setEmailInAddress(data.email_address)) .catch(() => setEmailInAddress(null)) }, [session]) async function handleCopyEmail() { if (emailInAddress) { await navigator.clipboard.writeText(emailInAddress) setCopied(true) setTimeout(() => setCopied(false), 2000) } } const user = session?.user const connectedStores: string[] = [] async function handleSignOut() { await authClient.signOut() setAuthenticated(false) navigate('/login') } return (

Settings

{/* Profile section */}

Profile

{user?.name?.charAt(0) ?? '?'}

{user?.name ?? 'Guest'}

{user?.email ?? ''}

{/* Connected stores */}

Connected Stores

{connectedStores.length > 0 ? (
{connectedStores.map((storeId) => (
{storeId} Connected
))}
) : (

No stores connected yet.

)}
{connectedStores.length > 0 ? 'Manage Stores' : 'Connect a Store'}
{/* Notifications */}

Notifications

{/* Appearance */}

Appearance

{(['light', 'dark', 'system'] as const).map((t) => ( ))}
{/* Account actions */}

Account

{/* Receipt Email section */}

Receipt Email

Forward your digital receipt emails to this address:

{emailInAddress ?? 'Loading...'}

Supports Meijer, Kroger, and Target receipt emails.

) } function SettingsToggle({ label, defaultChecked = false, }: { label: string defaultChecked?: boolean }) { return ( ) }