import { Field, Label, Listbox, ListboxButton, ListboxOption, ListboxOptions, ListboxSelectedOption, } from '@headlessui/react'; import { CheckIcon, ChevronDownIcon } from '@heroicons/react/20/solid'; import clsx from 'clsx'; import React, { useEffect, useState } from 'react'; import { GetCustomFieldType } from '../../../../../services/data'; type ListItem = { id: number; value: string; label?: string; }; type SelectDropdownProps = { items: ListItem[]; title: string; placeholder?: string; setCurrentCustomFields: React.Dispatch< React.SetStateAction >; id: string; text: string; currentLanguage: string; }; const SelectDropdownCustom: React.FC = ({ items, title, placeholder, id, setCurrentCustomFields, text, currentLanguage, }) => { const [selected, setSelected] = useState( items.find(item => item.value === text) ?? null, ); useEffect(() => { setSelected(items.find(item => item.value === text) ?? null); }, [items, text]); const onChange = (item: ListItem) => { setCurrentCustomFields((prevFields: GetCustomFieldType[]) => { return prevFields.map((field: GetCustomFieldType) => field._id === id ? { ...field, text: field.text.map(itemIter => itemIter.locale === currentLanguage ? { locale: itemIter.locale, value: item.value, } : itemIter, ), } : field, ); }); }; return (
(
{item.label ? item.label : item.value}
))} placeholder={placeholder} />
{items.map(item => (
{item.label ? item.label : item.value}
))}
); }; export default SelectDropdownCustom;