|
| 1 | +import { Check, Users } from "lucide-react"; |
| 2 | +import { Button } from "@/components/ui/button"; |
| 3 | +import type { Client } from "@/lib/types"; |
| 4 | +import { cn } from "@/lib/utils"; |
| 5 | + |
| 6 | +interface ClientSelectorProps { |
| 7 | + clients: Client[]; |
| 8 | + selectedClientId: string | null; |
| 9 | + onSelectClient: (clientId: string) => void; |
| 10 | + hasFilter?: boolean; |
| 11 | +} |
| 12 | + |
| 13 | +export function ClientSelector({ |
| 14 | + clients, |
| 15 | + selectedClientId, |
| 16 | + onSelectClient, |
| 17 | + hasFilter, |
| 18 | +}: ClientSelectorProps) { |
| 19 | + if (clients.length === 0) { |
| 20 | + return ( |
| 21 | + <div className="flex flex-col items-center justify-center py-8 text-center"> |
| 22 | + <Users className="mb-3 h-8 w-8 text-muted-foreground/50" /> |
| 23 | + <p className="text-sm text-muted-foreground"> |
| 24 | + {hasFilter |
| 25 | + ? "No clients match your search." |
| 26 | + : "No clients yet. Create one to get started."} |
| 27 | + </p> |
| 28 | + </div> |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + return ( |
| 33 | + <ul className="space-y-1"> |
| 34 | + {clients.map((client) => { |
| 35 | + const isSelected = selectedClientId === client.id; |
| 36 | + |
| 37 | + return ( |
| 38 | + <li key={client.id}> |
| 39 | + <Button |
| 40 | + variant={isSelected ? "default" : "ghost"} |
| 41 | + onClick={() => onSelectClient(client.id)} |
| 42 | + className={cn( |
| 43 | + "h-auto w-full justify-start py-2", |
| 44 | + !isSelected && "text-foreground", |
| 45 | + )} |
| 46 | + > |
| 47 | + <div className="flex flex-1 flex-col items-start gap-0.5 overflow-hidden"> |
| 48 | + <span className="truncate text-left text-sm font-medium"> |
| 49 | + {client.label || client.client} |
| 50 | + </span> |
| 51 | + {client.label && ( |
| 52 | + <span |
| 53 | + className={cn( |
| 54 | + "truncate text-left text-xs", |
| 55 | + isSelected |
| 56 | + ? "text-primary-foreground/70" |
| 57 | + : "text-muted-foreground", |
| 58 | + )} |
| 59 | + > |
| 60 | + {client.client} |
| 61 | + </span> |
| 62 | + )} |
| 63 | + </div> |
| 64 | + {isSelected && ( |
| 65 | + <Check className="h-4 w-4 shrink-0" /> |
| 66 | + )} |
| 67 | + </Button> |
| 68 | + </li> |
| 69 | + ); |
| 70 | + })} |
| 71 | + </ul> |
| 72 | + ); |
| 73 | +} |
0 commit comments