@open-formulieren/formio-builder
Version:
An opinionated Formio webform builder for Open Forms
20 lines (19 loc) • 2.02 kB
JavaScript
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 FixedValueDateField from './fixed-value-datefield';
import IncludeToday from './include-today';
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 DateConstraintValidation = ({ 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(FixedValueDateField, { constraint: constraint }), ['future', 'past'].includes(mode) && _jsx(IncludeToday, { 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 DateConstraintValidation;