From 023c789bafd610459df2f1dc7f90778e5eabd89d Mon Sep 17 00:00:00 2001 From: DanielS Date: Wed, 1 Jul 2026 09:37:30 +0200 Subject: [PATCH] feat: add customer search and scrollable list to orderwizard --- shop/components/order-wizard.tsx | 109 +++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 33 deletions(-) diff --git a/shop/components/order-wizard.tsx b/shop/components/order-wizard.tsx index ad9c382..fddbcf6 100644 --- a/shop/components/order-wizard.tsx +++ b/shop/components/order-wizard.tsx @@ -11,7 +11,7 @@ import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Separator } from '@/components/ui/separator' import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group' -import { Check, ChevronRight, ChevronLeft, ShoppingCart, User, ShieldCheck, Cloud, Utensils, HardDrive, Package, AlertCircle, Loader2, UserPlus, Building2, CreditCard, Calendar } from 'lucide-react' +import { Check, ChevronRight, ChevronLeft, ShoppingCart, User, ShieldCheck, Cloud, Utensils, HardDrive, Package, AlertCircle, Loader2, UserPlus, Building2, CreditCard, Calendar, Search } from 'lucide-react' import { submitOrder } from '@/lib/actions/orders' import { createEndCustomer } from '@/lib/actions/end-customers' import { Category } from '@/lib/types' @@ -100,6 +100,32 @@ export function OrderWizard({ ) const selectedEndCustomer = endCustomers.find(c => c.id === selectedEndCustomerId) ?? null + const [searchTerm, setSearchTerm] = useState('') + + const filteredEndCustomers = useMemo(() => { + const activeCustomers = endCustomers.filter(c => !c.is_anonymized) + const term = searchTerm.toLowerCase().trim() + if (!term) return activeCustomers + + return activeCustomers.filter(customer => { + const company = customer.company_name?.toLowerCase() || '' + const firstName = customer.first_name?.toLowerCase() || '' + const lastName = customer.last_name?.toLowerCase() || '' + const street = customer.street?.toLowerCase() || '' + const zip = customer.zip?.toLowerCase() || '' + const city = customer.city?.toLowerCase() || '' + + return ( + company.includes(term) || + firstName.includes(term) || + lastName.includes(term) || + street.includes(term) || + zip.includes(term) || + city.includes(term) + ) + }) + }, [endCustomers, searchTerm]) + // Modus: 'select' = Bestandskunde wählen | 'create' = Neuen anlegen const [customerMode, setCustomerMode] = useState<'select' | 'create'>('select') const [isCreatingCustomer, setIsCreatingCustomer] = useState(false) @@ -398,7 +424,7 @@ export function OrderWizard({ {/* Modus A: Bestandskunde wählen */} {customerMode === 'select' && (
- {endCustomers.length === 0 ? ( + {endCustomers.filter(c => !c.is_anonymized).length === 0 ? (

Noch keine Endkunden angelegt.

@@ -407,37 +433,54 @@ export function OrderWizard({
) : ( -
- {endCustomers.filter(c => !c.is_anonymized).map(customer => ( - - ))} +
+
+ + setSearchTerm(e.target.value)} + className="pl-9 bg-white/5 border-white/10 text-white placeholder:text-slate-500" + /> +
+ {filteredEndCustomers.length === 0 ? ( +
+

Keine passenden Kunden gefunden.

+
+ ) : ( +
+ {filteredEndCustomers.map(customer => ( + + ))} +
+ )}
)}