import { Field, useFormikContext } from "formik"; import type { ActionMeta, MultiValue } from "react-select"; import CreatableSelect from "react-select/creatable"; import { intl } from "src/locale"; import { validateDomain, validateDomains } from "src/modules/Validations"; export type SelectOption = { label: string; value: string; color?: string; }; interface Props { id?: string; maxDomains?: number; isWildcardPermitted?: boolean; dnsProviderWildcardSupported?: boolean; name?: string; label?: string; } export function DomainNamesField({ name = "domainNames", label = "domain-names", id = "domainNames", maxDomains, isWildcardPermitted = true, dnsProviderWildcardSupported = true, }: Props) { const { setFieldValue } = useFormikContext(); const handleChange = (v: MultiValue, _actionMeta: ActionMeta) => { const doms = v?.map((i: SelectOption) => { return i.value; }); setFieldValue(name, doms); }; const helperTexts: string[] = []; if (maxDomains) { helperTexts.push(intl.formatMessage({ id: "domain-names.max" }, { count: maxDomains })); } if (!isWildcardPermitted) { helperTexts.push(intl.formatMessage({ id: "domain-names.wildcards-not-permitted" })); } else if (!dnsProviderWildcardSupported) { helperTexts.push(intl.formatMessage({ id: "domain-names.wildcards-not-supported" })); } return ( {({ field, form }: any) => (
({ label: d, value: d }))} /> {form.errors[field.name] && form.touched[field.name] ? ( {form.errors[field.name]} ) : helperTexts.length ? ( helperTexts.map((i) => ( {i} )) ) : null}
)}
); }