@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
58 lines (56 loc) • 3.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AuthPlugin = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const react_intl_1 = require("react-intl");
const useAsync_1 = __importDefault(require("react-use/esm/useAsync"));
const builder_1 = require("../../components/builder");
const messages_1 = require("../../components/builder/messages");
const formio_1 = require("../../components/formio");
const context_1 = require("../../context");
const errors_1 = require("../../utils/errors");
/**
* Form to configure a Formio 'coSign' (cosign v1) type component.
*/
const EditForm = () => {
const intl = (0, react_intl_1.useIntl)();
(0, builder_1.useDeriveComponentKey)();
const { hasAnyError } = (0, errors_1.useErrorChecker)();
return ((0, jsx_runtime_1.jsxs)(formio_1.Tabs, { children: [(0, jsx_runtime_1.jsxs)(formio_1.TabList, { children: [(0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Basic, { hasErrors: hasAnyError('label', 'description', 'authPlugin', 'hidden') }), (0, jsx_runtime_1.jsx)(builder_1.BuilderTabs.Translations, { hasErrors: hasAnyError('openForms.translations') })] }), (0, jsx_runtime_1.jsxs)(formio_1.TabPanel, { children: [(0, jsx_runtime_1.jsx)(builder_1.Label, {}), (0, jsx_runtime_1.jsx)(builder_1.Description, {}), (0, jsx_runtime_1.jsx)(exports.AuthPlugin, {}), (0, jsx_runtime_1.jsx)(builder_1.Hidden, {})] }), (0, jsx_runtime_1.jsx)(formio_1.TabPanel, { children: (0, jsx_runtime_1.jsx)(builder_1.Translations.ComponentTranslations, { propertyLabels: {
label: intl.formatMessage(messages_1.LABELS.label),
description: intl.formatMessage(messages_1.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;
}
const AuthPlugin = () => {
const { getAuthPlugins } = (0, react_1.useContext)(context_1.BuilderContext);
const { value: options, loading, error } = (0, useAsync_1.default)(async () => await getAuthPlugins(), []);
if (error) {
throw error;
}
const _options = isAuthPluginOptions(options) ? options : [];
return ((0, jsx_runtime_1.jsx)(formio_1.Select, { name: "authPlugin", label: (0, jsx_runtime_1.jsx)(react_intl_1.FormattedMessage, { id: 'lOSmt+', defaultMessage: [{ type: 0, value: "Authentication method" }] }), description: (0, jsx_runtime_1.jsx)(react_intl_1.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" }));
};
exports.AuthPlugin = AuthPlugin;
exports.default = EditForm;