@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
51 lines (49 loc) • 2.68 kB
JavaScript
import { jsx as _jsx, 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 { BuilderTabs, Description, Hidden, Label, Translations, useDeriveComponentKey, } from '../../components/builder';
import { LABELS } from '../../components/builder/messages';
import { Select, TabList, TabPanel, Tabs } from '../../components/formio';
import { BuilderContext } from '../../context';
import { useErrorChecker } from '../../utils/errors';
/**
* Form to configure a Formio 'coSign' (cosign v1) type component.
*/
const EditForm = () => {
const intl = useIntl();
useDeriveComponentKey();
const { hasAnyError } = useErrorChecker();
return (_jsxs(Tabs, { children: [_jsxs(TabList, { children: [_jsx(BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'description', 'authPlugin', 'hidden') }), _jsx(BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), _jsxs(TabPanel, { children: [_jsx(Label, {}), _jsx(Description, {}), _jsx(AuthPlugin, {}), _jsx(Hidden, {})] }), _jsx(TabPanel, { children: _jsx(Translations.ComponentTranslations, { propertyLabels: {
label: intl.formatMessage(LABELS.label),
description: intl.formatMessage(LABELS.description),
} }) })] }));
};
/*
Making this introspected or declarative doesn't seem advisable, as React is calling
React.Children and related API's legacy API - this may get removed in future
versions.
Explicitly specifying the schema and default values is therefore probbaly best, at
the cost of some repetition.
*/
EditForm.defaultValues = {
// basic tab
label: '',
key: '',
description: '',
hidden: false,
authPlugin: '',
};
function isAuthPluginOptions(options) {
return options !== undefined;
}
export const AuthPlugin = () => {
const { getAuthPlugins } = useContext(BuilderContext);
const { value: options, loading, error } = useAsync(async () => await getAuthPlugins(), []);
if (error) {
throw error;
}
const _options = isAuthPluginOptions(options) ? options : [];
return (_jsx(Select, { name: "authPlugin", label: _jsx(FormattedMessage, { id: 'lOSmt+', defaultMessage: [{ type: 0, value: "Authentication method" }] }), description: _jsx(FormattedMessage, { id: 'Su4nqf', defaultMessage: [{ type: 0, value: "Which authentication method the co-signer must use. Note that this must be an authentication method available on the form." }] }), isLoading: loading, options: _options, valueProperty: "id" }));
};
export default EditForm;