@experium/findy-form 1.1.456 → 1.1.457

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.
package/.travis.yml CHANGED
@@ -16,7 +16,7 @@ jobs:
16
16
  skip_cleanup: true
17
17
  edge: true
18
18
  provider: script
19
- script: "cp .npmrc.template $HOME/.npmrc && npm version 1.1.456 && npm publish"
19
+ script: "cp .npmrc.template $HOME/.npmrc && npm version 1.1.457 && npm publish"
20
20
  on:
21
21
  branch: master
22
22
  - stage: deploy gh pages
@@ -102,19 +102,17 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
102
102
  value: null
103
103
  });
104
104
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "setValues", function () {
105
- if (_this.props.getOpdValues) {
106
- var values = _this.props.getOpdValues();
105
+ var values = _this.props.getOpdValues();
107
106
 
108
- var inputs = _this.form.querySelectorAll('input');
107
+ var inputs = _this.form.querySelectorAll('input');
109
108
 
110
- (0, _ramda.forEach)(function (input) {
111
- var value = (0, _ramda.path)([input.name], values);
109
+ (0, _ramda.forEach)(function (input) {
110
+ var value = (0, _ramda.path)([input.name], values);
112
111
 
113
- if (value) {
114
- input.setAttribute('value', (0, _ramda.trim)("".concat(value || '')));
115
- }
116
- }, inputs);
117
- }
112
+ if (value) {
113
+ input.setAttribute('value', (0, _ramda.trim)("".concat(value || '')));
114
+ }
115
+ }, inputs);
118
116
  });
119
117
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "scrollToInvalid", function () {
120
118
  var invalidInput = document.querySelector('.opd-html-form input:invalid');
@@ -205,7 +203,8 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
205
203
  formProps = _this$props.formProps,
206
204
  t = _this$props.t,
207
205
  htmlAttrs = _this$props.htmlAttrs,
208
- onClose = _this$props.onClose;
206
+ onClose = _this$props.onClose,
207
+ acceptBtn = _this$props.acceptBtn;
209
208
  var html = this.state.value || this.props.html;
210
209
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
211
210
  ref: function ref(node) {
@@ -248,7 +247,7 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
248
247
  onClick: function onClick() {
249
248
  return _this2.onSubmit(formProps);
250
249
  }
251
- }, (0, _attrs.getAttrs)('opdAccept', htmlAttrs)), t('opdFormAccept')))));
250
+ }, (0, _attrs.getAttrs)('opdAccept', htmlAttrs)), acceptBtn || t('opdFormAccept')))));
252
251
  }
253
252
  }]);
254
253
  return HtmlOpdForm;
@@ -81,6 +81,33 @@ var styles = {
81
81
  "modalButtonGroup": "index__modalButtonGroup"
82
82
  };
83
83
 
84
+ var getConstructorOpd = function getConstructorOpd(opdSettings) {
85
+ var opdConstructor = (0, _ramda.pathOr)([], ['data', 'opdConstructor'], opdSettings);
86
+ var text = opdConstructor.reduce(function (res, cur) {
87
+ switch (cur.type) {
88
+ case 'text':
89
+ return "".concat(res + cur.text, " ");
90
+
91
+ case 'question':
92
+ return "".concat(res, "<input name=\"").concat(cur.question, "\" placeholder=\"").concat(cur.placeholder ? (0, _ramda.toLower)(cur.placeholder) : '', "\" type=\"text\" ").concat(cur.required ? 'required' : '', " /> ");
93
+
94
+ case 'link':
95
+ return "".concat(res, "<a href=\"").concat(cur.link, "\" target=\"_blank\">").concat(cur.text, "</a> ");
96
+
97
+ case 'formated':
98
+ return res + cur.text;
99
+
100
+ default:
101
+ return res;
102
+ }
103
+ }, '');
104
+ return "<div>\n ".concat(text, "\n ").concat((0, _ramda.path)(['purposeCheckbox', 'active'], opdSettings) ? "<p><label><input name=\"opdPurpose\" type=\"checkbox\" data-separate-field=\"opdPurpose\" ".concat((0, _ramda.path)(['purposeCheckbox', 'required'], opdSettings) ? 'required' : '', " />").concat((0, _ramda.path)(['purposeCheckbox', 'label'], opdSettings) || 'я выражаю согласие на обработку персональных данных для цели рассмотрения вопроса о моем трудоустройстве в Компании и включения в кадровый резерв Компании', "</label></p>") : '', "\n ").concat((0, _ramda.path)(['acceptCheckbox', 'active'], opdSettings) ? "<p><label><input name=\"opdAccept\" type=\"checkbox\" data-separate-field=\"opdAccept\" ".concat((0, _ramda.path)(['acceptCheckbox', 'required'], opdSettings) ? 'required' : '', " />").concat((0, _ramda.path)(['acceptCheckbox', 'label'], opdSettings) || 'я выражаю согласие на передачу моих персональных данных в организацию', "</label></p>") : '', "\n ").concat((0, _ramda.path)(['transmissionCheckbox', 'active'], opdSettings) ? "<p><label><input name=\"transmission\" type=\"checkbox\" data-separate-field=\"transmission\" ".concat((0, _ramda.path)(['transmissionCheckbox', 'required'], opdSettings) ? 'required' : '', " />").concat((0, _ramda.path)(['transmissionCheckbox', 'label'], opdSettings) || 'я выражаю согласие на трансграничную передачу моих персональных данных', "</label></p>") : '', "\n ").concat((0, _ramda.path)(['mailingCheckbox', 'active'], opdSettings) ? "<p><label><input name=\"mailing\" type=\"checkbox\" data-separate-field=\"mailing\" ".concat((0, _ramda.path)(['mailingCheckbox', 'required'], opdSettings) ? 'required' : '', " />").concat((0, _ramda.path)(['mailingCheckbox', 'label'], opdSettings) || 'я выражаю согласие на получение рассылки материалов рекламного и/или информационного характера посредством SMS-сервисов, Viber, WhatsApp, Telegram, Skype и других месcенджеров, электронной почты и т.д.', "</label></p>") : '', "\n ").concat((0, _ramda.filter)(function (i) {
105
+ return !!i.show;
106
+ }, (0, _ramda.pathOr)([], ['data', 'checkboxes'], opdSettings)).reduce(function (res, cur, index) {
107
+ return "".concat(res, "<p><label><input name=\"checkbox-").concat(index, "\" type=\"checkbox\" ").concat(cur.required ? 'required' : '', " />").concat(cur.label, "</label></p>");
108
+ }, ''), "\n </div>");
109
+ };
110
+
84
111
  var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
85
112
  (0, _inherits2["default"])(PersonalDataAgreementComponent, _Component);
86
113
 
@@ -169,6 +196,25 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
169
196
  openedHtml: false
170
197
  });
171
198
  });
199
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getOpdValues", function (formProps) {
200
+ var _this$props2 = _this.props,
201
+ opdSettings = _this$props2.opdSettings,
202
+ getOpdValues = _this$props2.getOpdValues;
203
+
204
+ if (getOpdValues) {
205
+ return getOpdValues(formProps);
206
+ }
207
+
208
+ if ((0, _ramda.path)(['useConstructor'], opdSettings)) {
209
+ return (0, _ramda.pick)((0, _ramda.filter)(function (field) {
210
+ return (0, _ramda.find)(function (i) {
211
+ return i.type === 'question' && i.question === field;
212
+ }, (0, _ramda.pathOr)([], ['data', 'opdConstructor'], opdSettings));
213
+ }, ['firstName', 'lastName', 'middleName', 'phone', 'email', 'district', 'address', 'webpage', 'messanger', 'birthDate']), formProps.values);
214
+ }
215
+
216
+ return {};
217
+ });
172
218
  return _this;
173
219
  }
174
220
 
@@ -177,18 +223,20 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
177
223
  value: function render() {
178
224
  var _this2 = this;
179
225
 
226
+ var opdSettings = this.props.opdSettings;
227
+ var constructorOpd = (0, _ramda.path)(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings) : null;
180
228
  return /*#__PURE__*/_react["default"].createElement(_FormContext.FormContext.Consumer, null, function (_ref) {
181
229
  var htmlAttrs = _ref.htmlAttrs;
182
230
  return /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement(_Checkbox.Checkbox, (0, _extends2["default"])({
183
231
  id: 'opdCheckbox'
184
232
  }, _this2.props, {
185
- onValueChange: _this2.props.htmlOpd ? _this2.onChange : null,
233
+ onValueChange: _this2.props.htmlOpd || constructorOpd ? _this2.onChange : null,
186
234
  options: [{
187
235
  value: true,
188
236
  label: _this2.getLabel()
189
237
  }],
190
238
  htmlAttrs: (0, _attrs.getAttrs)('opdCheckbox', htmlAttrs)
191
- })), _this2.props.htmlOpd && /*#__PURE__*/_react["default"].createElement(_reactResponsiveModal["default"], {
239
+ })), (_this2.props.htmlOpd || constructorOpd) && /*#__PURE__*/_react["default"].createElement(_reactResponsiveModal["default"], {
192
240
  open: _this2.state.openedHtml,
193
241
  onClose: _this2.closeHtml,
194
242
  classNames: {
@@ -205,10 +253,11 @@ var PersonalDataAgreementComponent = /*#__PURE__*/function (_Component) {
205
253
  value: _this2.props.input.value,
206
254
  formProps: formProps,
207
255
  getOpdValues: function getOpdValues() {
208
- return _this2.props.getOpdValues && _this2.props.getOpdValues(formProps);
256
+ return _this2.getOpdValues(formProps);
209
257
  },
210
258
  htmlAttrs: htmlAttrs,
211
- html: _this2.props.htmlOpd
259
+ html: _this2.props.htmlOpd || constructorOpd,
260
+ acceptBtn: (0, _ramda.path)(['acceptButtonLabel'], opdSettings)
212
261
  });
213
262
  })));
214
263
  });
@@ -204,8 +204,9 @@ var rules = {
204
204
  });
205
205
  },
206
206
  personalDataAgreement: function personalDataAgreement(field, _ref3) {
207
- var htmlOpd = _ref3.htmlOpd;
208
- return htmlOpd ? yup.string() : yup["boolean"]();
207
+ var htmlOpd = _ref3.htmlOpd,
208
+ opdSettings = _ref3.opdSettings;
209
+ return htmlOpd || (0, _ramda.path)(['useConstructor'], opdSettings) ? yup.string() : yup["boolean"]();
209
210
  },
210
211
  "boolean": function boolean(field) {
211
212
  return yup["boolean"]();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.1.456",
3
+ "version": "1.1.457",
4
4
  "main": "./lib/index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -92,17 +92,15 @@ class HtmlOpdForm extends Component {
92
92
  }
93
93
 
94
94
  setValues = () => {
95
- if (this.props.getOpdValues) {
96
- const values = this.props.getOpdValues();
97
- const inputs = this.form.querySelectorAll('input');
95
+ const values = this.props.getOpdValues();
96
+ const inputs = this.form.querySelectorAll('input');
98
97
 
99
- forEach(input => {
100
- const value = path([input.name], values);
101
- if (value) {
102
- input.setAttribute('value', trim(`${value || ''}`));
103
- }
104
- }, inputs);
105
- }
98
+ forEach(input => {
99
+ const value = path([input.name], values);
100
+ if (value) {
101
+ input.setAttribute('value', trim(`${value || ''}`));
102
+ }
103
+ }, inputs);
106
104
  }
107
105
 
108
106
  scrollToInvalid = () => {
@@ -164,7 +162,7 @@ class HtmlOpdForm extends Component {
164
162
  }
165
163
 
166
164
  render() {
167
- const { formProps, t, htmlAttrs, onClose } = this.props;
165
+ const { formProps, t, htmlAttrs, onClose, acceptBtn } = this.props;
168
166
  const html = this.state.value || this.props.html;
169
167
 
170
168
  return <Fragment>
@@ -179,7 +177,7 @@ class HtmlOpdForm extends Component {
179
177
  <div className={cx('opd-html-form', { submitted: this.state.submitted })} dangerouslySetInnerHTML={{ __html: html }} />
180
178
 
181
179
  <button className={`${styles.formBtn} form-button`} type='button' onClick={() => this.onSubmit(formProps)} {...getAttrs('opdAccept', htmlAttrs)}>
182
- {t('opdFormAccept')}
180
+ { acceptBtn || t('opdFormAccept') }
183
181
  </button>
184
182
  </form>
185
183
  </div>
@@ -2,7 +2,7 @@ import React, { Component, Fragment } from 'react';
2
2
  import Modal from 'react-responsive-modal';
3
3
  import { withTranslation } from 'react-i18next';
4
4
  import { FormSpy } from 'react-final-form';
5
- import { path, pathOr } from 'ramda';
5
+ import { filter, find, path, pathOr, pick, toLower } from 'ramda';
6
6
 
7
7
  import 'rc-checkbox/assets/index.css';
8
8
  import 'react-responsive-modal/styles.css';
@@ -13,6 +13,34 @@ import HtmlOpdForm from './HtmlOpdForm';
13
13
  import { FormContext } from '../../context/FormContext';
14
14
  import { getAttrs } from '../../utils/attrs';
15
15
 
16
+ const getConstructorOpd = opdSettings => {
17
+ const opdConstructor = pathOr([], ['data', 'opdConstructor'], opdSettings);
18
+
19
+ const text = opdConstructor.reduce((res, cur) => {
20
+ switch (cur.type) {
21
+ case 'text':
22
+ return `${res + cur.text} `;
23
+ case 'question':
24
+ return `${res}<input name="${cur.question}" placeholder="${cur.placeholder ? toLower(cur.placeholder) : ''}" type="text" ${cur.required ? 'required' : ''} /> `;
25
+ case 'link':
26
+ return `${res}<a href="${cur.link}" target="_blank">${cur.text}</a> `;
27
+ case 'formated':
28
+ return res + cur.text;
29
+ default:
30
+ return res;
31
+ }
32
+ }, '');
33
+
34
+ return `<div>
35
+ ${text}
36
+ ${path(['purposeCheckbox', 'active'], opdSettings) ? `<p><label><input name="opdPurpose" type="checkbox" data-separate-field="opdPurpose" ${path(['purposeCheckbox', 'required'], opdSettings) ? 'required' : ''} />${path(['purposeCheckbox', 'label'], opdSettings) || 'я выражаю согласие на обработку персональных данных для цели рассмотрения вопроса о моем трудоустройстве в Компании и включения в кадровый резерв Компании'}</label></p>` : ''}
37
+ ${path(['acceptCheckbox', 'active'], opdSettings) ? `<p><label><input name="opdAccept" type="checkbox" data-separate-field="opdAccept" ${path(['acceptCheckbox', 'required'], opdSettings) ? 'required' : ''} />${path(['acceptCheckbox', 'label'], opdSettings) || 'я выражаю согласие на передачу моих персональных данных в организацию'}</label></p>` : ''}
38
+ ${path(['transmissionCheckbox', 'active'], opdSettings) ? `<p><label><input name="transmission" type="checkbox" data-separate-field="transmission" ${path(['transmissionCheckbox', 'required'], opdSettings) ? 'required' : ''} />${path(['transmissionCheckbox', 'label'], opdSettings) || 'я выражаю согласие на трансграничную передачу моих персональных данных'}</label></p>` : ''}
39
+ ${path(['mailingCheckbox', 'active'], opdSettings) ? `<p><label><input name="mailing" type="checkbox" data-separate-field="mailing" ${path(['mailingCheckbox', 'required'], opdSettings) ? 'required' : ''} />${path(['mailingCheckbox', 'label'], opdSettings) || 'я выражаю согласие на получение рассылки материалов рекламного и/или информационного характера посредством SMS-сервисов, Viber, WhatsApp, Telegram, Skype и других месcенджеров, электронной почты и т.д.'}</label></p>` : ''}
40
+ ${filter(i => !!i.show, pathOr([], ['data', 'checkboxes'], opdSettings)).reduce((res, cur, index) => `${res}<p><label><input name="checkbox-${index}" type="checkbox" ${cur.required ? 'required' : ''} />${cur.label}</label></p>`, '')}
41
+ </div>`;
42
+ };
43
+
16
44
  class PersonalDataAgreementComponent extends Component {
17
45
  state = {
18
46
  opened: false,
@@ -92,20 +120,39 @@ class PersonalDataAgreementComponent extends Component {
92
120
  this.setState({ openedHtml: false });
93
121
  }
94
122
 
123
+ getOpdValues = formProps => {
124
+ const { opdSettings, getOpdValues } = this.props;
125
+
126
+ if (getOpdValues) {
127
+ return getOpdValues(formProps);
128
+ }
129
+
130
+ if (path(['useConstructor'], opdSettings)) {
131
+ return pick(filter(field => find(i => i.type === 'question' && i.question === field, pathOr([], ['data', 'opdConstructor'], opdSettings)), [
132
+ 'firstName', 'lastName', 'middleName', 'phone', 'email', 'district', 'address', 'webpage', 'messanger', 'birthDate'
133
+ ]), formProps.values);
134
+ }
135
+
136
+ return {};
137
+ }
138
+
95
139
  render() {
140
+ const { opdSettings } = this.props;
141
+ const constructorOpd = path(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings) : null;
142
+
96
143
  return <FormContext.Consumer>{ ({ htmlAttrs }) => (
97
144
  <Fragment>
98
145
  <Checkbox
99
146
  id={'opdCheckbox'}
100
147
  {...this.props}
101
- onValueChange={this.props.htmlOpd ? this.onChange : null}
148
+ onValueChange={(this.props.htmlOpd || constructorOpd) ? this.onChange : null}
102
149
  options={[{
103
150
  value: true,
104
151
  label: this.getLabel()
105
152
  }]}
106
153
  htmlAttrs={getAttrs('opdCheckbox', htmlAttrs)}
107
154
  />
108
- { this.props.htmlOpd &&
155
+ { (this.props.htmlOpd || constructorOpd) &&
109
156
  <Modal
110
157
  open={this.state.openedHtml}
111
158
  onClose={this.closeHtml}
@@ -124,9 +171,10 @@ class PersonalDataAgreementComponent extends Component {
124
171
  onClose={this.closeHtml}
125
172
  value={this.props.input.value}
126
173
  formProps={formProps}
127
- getOpdValues={() => this.props.getOpdValues && this.props.getOpdValues(formProps)}
174
+ getOpdValues={() => this.getOpdValues(formProps)}
128
175
  htmlAttrs={htmlAttrs}
129
- html={this.props.htmlOpd} />
176
+ html={this.props.htmlOpd || constructorOpd}
177
+ acceptBtn={path(['acceptButtonLabel'], opdSettings)} />
130
178
  )}
131
179
  </FormSpy>
132
180
  </Modal>
@@ -166,7 +166,7 @@ const rules = {
166
166
  return value.length <= maxLength;
167
167
  }
168
168
  }),
169
- personalDataAgreement: (field, { htmlOpd }) => htmlOpd ? yup.string() : yup.boolean(),
169
+ personalDataAgreement: (field, { htmlOpd, opdSettings }) => htmlOpd || path(['useConstructor'], opdSettings) ? yup.string() : yup.boolean(),
170
170
  boolean: field => yup.boolean(),
171
171
  choice: field => path(['settings', 'multiple'], field) ? yup.array() : yup.string(),
172
172
  file: (field, { allowFileExtensions }) => yup.mixed().test({