@experium/findy-form 1.3.26 → 1.3.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -98,6 +98,17 @@ var styles = {
98
98
  "timeIndicator": "index__timeIndicator",
99
99
  "modalButtonGroup": "index__modalButtonGroup"
100
100
  };
101
+ var OPD_FIELD = 'personalDataAgreement';
102
+ var OPD_DATA_CHECKBOX = {
103
+ 'accept': true,
104
+ 'acceptCheckbox': true,
105
+ 'value': true
106
+ };
107
+ var OPD_DATA_CHECKBOXES = {
108
+ 'purposeCheckbox': 'purpose',
109
+ 'mailingCheckbox': 'mailing',
110
+ 'transmissionCheckbox': 'transmission'
111
+ };
101
112
 
102
113
  var getInitialValues = function getInitialValues(initialValues, fields, captchaOptions) {
103
114
  var values = initialValues || {};
@@ -205,6 +216,17 @@ var Form = /*#__PURE__*/function (_Component) {
205
216
  submitted: true
206
217
  });
207
218
 
219
+ if ((0, _ramda.equals)(values[OPD_FIELD], true) && !values[OPD_FIELD].value) {
220
+ values[OPD_FIELD] = OPD_DATA_CHECKBOX;
221
+ }
222
+
223
+ (0, _ramda.mapObjIndexed)(function (value, name) {
224
+ if (OPD_DATA_CHECKBOXES[name]) {
225
+ values[OPD_FIELD][name] = value;
226
+ values[OPD_FIELD][OPD_DATA_CHECKBOXES[name]] = value;
227
+ }
228
+ }, values);
229
+
208
230
  _this.props.onSubmit(values, _objectSpread(_objectSpread({}, _this.formProps), {}, {
209
231
  reset: _this.reset
210
232
  }));
@@ -7,7 +7,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports["default"] = exports.HtmlOpdFormClear = exports.getHtml = void 0;
10
+ exports["default"] = exports.getHtml = void 0;
11
11
 
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
13
 
@@ -304,34 +304,6 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
304
304
  return HtmlOpdForm;
305
305
  }(_react.Component);
306
306
 
307
- var HtmlOpdFormClear = /*#__PURE__*/function (_Component2) {
308
- (0, _inherits2["default"])(HtmlOpdFormClear, _Component2);
309
-
310
- var _super2 = _createSuper(HtmlOpdFormClear);
311
-
312
- function HtmlOpdFormClear() {
313
- (0, _classCallCheck2["default"])(this, HtmlOpdFormClear);
314
- return _super2.apply(this, arguments);
315
- }
316
-
317
- (0, _createClass2["default"])(HtmlOpdFormClear, [{
318
- key: "componentDidUpdate",
319
- value: function componentDidUpdate(prevProps) {
320
- if (prevProps.value && !prevProps.open && !(0, _ramda.equals)(prevProps.values, this.props.values)) {
321
- this.props.onSubmitHtml();
322
- }
323
- }
324
- }, {
325
- key: "render",
326
- value: function render() {
327
- return null;
328
- }
329
- }]);
330
- return HtmlOpdFormClear;
331
- }(_react.Component);
332
-
333
- exports.HtmlOpdFormClear = HtmlOpdFormClear;
334
-
335
307
  var _default = (0, _reactI18next.withTranslation)()(HtmlOpdForm);
336
308
 
337
309
  exports["default"] = _default;
@@ -37,7 +37,7 @@ var _ramda = require("ramda");
37
37
 
38
38
  var _Checkbox = require("./Checkbox");
39
39
 
40
- var _HtmlOpdForm = _interopRequireWildcard(require("./HtmlOpdForm"));
40
+ var _HtmlOpdForm = _interopRequireDefault(require("./HtmlOpdForm"));
41
41
 
42
42
  var _FormContext = require("../../context/FormContext");
43
43
 
@@ -283,16 +283,7 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
283
283
  label: _this2.getLabel()
284
284
  }],
285
285
  htmlAttrs: (0, _attrs.getAttrs)('opdCheckbox', htmlAttrs)
286
- })), isHtmlOpd && /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_reactFinalForm.FormSpy, {
287
- subscription: ['values']
288
- }, function (formProps) {
289
- return /*#__PURE__*/_react["default"].createElement(_HtmlOpdForm.HtmlOpdFormClear, {
290
- open: _this2.state.openedHtml,
291
- value: _this2.props.input.value,
292
- values: _this2.getOpdValues(formProps),
293
- onSubmitHtml: _this2.onSubmitHtml
294
- });
295
- }), /*#__PURE__*/_react["default"].createElement(_reactResponsiveModal["default"], {
286
+ })), isHtmlOpd && /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_reactResponsiveModal["default"], {
296
287
  open: _this2.state.openedHtml,
297
288
  onClose: _this2.closeHtml,
298
289
  classNames: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.3.26",
3
+ "version": "1.3.29",
4
4
  "main": "./lib/index.js",
5
5
  "homepage": "https://experium.github.io/findy-form",
6
6
  "repository": "https://github.com/experium/findy-form",
@@ -5,7 +5,7 @@ import i18n from '../utils/i18n';
5
5
 
6
6
  import React, { Component } from 'react';
7
7
  import { Form as FinalFormForm, Field, FormSpy } from 'react-final-form';
8
- import { head, pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath } from 'ramda';
8
+ import { head, pathOr, prop, equals, isEmpty, forEach, path, includes, assocPath, mapObjIndexed } from 'ramda';
9
9
  import arrayMutators from 'final-form-arrays';
10
10
  import { withTranslation } from 'react-i18next';
11
11
  import cx from 'classnames';
@@ -23,6 +23,18 @@ import Fields from './Fields';
23
23
  import Spinner from './formComponents/Spinner';
24
24
  import Captcha from './formComponents/Captcha';
25
25
 
26
+ const OPD_FIELD = 'personalDataAgreement';
27
+ const OPD_DATA_CHECKBOX = {
28
+ 'accept': true,
29
+ 'acceptCheckbox': true,
30
+ 'value': true,
31
+ };
32
+ const OPD_DATA_CHECKBOXES = {
33
+ 'purposeCheckbox': 'purpose',
34
+ 'mailingCheckbox': 'mailing',
35
+ 'transmissionCheckbox': 'transmission',
36
+ };
37
+
26
38
  const getInitialValues = (initialValues, fields, captchaOptions) => {
27
39
  let values = initialValues || {};
28
40
 
@@ -156,6 +168,18 @@ class Form extends Component {
156
168
 
157
169
  onSubmit = values => {
158
170
  this.setState({ submitted: true });
171
+
172
+ if (equals(values[OPD_FIELD], true) && !values[OPD_FIELD].value) {
173
+ values[OPD_FIELD] = OPD_DATA_CHECKBOX;
174
+ }
175
+
176
+ mapObjIndexed((value, name) => {
177
+ if (OPD_DATA_CHECKBOXES[name]) {
178
+ values[OPD_FIELD][name] = value;
179
+ values[OPD_FIELD][OPD_DATA_CHECKBOXES[name]] = value;
180
+ }
181
+ }, values);
182
+
159
183
  this.props.onSubmit(values, { ...this.formProps, reset: this.reset });
160
184
  };
161
185
 
@@ -1,6 +1,6 @@
1
1
  import React, { Component, Fragment } from 'react';
2
2
  import { withTranslation } from 'react-i18next';
3
- import { all, equals, join, find, forEach, map, includes, is, path, propEq, trim } from 'ramda';
3
+ import { all, join, find, forEach, map, includes, is, path, propEq, trim } from 'ramda';
4
4
  import cx from 'classnames';
5
5
 
6
6
  import styles from '../../styles/index.module.css';
@@ -287,16 +287,4 @@ class HtmlOpdForm extends Component {
287
287
  }
288
288
  }
289
289
 
290
- export class HtmlOpdFormClear extends Component {
291
- componentDidUpdate(prevProps) {
292
- if (prevProps.value && !prevProps.open && !equals(prevProps.values, this.props.values)) {
293
- this.props.onSubmitHtml();
294
- }
295
- }
296
-
297
- render() {
298
- return null;
299
- }
300
- }
301
-
302
290
  export default withTranslation()(HtmlOpdForm);
@@ -6,7 +6,7 @@ import { filter, find, map, path, pathOr, prop, pick } from 'ramda';
6
6
 
7
7
  import { Checkbox } from './Checkbox';
8
8
  import styles from '../../styles/index.module.css';
9
- import HtmlOpdForm, { HtmlOpdFormClear } from './HtmlOpdForm';
9
+ import HtmlOpdForm from './HtmlOpdForm';
10
10
  import { FormContext } from '../../context/FormContext';
11
11
  import { getAttrs } from '../../utils/attrs';
12
12
 
@@ -203,16 +203,6 @@ class PersonalDataAgreementComponent extends Component {
203
203
  />
204
204
  { isHtmlOpd &&
205
205
  <Fragment>
206
- <FormSpy subscription={['values']}>
207
- { formProps => (
208
- <HtmlOpdFormClear
209
- open={this.state.openedHtml}
210
- value={this.props.input.value}
211
- values={this.getOpdValues(formProps)}
212
- onSubmitHtml={this.onSubmitHtml}
213
- />
214
- )}
215
- </FormSpy>
216
206
  <Modal
217
207
  open={this.state.openedHtml}
218
208
  onClose={this.closeHtml}