"use client"; import {useEffect, useState} from "react"; import {Check, ChevronDown} from "lucide-react"; import {cn} from "@/lib/utils"; import {Button} from "@/components/ui/button"; import {Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList} from "@/components/ui/command"; import {Popover, PopoverContent, PopoverTrigger} from "@/components/ui/popover"; import {FormControl} from "@/components/ui/form"; import {SidebarMenuButton} from "@/components/ui/sidebar"; import {Separator} from "@/components/ui/separator"; import {CreateOrganizationModal} from "@/components/wrappers/dashboard/organization/create-organisation-modal"; export type comboBoxProps = { values: Array<{ value: string; label: string }>; defaultValue?: string; onValueChange?: any; searchField?: boolean; sideBar?: boolean; reload?: () => void; }; export function ComboBox(props: comboBoxProps) { const { values: choices, defaultValue: defaultChoice = "", onValueChange, searchField = false, sideBar = false } = props; const [value, setValue] = useState(); useEffect(() => { setValue(defaultChoice); }, [defaultChoice]); const [open, setOpen] = useState(false); const [openModal, setOpenModal] = useState(false); return (
{ props.reload?.(); }} onOpenChange={setOpenModal} /> {sideBar ? ( {value ? choices.find((choice) => choice.value === value)?.label : "Select choice..."} ) : ( )} {searchField ? : null} No choice found. {choices.map((choice) => ( { setValue(currentValue); onValueChange(currentValue); setOpen(false); }} > {choice.label} ))} {sideBar ? ( { setOpen(false) setOpenModal(true) } }>+ Create new organization ) : null}
); } export type comboBoxFormItemProps = comboBoxProps & { value: any; name: any; onChange: any; }; /** Combobox to use when working with zodForm. */ export function ComboBoxFormItem(props: comboBoxFormItemProps) { const {values: choices, searchField = false, value, name, onChange} = props; const [open, setOpen] = useState(false); return ( {searchField ? : null} No {name} found. {choices.map((choice) => ( { onChange(choice.value); setOpen(false); }} > {choice.label} ))} ); }