import { useState } from 'react'; import { useQuery } from '@tanstack/react-query'; import { Link } from 'react-router-dom'; import { customerApi } from '../../services/api'; import { useAuth } from '../../context/AuthContext'; import Card from '../../components/ui/Card'; import Button from '../../components/ui/Button'; import Input from '../../components/ui/Input'; import Badge from '../../components/ui/Badge'; import { Plus, Search, Eye, Edit } from 'lucide-react'; export default function CustomerList() { const [search, setSearch] = useState(''); const [type, setType] = useState(''); const [page, setPage] = useState(1); const { hasPermission } = useAuth(); const { data, isLoading } = useQuery({ queryKey: ['customers', search, type, page], queryFn: () => customerApi.getAll({ search, type: type || undefined, page, limit: 20 }), }); return (

Kunden

{hasPermission('customers:create') && ( )}
setSearch(e.target.value)} className="flex-1" />
{isLoading ? (
Laden...
) : data?.data && data.data.length > 0 ? ( <>
{data.data.map((customer) => ( ))}
Kundennr. Name Typ E-Mail Verträge Aktionen
{customer.customerNumber} {customer.type === 'BUSINESS' && customer.companyName ? customer.companyName : `${customer.firstName} ${customer.lastName}`} {customer.type === 'BUSINESS' ? 'Firma' : 'Privat'} {customer.email || '-'} {(customer as any)._count?.contracts || 0}
{hasPermission('customers:update') && ( )}
{data.pagination && data.pagination.totalPages > 1 && (

Seite {data.pagination.page} von {data.pagination.totalPages} ({data.pagination.total} Einträge)

)} ) : (
Keine Kunden gefunden.
)}
); }