@experium/findy-form 1.1.457 → 1.2.1

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.
@@ -1,8 +1,9 @@
1
1
  import React, { Component } from 'react';
2
- import { prop, append, remove, isEmpty, path, pathOr, join, values } from 'ramda';
2
+ import { prop, append, remove, isEmpty, path, pathOr, join, values, keys, last } from 'ramda';
3
3
  import Modal from 'react-responsive-modal';
4
4
  import { withTranslation } from 'react-i18next';
5
5
  import getusermedia from 'getusermedia';
6
+ import axios from 'axios';
6
7
 
7
8
  import withFieldWrapper from '../hocs/withFieldWrapper';
8
9
  import ImageFile from './ImageFile';
@@ -12,7 +13,7 @@ import styles from '../../styles/index.module.css';
12
13
  import formStyles from '../../styles/index.module.css';
13
14
  import Spinner from './Spinner';
14
15
  import { getFileErrorText } from '../../utils/file';
15
- import { TYPES } from '../../constants/allowFileExtensions';
16
+ import { TYPES, defaultAllowFileExtensions } from '../../constants/allowFileExtensions';
16
17
  import { checkFileType, getFileTypeMessage } from '../../utils/validation';
17
18
 
18
19
  const FILE_TYPES = {
@@ -55,8 +56,9 @@ class File extends Component {
55
56
  const multiple = prop('multiple', settings);
56
57
  const type = prop('type', settings);
57
58
  const fd = new FormData();
58
-
59
- const validFileType = checkFileType(type, file.type, allowFileExtensions);
59
+ const fileExtenstion = last(`${file.name}`.split('.'));
60
+ const fileType = file.type || path([type, fileExtenstion], defaultAllowFileExtensions);
61
+ const validFileType = checkFileType(type, file.type, fileExtenstion, allowFileExtensions);
60
62
 
61
63
  fd.append('file', file);
62
64
  fd.append('name', file.name);
@@ -65,18 +67,16 @@ class File extends Component {
65
67
  this.setState({ loading: true, error: false });
66
68
  setInputError(undefined);
67
69
 
68
- fetch(postFileUrl, {
69
- method: 'POST',
70
- body: fd
70
+ axios.post(postFileUrl, fd, {
71
+ headers: {
72
+ 'Content-Type': 'multipart/form-data',
73
+ },
71
74
  })
72
75
  .then(response => {
73
- if (!response.ok && response.status !== 400) {
74
- throw new Error();
75
- } else {
76
- return response.json();
77
- }
78
- })
79
- .then(data => {
76
+ const { data } = response;
77
+ const { input: { name } } = this.props;
78
+ const fileName = data.filename;
79
+
80
80
  if (data.statusCode === 400) {
81
81
  setInputError(getFileErrorText(data.message));
82
82
  return this.setState({ error: data.message || true, loading: false });
@@ -86,15 +86,14 @@ class File extends Component {
86
86
  return this.setState({ error: true, loading: false });
87
87
  }
88
88
 
89
- const { input: { name } } = this.props;
90
- const fileName = data.filename;
91
89
  const url = getFileUrl ? getFileUrl(data.id) : data.id;
92
90
  this.setState({ loading: false });
93
91
 
94
92
  const fileItem = {
95
93
  url,
96
94
  text: fileName,
97
- contentType: file.type,
95
+ extenstion: fileExtenstion,
96
+ contentType: fileType,
98
97
  type,
99
98
  };
100
99
 
@@ -112,13 +111,14 @@ class File extends Component {
112
111
  }
113
112
  })
114
113
  .catch((error) => {
115
- setInputError(getFileErrorText(error));
114
+ setInputError(getFileErrorText(pathOr('', ['response', 'data', 'message'], error)));
116
115
  this.setState({ error: true });
117
116
  });
118
117
  } else {
119
118
  const fileItem = {
120
119
  text: file.name,
121
- contentType: file.type,
120
+ extenstion: fileExtenstion,
121
+ contentType: fileType,
122
122
  type,
123
123
  };
124
124
 
@@ -250,7 +250,7 @@ class File extends Component {
250
250
 
251
251
  if (allowFileExtensions) {
252
252
  return allowFileExtensions[type] ? (
253
- join(',', values(allowFileExtensions[type]))
253
+ `.${join(', .', keys(allowFileExtensions[type]))}`
254
254
  ) : TYPES[type];
255
255
  } else {
256
256
  return TYPES[type];
@@ -305,10 +305,10 @@ class File extends Component {
305
305
  value=''
306
306
  onChange={this.onChange}
307
307
  accept={this.getAccept(type)}
308
- disabled={disabled || loading && !error}
308
+ disabled={disabled || (loading && !error)}
309
309
  />
310
310
  <label htmlFor={name} className={`${disabled ? 'disabled' : ''}`}>
311
- { loading && !error && <Spinner /> }
311
+ { (loading && !error) && <Spinner /> }
312
312
  <span className='button-text'>
313
313
  {t('upload')}
314
314
  </span>
@@ -1,6 +1,6 @@
1
1
  import React, { Component, Fragment } from 'react';
2
2
  import { withTranslation } from 'react-i18next';
3
- import { all, forEach, is, path, trim } from 'ramda';
3
+ import { all, equals, 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';
@@ -11,12 +11,17 @@ import { EMAIL_EXPERIUM } from '../../constants/regexps';
11
11
  const commonStyle = `
12
12
  .opd-html-form {
13
13
  line-height: 20px;
14
+ margin-bottom: 24px;
14
15
  }
15
16
  .opd-html-form input {
16
17
  border: none;
17
18
  border-bottom: 1px solid #000;
18
19
  font-size: 16px;
19
20
  pointer-events: auto;
21
+ margin: 4px 0;
22
+ appearance: none;
23
+ -moz-appearance: none;
24
+ -webkit-appearance: none;
20
25
  }
21
26
  .opd-html-form label {
22
27
  pointer-events: auto;
@@ -27,9 +32,39 @@ const commonStyle = `
27
32
  .opd-html-form.submitted input:invalid {
28
33
  border-bottom: 1px solid red;
29
34
  }
35
+ .opd-html-form label{
36
+ cursor: pointer;
37
+ }
30
38
  .opd-html-form input[type="checkbox"] {
31
39
  position: relative;
32
- margin-right: 10px;
40
+ margin-right: 8px;
41
+ margin-bottom: -2px;
42
+ border: 1px solid #ccc;
43
+ appearance: none;
44
+ width: 18px;
45
+ height: 18px;
46
+ border-radius: 2px;
47
+ }
48
+ .opd-html-form input[type="checkbox"]:checked {
49
+ background: #3a70bb;
50
+ border-color: #3a70bb;
51
+ }
52
+ .opd-html-form input[type="checkbox"]:checked:before {
53
+ background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAAAXNSR0IArs4c6QAAA21JREFUaEPtmF3oVUUUxX+rsOiD6MMgiSQMIYIyEE3wIzERBQmzIKiwBCnxwUTEerAX66UkwkwoiCALIujLIKO0IoIKKnqoXrTHfMgHQ8oEy5ZsHU2u556Zc/733v/9w53Xs2Zmrb337DVzxAQfmuD8GQkY7wyOMjDKQEcEbC8G3gR2As9Icl2QhqqEbN8A/ABcm0jvAR6S9Ec3EUMjwPYk4AtgbgfZX4GVkn6qEjFMAl4GHusS6b+ANZLe7vw+FAJsrwJezzSEOAv3SXrvXNy4C7A9A/gGuCQj4AQwX1Jgz45xFWD7SuB74KaCdvykpGeHpoRsR/DeBe4pIP8hsKKqpY5bBmxvAZ4uIH8AmCXpyNB0Idt3AZ8AF2YEHIu2KunHofGBCrOq0/CIpNruNNASsn0x8FWUREHp7JC0PocbtIBXgEdzpIBvgTslHc9hBybA9oPpkpbjdAiYKem3HDC+D0SA7duSWV1aYFbLJO0tIT8QAbavAr4rNKsnJD1XSr5IQDKctVGXde2salPbFwC7geUFpN4H7s3d/xs7se1twCbgKHC3pM8LyJyC2H4K2FqArzWruvm1Z8B2OGU45pnxd1i/pE9zpBqYVQRmjqSfc2s2cmLbG4AXKiZFa7tf0gfdNrQ9Nb2sJheQeljSrgJcJaQyA7bXAS/VdKl/gAckvdO5akOzelHS423JVx5i20uAj4E4gHXjX2C1pHiAnx22S83qa2ChpAhG63FeBmwvAKIPX1Sw6n/xDJT0ajq0q4HXCub9nszqYAG2FtKthJalu3rulXSKN7AxPcgjqj03qzoFXbtQ6iLRwy8rjNJh4OoC7GZJ0Zp7MnJtdB7wEXBFT3Y7bWrRhmt/VjXZK3sXsj0zPT6uabJwBXY/MLvby6rt2lkB6XDeAuwDprTcKMzqDkm/tJzfdVqRgCTi5iTi+hYkVkl6o8W87JRiAUnEjcBnwLTsyv8DtksKV+/LaCQgiYhrQpTT9AJG8RMqzCr7sipYqxLSWEAScR0QF7pbazbumVnViWslIImIX+Ah4vaKDeKasVjSl20jWzqvtYAkIn4Nxr1pTseGmyQ9X0piLLgxCUgiLk+vrkWJSM/Nqi8ldO6ituO68RYQZrdU0p9jiWqTuWPOQJPN+oEdCehHVJusOcpAk2j1AzvhM3ASm876Mart7QEAAAAASUVORK5CYII=");
54
+ position: absolute;
55
+ left: 0;
56
+ top: 0;
57
+ right: 0;
58
+ bottom: 0;
59
+ content: '';
60
+ display: table-cell;
61
+ border-top: 0;
62
+ border-left: 0;
63
+ width: 16px;
64
+ height: 16px;
65
+ background-size: 12px;
66
+ background-repeat: no-repeat;
67
+ background-position: center;
33
68
  }
34
69
  .opd-html-form input[type="checkbox"]:required::after {
35
70
  content: "*";
@@ -38,6 +73,25 @@ const commonStyle = `
38
73
  right: -8px;
39
74
  position: absolute;
40
75
  }
76
+ .opd-html-form.submitted input[type="checkbox"]:invalid {
77
+ border-color: red;
78
+ }
79
+ .opd-html-form > div > div {
80
+ margin: 4px 0;
81
+ }
82
+ .opd-html-form > div p {
83
+ display: inline-block;
84
+ margin: 4px 0;
85
+ }
86
+ .opd-html-form > div p + p {
87
+ display: block;
88
+ }
89
+ @media screen and (max-width: 991px) {
90
+ .opd-html-form input[type="checkbox"]:checked:before {
91
+ left: 6px;
92
+ top: 3px;
93
+ }
94
+ }
41
95
  `;
42
96
 
43
97
  export const getHtml = body => `
@@ -60,9 +114,6 @@ export const getHtml = body => `
60
114
  .opd-html-form input[type="checkbox"]:required::after {
61
115
  content: "";
62
116
  }
63
- .form-button {
64
- display: none;
65
- }
66
117
  </style>
67
118
  </head>
68
119
  <body>
@@ -73,6 +124,21 @@ export const getHtml = body => `
73
124
  </html>
74
125
  `;
75
126
 
127
+ const TEXT_FIELDS = ['text', 'email', 'phone', 'date'];
128
+ const SELECT_FIELDS = ['dictionary', 'company_dictionary', 'list', 'city', 'country', 'region', 'money'];
129
+ const OPD_DATA_CHECKBOXES = {
130
+ 'accept': 'accept',
131
+ 'acceptCheckbox': 'accept',
132
+ 'opdAccept': 'accept',
133
+ 'purpose': 'purpose',
134
+ 'purposeCheckbox': 'purpose',
135
+ 'opdPurpose': 'purpose',
136
+ 'mailing': 'mailing',
137
+ 'mailingCheckbox': 'mailing',
138
+ 'transmission': 'transmission',
139
+ 'transmissionCheckbox': 'transmission',
140
+ };
141
+
76
142
  class HtmlOpdForm extends Component {
77
143
  state = {
78
144
  submitted: false,
@@ -96,9 +162,33 @@ class HtmlOpdForm extends Component {
96
162
  const inputs = this.form.querySelectorAll('input');
97
163
 
98
164
  forEach(input => {
99
- const value = path([input.name], values);
165
+ const value = trim(`${path([input.name], values) || ''}`);
166
+
100
167
  if (value) {
101
- input.setAttribute('value', trim(`${value || ''}`));
168
+ const field = find(propEq('field', input.name), this.props.formFields);
169
+
170
+ if (!field || includes(field.type, TEXT_FIELDS)) {
171
+ input.value = value;
172
+ input.setAttribute('value', value);
173
+ } else if (field && includes(field.type, SELECT_FIELDS)) {
174
+ const selectValue = path(['settings', 'multiple'], field)
175
+ ? path(['settings', 'checkboxes'], field)
176
+ ? join(', ', map(el => path(['innerHTML'], el), document.querySelectorAll(`#field-${input.name} .rc-checkbox-checked + .checkbox-label`)))
177
+ : join(', ', map(el => path(['innerHTML'], el), document.querySelectorAll(`#field-${input.name} .jobot-forms-rc-select-selection-item-content`)))
178
+ : path(['settings', 'checkboxes'], field)
179
+ ? path(['innerHTML'], document.querySelector(`#field-${input.name} .rc-checkbox-checked + .radio-label`))
180
+ : path(['innerHTML'], document.querySelector(`#field-${input.name} .jobot-forms-rc-select-selection-item`));
181
+
182
+ if (field.type === 'money') {
183
+ const inputValue = document.querySelector(`#field-${input.name} input#${input.name}`).value;
184
+ const moneyValue = `${inputValue || ''} ${selectValue || ''}`;
185
+ input.value = moneyValue;
186
+ input.setAttribute('value', moneyValue);
187
+ } else if (selectValue) {
188
+ input.value = selectValue;
189
+ input.setAttribute('value', selectValue);
190
+ }
191
+ }
102
192
  }
103
193
  }, inputs);
104
194
  }
@@ -146,15 +236,27 @@ class HtmlOpdForm extends Component {
146
236
  }
147
237
  } else {
148
238
  input.setAttribute('value', input.value);
239
+
240
+ const field = find(propEq('field', input.name), this.props.formFields);
241
+ if (field && includes(field.type, TEXT_FIELDS)) {
242
+ form.change(input.name, input.value);
243
+ }
149
244
  }
150
245
 
151
246
  const separateField = input.getAttribute('data-separate-field');
152
247
 
153
248
  if (separateField) {
154
249
  const value = input.type === 'checkbox' ? input.checked : input.value;
155
- values[separateField] = value;
250
+ const id = OPD_DATA_CHECKBOXES[separateField];
251
+ values[id] = value;
156
252
  form.change(separateField, value);
157
253
  }
254
+
255
+ const fixedField = OPD_DATA_CHECKBOXES[input.getAttribute('id')];
256
+ if (fixedField) {
257
+ const value = input.type === 'checkbox' ? input.checked : input.value;
258
+ values[separateField] = value;
259
+ }
158
260
  }, inputs);
159
261
 
160
262
  this.props.onSubmit(getHtml(this.form.innerHTML), values);
@@ -169,20 +271,30 @@ class HtmlOpdForm extends Component {
169
271
  <div>
170
272
  <div ref={node => this.valueHtml = node} style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: path(['value', 'htmlContent'], this.props) }} />
171
273
  <style>{commonStyle}</style>
274
+ <button onClick={onClose} type='button' className='form-button react-responsive-modal-closeButton pda-modal-close-button' data-testid='close-button' {...getAttrs('opdClose', htmlAttrs)}>
275
+ <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 36 36" data-testid="close-icon"><path d="M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z"></path></svg>
276
+ </button>
172
277
  <form className='personalDataAgreementForm' ref={node => this.form = node}>
173
- <button onClick={onClose} type='button' className='form-button react-responsive-modal-closeButton pda-modal-close-button' data-testid='close-button' {...getAttrs('opdClose', htmlAttrs)}>
174
- <svg xmlns="http://www.w3.org/2000/svg" width="28" height="28" viewBox="0 0 36 36" data-testid="close-icon"><path d="M28.5 9.62L26.38 7.5 18 15.88 9.62 7.5 7.5 9.62 15.88 18 7.5 26.38l2.12 2.12L18 20.12l8.38 8.38 2.12-2.12L20.12 18z"></path></svg>
175
- </button>
176
-
177
278
  <div className={cx('opd-html-form', { submitted: this.state.submitted })} dangerouslySetInnerHTML={{ __html: html }} />
178
-
179
- <button className={`${styles.formBtn} form-button`} type='button' onClick={() => this.onSubmit(formProps)} {...getAttrs('opdAccept', htmlAttrs)}>
180
- { acceptBtn || t('opdFormAccept') }
181
- </button>
182
279
  </form>
280
+ <button className={`${styles.formBtn} form-button`} type='button' onClick={() => this.onSubmit(formProps)} {...getAttrs('opdAccept', htmlAttrs)}>
281
+ { acceptBtn || t('opdFormAccept') }
282
+ </button>
183
283
  </div>
184
284
  </Fragment>;
185
285
  }
186
286
  }
187
287
 
288
+ export class HtmlOpdFormClear extends Component {
289
+ componentDidUpdate(prevProps) {
290
+ if (prevProps.value && !prevProps.open && !equals(prevProps.values, this.props.values)) {
291
+ this.props.onSubmitHtml();
292
+ }
293
+ }
294
+
295
+ render() {
296
+ return null;
297
+ }
298
+ }
299
+
188
300
  export default withTranslation()(HtmlOpdForm);
@@ -2,30 +2,33 @@ 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 { filter, find, path, pathOr, pick, toLower } from 'ramda';
6
-
7
- import 'rc-checkbox/assets/index.css';
8
- import 'react-responsive-modal/styles.css';
5
+ import { filter, find, map, path, pathOr, prop, propEq, pick } from 'ramda';
9
6
 
10
7
  import { Checkbox } from './Checkbox';
11
8
  import styles from '../../styles/index.module.css';
12
- import HtmlOpdForm from './HtmlOpdForm';
9
+ import HtmlOpdForm, { HtmlOpdFormClear } from './HtmlOpdForm';
13
10
  import { FormContext } from '../../context/FormContext';
14
11
  import { getAttrs } from '../../utils/attrs';
15
12
 
16
- const getConstructorOpd = opdSettings => {
13
+ const getConstructorOpd = (opdSettings, language) => {
17
14
  const opdConstructor = pathOr([], ['data', 'opdConstructor'], opdSettings);
18
15
 
19
- const text = opdConstructor.reduce((res, cur) => {
16
+ const text = (opdConstructor || []).reduce((res, cur) => {
20
17
  switch (cur.type) {
21
- case 'text':
22
- return `${res + cur.text} `;
23
18
  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> `;
19
+ return `${res}<input name="${cur.question}" placeholder="${cur.placeholder || ''}" type="text" ${cur.required ? 'required' : ''} /> `;
27
20
  case 'formated':
28
- return res + cur.text;
21
+ return res + (cur.text || '');
22
+ case 'checkbox':
23
+ return `${res}<div>
24
+ <input type="checkbox" id="${`checkbox-${cur.id}`}" ${cur.required ? 'required="required"' : ''} />
25
+ <label for="${`checkbox-${cur.id}`}">${cur.label || ''}</label>
26
+ </div>`;
27
+ case 'opdCheckbox':
28
+ return `${res}<div>
29
+ <input type="checkbox" id="${cur.opdType}" ${path([cur.opdType, 'required'], opdSettings) ? 'required="required"' : ''} />
30
+ <label for="${cur.opdType}">${pathOr('', [cur.opdType, 'label'], opdSettings)}</label>
31
+ </div>`;
29
32
  default:
30
33
  return res;
31
34
  }
@@ -33,11 +36,6 @@ const getConstructorOpd = opdSettings => {
33
36
 
34
37
  return `<div>
35
38
  ${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
39
  </div>`;
42
40
  };
43
41
 
@@ -112,72 +110,96 @@ class PersonalDataAgreementComponent extends Component {
112
110
  }
113
111
 
114
112
  onSubmitHtml = (html, data) => {
115
- this.props.input.onChange({
113
+ this.props.input.onChange(html ? {
116
114
  value: !!html,
117
115
  htmlContent: html,
118
- data,
119
- });
116
+ ...(data || {}),
117
+ } : null);
118
+
120
119
  this.setState({ openedHtml: false });
121
120
  }
122
121
 
123
122
  getOpdValues = formProps => {
124
- const { opdSettings, getOpdValues } = this.props;
123
+ const { opdSettings, getOpdValues, fields } = this.props;
125
124
 
126
125
  if (getOpdValues) {
127
126
  return getOpdValues(formProps);
128
127
  }
129
128
 
130
129
  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);
130
+ return pick(
131
+ filter(
132
+ field => find(i => i.type === 'question' && i.question === field, pathOr([], ['data', 'opdConstructor'], opdSettings)),
133
+ map(prop('field'), fields)
134
+ ),
135
+ formProps.values || {}
136
+ );
134
137
  }
135
138
 
136
139
  return {};
137
140
  }
138
141
 
142
+ isHtmlOpd = () => {
143
+ const constructorOpd = path(['useConstructor'], this.props.opdSettings) ? getConstructorOpd(this.props.opdSettings, this.props.language) : null;
144
+ return !!(this.props.htmlOpd || constructorOpd);
145
+ }
146
+
139
147
  render() {
140
- const { opdSettings } = this.props;
141
- const constructorOpd = path(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings) : null;
148
+ const { opdSettings, language } = this.props;
149
+ const isHtmlOpd = this.isHtmlOpd();
150
+ const constructorOpd = path(['useConstructor'], opdSettings) ? getConstructorOpd(opdSettings, language) : null;
142
151
 
143
152
  return <FormContext.Consumer>{ ({ htmlAttrs }) => (
144
153
  <Fragment>
145
154
  <Checkbox
146
155
  id={'opdCheckbox'}
147
156
  {...this.props}
148
- onValueChange={(this.props.htmlOpd || constructorOpd) ? this.onChange : null}
157
+ onValueChange={isHtmlOpd ? this.onChange : null}
149
158
  options={[{
150
159
  value: true,
151
160
  label: this.getLabel()
152
161
  }]}
153
162
  htmlAttrs={getAttrs('opdCheckbox', htmlAttrs)}
154
163
  />
155
- { (this.props.htmlOpd || constructorOpd) &&
156
- <Modal
157
- open={this.state.openedHtml}
158
- onClose={this.closeHtml}
159
- classNames={{
160
- modal: 'pda-modal',
161
- closeButton: 'pda-modal-close-button',
162
- }}
163
- destroyOnClose
164
- showCloseIcon={false}
165
- center
166
- >
167
- <FormSpy>
164
+ { isHtmlOpd &&
165
+ <Fragment>
166
+ <FormSpy subscription={['values']}>
168
167
  { formProps => (
169
- <HtmlOpdForm
170
- onSubmit={this.onSubmitHtml}
171
- onClose={this.closeHtml}
168
+ <HtmlOpdFormClear
169
+ open={this.state.openedHtml}
172
170
  value={this.props.input.value}
173
- formProps={formProps}
174
- getOpdValues={() => this.getOpdValues(formProps)}
175
- htmlAttrs={htmlAttrs}
176
- html={this.props.htmlOpd || constructorOpd}
177
- acceptBtn={path(['acceptButtonLabel'], opdSettings)} />
171
+ values={this.getOpdValues(formProps)}
172
+ onSubmitHtml={this.onSubmitHtml}
173
+ />
178
174
  )}
179
175
  </FormSpy>
180
- </Modal>
176
+ <Modal
177
+ open={this.state.openedHtml}
178
+ onClose={this.closeHtml}
179
+ classNames={{
180
+ modal: 'pda-modal',
181
+ closeButton: 'pda-modal-close-button',
182
+ }}
183
+ destroyOnClose
184
+ showCloseIcon={false}
185
+ center
186
+ >
187
+ <FormSpy>
188
+ { formProps => (
189
+ <HtmlOpdForm
190
+ onSubmit={this.onSubmitHtml}
191
+ onClose={this.closeHtml}
192
+ value={this.props.input.value}
193
+ formProps={formProps}
194
+ formFields={this.props.fields}
195
+ getOpdValues={() => this.getOpdValues(formProps)}
196
+ htmlAttrs={htmlAttrs}
197
+ html={this.props.htmlOpd || constructorOpd}
198
+ acceptBtn={pathOr(path(['acceptButtonLabel'], opdSettings), ['translations', 'acceptButtonLabel', language], opdSettings)} />
199
+ )}
200
+ </FormSpy>
201
+ </Modal>
202
+ </Fragment>
181
203
  }
182
204
  </Fragment>
183
205
  )}</FormContext.Consumer>;
@@ -5,7 +5,7 @@ export const defaultAllowFileExtensions = {
5
5
  html: 'text/html',
6
6
  odt: 'application/vnd.oasis.opendocument.text',
7
7
  pdf: 'application/pdf',
8
- rtf: 'application/rtf, text/rtf, .rtf',
8
+ rtf: 'application/rtf',
9
9
  txt: 'text/plain',
10
10
  xls: 'application/vnd.ms-excel',
11
11
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
@@ -26,5 +26,5 @@ export const TYPES = {
26
26
 
27
27
  export const VALIDATION_FILE_TYPES = {
28
28
  image: 'jpeg, tiff, png',
29
- document: 'doc, docx, html, odt, pdf, rtf, xls, xlsx',
29
+ document: 'doc, docx, html, odt, pdf, rtf, txt, xls, xlsx',
30
30
  };