import { FormControl, FormErrorMessage, FormLabel, Select, } from "@chakra-ui/react"; import { DNSProvider } from "api/npm"; import { Field, useFormikContext } from "formik"; import { useDNSProviders } from "hooks"; import { intl } from "locale"; const fieldName = "dnsProviderId"; function DNSProviderField() { const { setFieldValue } = useFormikContext(); const { data, isLoading } = useDNSProviders(0, 999); const handleOnChange = (e: any) => { if (e.currentTarget.value) { const id = parseInt(e.currentTarget.value, 10); // This step enforces that the formik payload has a // string number instead of a string as the value // for this field setFieldValue(fieldName, id); } }; return ( {({ field, form }: any) => ( {intl.formatMessage({ id: "dns-provider", })} {!isLoading && !data?.total ? intl.formatMessage({ id: "dns-providers.empty", }) : form.errors[fieldName]} )} ); } export { DNSProviderField };