import { FormErrorMessage, FormLabel, Skeleton } from '@chakra-ui/react'; import { useQuery } from '@tanstack/react-query'; import { __ } from '@wordpress/i18n'; import React, { useMemo } from 'react'; import { Controller, useFormContext } from 'react-hook-form'; import Select from 'react-select'; import FormControlTwoCol from '../../../../../../assets/js/back-end/components/common/FormControlTwoCol'; import urls from '../../../../../../assets/js/back-end/constants/urls'; import { CurrenciesSchema } from '../../../../../../assets/js/back-end/schemas'; import ToolTip from '../../../../../../assets/js/back-end/screens/settings/components/ToolTip'; import API from '../../../../../../assets/js/back-end/utils/api'; import { MultipleCurrencySettingsSchema } from '../../types/multiCurrency'; interface CountryOption { value: string; label: string; } interface Props { defaultValue: CountryOption; testModeWatch: boolean; } const Country: React.FC = ({ defaultValue, testModeWatch }) => { const countriesAPI = new API(urls.countries); const { control, setValue, formState: { errors }, } = useFormContext(); const countriesQuery = useQuery({ queryKey: ['countries'], queryFn: () => countriesAPI.list(), }); const countryOptions = useMemo(() => { return countriesQuery.isSuccess ? countriesQuery.data?.map((country: CurrenciesSchema) => ({ value: country.code, label: country.name, })) : []; }, [countriesQuery.isSuccess, countriesQuery.data]); const noOptionsMessage = () => __('No country found.', 'learning-management-system'); return ( {__('Test Country', 'learning-management-system')} {countriesQuery.isLoading ? ( ) : ( (