import { useState, useMemo } from 'react' import { Link } from 'react-router-dom' import { FaSpinner, FaPlus, FaStar, FaFileInvoiceDollar } from 'react-icons/fa6' import { useCustomers } from '../hooks/useCustomers' import { useAuth } from '../context/AuthContext' import { createLead, customerStage, isArchived } from '../lib/leads' import { PageHeader, Card, Button, Badge, EmptyState, Field } from '../components/ui' export default function CustomersPage() { const { customers, loading, refresh } = useCustomers() const { user } = useAuth() const [search, setSearch] = useState('') const [stage, setStage] = useState('all') // all | lead | customer | archived const [showCreate, setShowCreate] = useState(false) const filtered = useMemo(() => { return (customers || []) .filter((c) => { const archived = isArchived(c) // Archivierte nur im Archiviert-Tab, sonst nie if (stage === 'archived') return archived if (archived) return false const st = customerStage(c) if (st === 'lost') return stage === 'all' if (stage === 'all') return true return st === stage }) .filter((c) => { if (!search) return true const s = search.toLowerCase() return `${c.name} ${c.code || ''} ${c.location || ''} ${c.email || ''}`.toLowerCase().includes(s) }) }, [customers, search, stage]) return (
setShowCreate((s) => !s)}> Neuer Lead} /> {showCreate && (
setShowCreate(false)} onDone={async (data) => { const r = await createLead(data, user) setShowCreate(false) refresh() return r }} />
)}
setSearch(e.target.value)} style={{ maxWidth: 320 }} />
{loading ? (
) : filtered.length === 0 ? ( ) : (
{filtered.map((c) => { const st = customerStage(c) return (
{(c.name || '?').charAt(0).toUpperCase()}
{c.importantCustomer && } {c.name} {c.code && · {c.code}}
{[c.location, c.email].filter(Boolean).join(' · ') || '-'}
{isArchived(c) && Archiviert} {st === 'lead' && Lead} {st === 'customer' && Fester Kunde} {st === 'lost' && Abgesagt} {c.invoiceNinjaClientId && Ninja}
) })}
)}
) } function CreateLeadForm({ onCancel, onDone }) { const [company, setCompany] = useState('') const [email, setEmail] = useState('') const [busy, setBusy] = useState(false) const [error, setError] = useState(null) const submit = async (e) => { e.preventDefault() if (!company.trim()) { setError('Unternehmen erforderlich'); return } setBusy(true); setError(null) try { await onDone({ company: company.trim(), email: email.trim() }) } catch (err) { setError(err.message || 'Fehler') setBusy(false) } } return (

Fuer einen Lead reichen Unternehmen und E-Mail. Es wird automatisch ein Akquise-Ticket erstellt.

setCompany(e.target.value)} required /> setEmail(e.target.value)} />
{error &&
{error}
}
) }