UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

35 lines (34 loc) 1.73 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'; import { transformItems } from './utils'; function isTableOptions(options) { return options !== undefined; } /** * The `ReferenceListsTableCode` component is used to specify the code of the table * in Reference lists API for which the items will be fetched */ export const ReferenceListsTableCode = () => { var _a; const intl = useIntl(); const { values } = useFormikContext(); const service = (_a = values === null || values === void 0 ? void 0 : values.openForms) === null || _a === void 0 ? void 0 : _a.service; const { getReferenceListsTables } = useContext(BuilderContext); const { value: options, loading, error, } = useAsync(async () => { if (!service) { return []; } return await getReferenceListsTables(service); }, [service]); if (error) { throw error; } const _options = isTableOptions(options) ? transformItems(options, intl) : []; return (_jsx(Select, { name: "openForms.code", label: _jsx(FormattedMessage, { id: 'cLzsxn', defaultMessage: [{ type: 0, value: "Reference lists table code" }] }), tooltip: intl.formatMessage({ id: "YObTjL", defaultMessage: [{ type: 0, value: "The code of the table from which the options will be retrieved." }] }), isLoading: loading, options: _options, valueProperty: "value", required: true })); }; export default ReferenceListsTableCode;