@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
33 lines (32 loc) • 1.64 kB
JavaScript
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 isPluginOptions(options) {
return options !== undefined;
}
/**
* Fetch the available validator plugins and display them in a multiselect.
*
* This requires an async function `getPrefillPlugins` 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 PrefillPluginSelect = () => {
const intl = useIntl();
const { values } = useFormikContext();
const { getPrefillPlugins } = useContext(BuilderContext);
const { value: options, loading, error, } = useAsync(async () => await getPrefillPlugins(values.type || ''), []);
if (error) {
throw error;
}
const tooltip = intl.formatMessage({ id: "YmWeGZ", defaultMessage: [{ type: 0, value: "Select the plugin to use for the prefill functionality." }] });
const _options = isPluginOptions(options) ? options : [];
return (_jsx(Select, { name: "prefill.plugin", label: _jsx(FormattedMessage, { id: 'ce1N0I', defaultMessage: [{ type: 0, value: "Plugin" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: _options, valueProperty: "id", emptyValue: "" }));
};
export default PrefillPluginSelect;