@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
65 lines (64 loc) • 3.87 kB
JavaScript
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { useContext } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import useAsync from 'react-use/esm/useAsync';
import { Select, TextField } from '../../components/formio';
import { BuilderContext } from '../../context';
const groupDocumentTypeOptions = (options) => {
const optionsWithGroupLabel = options.map(item => {
const groupLabel = [item.backendLabel, item.catalogueLabel].filter(Boolean).join(' > ');
return {
groupLabel,
value: item.url,
label: item.description,
};
});
const groups = optionsWithGroupLabel.reduce((accumulator, optionWithGroupLabel) => {
const { groupLabel, value, label } = optionWithGroupLabel;
if (!accumulator[groupLabel]) {
accumulator[groupLabel] = [];
}
accumulator[groupLabel].push({ value, label });
return accumulator;
}, {});
// now convert this mapping back to a list of opt groups
const optGroups = Object.entries(groups).map(([groupLabel, options]) => ({
label: groupLabel,
options,
}));
return optGroups;
};
const DocumentTypeSelect = () => {
const intl = useIntl();
const { getDocumentTypes } = useContext(BuilderContext);
const { value: options, loading, error } = useAsync(async () => await getDocumentTypes(), []);
if (error) {
throw error;
}
const tooltip = intl.formatMessage({ id: "5y8Yt4", defaultMessage: [{ type: 0, value: "Save the attachment in the Documents API with this InformatieObjectType. If unspecified, the registration plugin defaults are used." }] });
return (_jsx(Select, { name: "registration.informatieobjecttype", label: _jsx(FormattedMessage, { id: 'fY/8xt', defaultMessage: [{ type: 0, value: "Information object type" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: groupDocumentTypeOptions(options || []) }));
};
const SourceOrganisation = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({ id: "yQUV3M", defaultMessage: [{ type: 0, value: "RSIN of the organization which creates the ENKELVOUDIGINFORMATIEOBJECT." }] });
return (_jsx(TextField, { name: "registration.bronorganisatie", label: _jsx(FormattedMessage, { id: 'nW5g1S', defaultMessage: [{ type: 0, value: "Bronorganisatie" }] }), tooltip: tooltip, inputMode: "numeric" }));
};
const ConfidentialityLevelSelect = () => {
const intl = useIntl();
const { getConfidentialityLevels } = useContext(BuilderContext);
const { value: options, loading, error, } = useAsync(async () => await getConfidentialityLevels(), []);
if (error) {
throw error;
}
const tooltip = intl.formatMessage({ id: "vlY36U", defaultMessage: [{ type: 0, value: "Indication of the level to which extent the INFORMATIEOBJECT is meant to be public." }] });
return (_jsx(Select, { name: "registration.docVertrouwelijkheidaanduiding", label: _jsx(FormattedMessage, { id: '6XG2pL', defaultMessage: [{ type: 0, value: "Confidentiality level" }] }), tooltip: tooltip, isLoading: loading, isClearable: true, options: options, valueProperty: "value" }));
};
const Title = () => {
const intl = useIntl();
const tooltip = intl.formatMessage({ id: "2mgmOj", defaultMessage: [{ type: 0, value: "The title for the document that is related to the case." }] });
return (_jsx(TextField, { name: "registration.titel", label: _jsx(FormattedMessage, { id: 'SEu4I2', defaultMessage: [{ type: 0, value: "Title" }] }), tooltip: tooltip }));
};
const RegistrationTabFields = () => {
return (_jsxs(_Fragment, { children: [_jsx(DocumentTypeSelect, {}), _jsx(SourceOrganisation, {}), _jsx(ConfidentialityLevelSelect, {}), _jsx(Title, {})] }));
};
export default RegistrationTabFields;