import * as React from 'react'; import { Trans } from '@lingui/react/macro'; import { Role } from '@prisma/client'; import { Check, ChevronsUpDown } from 'lucide-react'; import { cn } from '@documenso/ui/lib/utils'; import { Button } from '@documenso/ui/primitives/button'; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, } from '@documenso/ui/primitives/command'; import { Popover, PopoverContent, PopoverTrigger } from '@documenso/ui/primitives/popover'; type ComboboxProps = { listValues: string[]; onChange: (_values: string[]) => void; }; const MultiSelectRoleCombobox = ({ listValues, onChange }: ComboboxProps) => { const [open, setOpen] = React.useState(false); const [selectedValues, setSelectedValues] = React.useState([]); const dbRoles = Object.values(Role); React.useEffect(() => { setSelectedValues(listValues); }, [listValues]); const allRoles = [...new Set([...dbRoles, ...selectedValues])]; const handleSelect = (currentValue: string) => { let newSelectedValues; if (selectedValues.includes(currentValue)) { newSelectedValues = selectedValues.filter((value) => value !== currentValue); } else { newSelectedValues = [...selectedValues, currentValue]; } setSelectedValues(newSelectedValues); onChange(newSelectedValues); setOpen(false); }; return ( No value found. {allRoles.map((value: string, i: number) => ( handleSelect(value)}> {value} ))} ); }; export { MultiSelectRoleCombobox };