UNPKG

@open-formulieren/formio-builder

Version:

An opinionated Formio webform builder for Open Forms

19 lines (18 loc) 1.92 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { useFormikContext } from 'formik'; import { defineMessages, useIntl } from 'react-intl'; import { Panel } from '../../../components/formio'; import { ErrorList, useValidationErrors } from '../../../utils/errors'; import ModeSelect from './constraint-mode'; import FixedValueDateTimeField from './fixed-value-datetimefield'; import RelativeDelta from './relative-delta'; const PANEL_TITLES = 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 DateTimeConstraintValidation = ({ constraint }) => { var _a, _b; const intl = useIntl(); const { values } = 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 } = useValidationErrors(`openForms.${constraint}`); return (_jsxs(Panel, Object.assign({ title: intl.formatMessage(PANEL_TITLES[constraint], { configured: String(mode !== '') }), collapsible: true, initialCollapsed: true }, { children: [_jsx(ModeSelect, { constraint: constraint }), mode === 'fixedValue' && _jsx(FixedValueDateTimeField, { constraint: constraint }), mode === 'relativeToVariable' && _jsx(RelativeDelta, { constraint: constraint }), hasErrors && (_jsx("div", Object.assign({ className: "formio-component has-error" }, { children: _jsx(ErrorList, { errors: errors }) })))] }))); }; export default DateTimeConstraintValidation;