import { useTranslation } from "react-i18next"; import { Combobox, ComboboxButton,…
- User
import { useTranslation } from "react-i18next"; import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions, Transition, } from "@headlessui/react"; import { Fragment, useEffect, useRef, useState } from "react"; import { CheckIcon, ChevronDownIcon, XMarkIcon, } from "@heroicons/react/20/solid";
import { useLocation } from "react-router-dom"; import { getCurrentCurrencySymbol, } from "../../utilities/Utils"; import ERPElementValidationMessage from "./erp-element-validation-message"; import { useAppDispatch, } from "../../utilities/hooks/useAppDispatch"; import { APIClient } from "../../helpers/api-client"; interface ERPDataComboboxProps { id: string; label?: string; options?: any[]; excludeOptions?: any[]; includeOptions?: any[]; value?: any; defaultValue?: any; handleChange?: (id: string, value: any) => void; handleChangeData?: (id: string, value: any) => void; onChangeData?: (data: any) => void; onChange?: (value: any) => void; onSelectItem?: (item?: any) => void; field?: any; defaultData?: any; data?: any; required?: boolean; className?: string; noLabel?: boolean; multiple?: boolean; autoFocus?: boolean; disabled?: boolean; initialValue?: any; isPaginated?: boolean; disabledApiCall?: boolean; validation?: string; }
export const getOptions = (data: any, keyLabel: string, keyValue: string) => { let getter = keyLabel?.split("."); if (data?.length > 0) { let options; if (getter?.length > 1) { options = data?.map((item: any) => ({ label: item?.[getter[0]]?.[getter[1]], value: item?.[keyValue], is_active: item?.is_active, })); } else { console.log('data:' + data);
codeoptions = data?.map((item: any) => ({ label: item?.[keyLabel], value: item?.[keyValue], is_active: item?.is_active, })); } return options || [];} }; const api = new APIClient(); export default function ERPDataCombobox({ id, label, handleChange, handleChangeData, onChange, onChangeData, onSelectItem, options, field, defaultData, defaultValue, data, noLabel, required, excludeOptions, includeOptions, multiple, autoFocus, disabled = false, initialValue, className, isPaginated = false, disabledApiCall = false, validation }: ERPDataComboboxProps) { const { t } = useTranslation(); const dispatch = useAppDispatch(); const { pathname } = useLocation();
const comboboxRef = useRef(null); const currencySymbol = getCurrentCurrencySymbol();
const [query, setQuery] = useState(""); const [localValue, setLocalValue] = useState(); const [items, setItems] = useState([]); const [loading, setLoading] = useState([]); const [hasValue, setHasValue] = useState(false); const [initial, setInitial] = useState(initialValue); useEffect(() => {
codeif (!disabledApiCall) { loadData(); } - Assistant