UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

33 lines (32 loc) 1.7 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { useFormikContext } from 'formik'; import { useContext } from 'react'; import { FormattedMessage, useIntl } from 'react-intl'; import useAsync from 'react-use/esm/useAsync'; import Select from '../../../components/formio/select'; import { BuilderContext } from '../../../context'; function isAttributeOptions(options) { return options !== undefined; } /** * Fetch the available validator plugins and display them in a multiselect. * * This requires an async function `getRegistrationAttributes` to be provided to the * BuilderContext which is responsible for retrieving the list of available plugins. * * If a fetch error occurs, it is thrown during rendering - you should provide your * own error boundary to catch this. */ const RegistrationAttributeSelect = () => { const intl = useIntl(); const { values } = useFormikContext(); const { getRegistrationAttributes } = useContext(BuilderContext); const { value: options, loading, error, } = useAsync(async () => await getRegistrationAttributes(values.type || ''), []); if (error) { throw error; } const tooltip = intl.formatMessage({ id: "fT6Gtt", defaultMessage: [{ type: 0, value: "Save the value as this attribute in the registration backend system." }] }); const _options = isAttributeOptions(options) ? options : []; return (_jsx(Select, { name: "registration.attribute", label: _jsx(FormattedMessage, { id: 'EacF3m', defaultMessage: [{ type: 0, value: "Registration attribute" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: _options, valueProperty: "id" })); }; export default RegistrationAttributeSelect;