@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
25 lines (24 loc) • 2.56 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsx_runtime_1 = require("react/jsx-runtime");
const formik_1 = require("formik");
const react_intl_1 = require("react-intl");
const formio_1 = require("../../../components/formio");
const errors_1 = require("../../../utils/errors");
const constraint_mode_1 = __importDefault(require("./constraint-mode"));
const fixed_value_datefield_1 = __importDefault(require("./fixed-value-datefield"));
const include_today_1 = __importDefault(require("./include-today"));
const relative_delta_1 = __importDefault(require("./relative-delta"));
const PANEL_TITLES = (0, react_intl_1.defineMessages)({ minDate: { id: "dvlFuk", defaultMessage: [{ type: 0, value: "Minimum date " }, { type: 5, value: "configured", options: { false: { value: [{ type: 0, value: "(not set)" }] }, other: { value: [] } } }] }, maxDate: { id: "VX9nvG", defaultMessage: [{ type: 0, value: "Maximum date " }, { type: 5, value: "configured", options: { false: { value: [{ type: 0, value: "(not set)" }] }, other: { value: [] } } }] } });
const DateConstraintValidation = ({ constraint }) => {
var _a, _b;
const intl = (0, react_intl_1.useIntl)();
const { values } = (0, formik_1.useFormikContext)();
const mode = ((_b = (_a = values === null || values === void 0 ? void 0 : values.openForms) === null || _a === void 0 ? void 0 : _a[constraint]) === null || _b === void 0 ? void 0 : _b.mode) || '';
const { errors, hasErrors } = (0, errors_1.useValidationErrors)(`openForms.${constraint}`);
return ((0, jsx_runtime_1.jsxs)(formio_1.Panel, Object.assign({ title: intl.formatMessage(PANEL_TITLES[constraint], { configured: String(mode !== '') }), collapsible: true, initialCollapsed: true }, { children: [(0, jsx_runtime_1.jsx)(constraint_mode_1.default, { constraint: constraint }), mode === 'fixedValue' && (0, jsx_runtime_1.jsx)(fixed_value_datefield_1.default, { constraint: constraint }), ['future', 'past'].includes(mode) && (0, jsx_runtime_1.jsx)(include_today_1.default, { constraint: constraint }), mode === 'relativeToVariable' && (0, jsx_runtime_1.jsx)(relative_delta_1.default, { constraint: constraint }), hasErrors && ((0, jsx_runtime_1.jsx)("div", Object.assign({ className: "formio-component has-error" }, { children: (0, jsx_runtime_1.jsx)(errors_1.ErrorList, { errors: errors }) })))] })));
};
exports.default = DateConstraintValidation;