@experium/findy-form 1.2.40 → 1.2.44

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.
@@ -534,7 +534,7 @@ var Fields = /*#__PURE__*/function (_Component) {
534
534
  renderField: function renderField(field) {
535
535
  return /*#__PURE__*/_react["default"].createElement("div", {
536
536
  key: field.field
537
- }, field.type === 'composite' ? /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, /*#__PURE__*/_react["default"].createElement("h2", null, language ? (0, _ramda.pathOr)(field.label, ['translations', 'label', language], field) : field.label), (0, _ramda.path)(['settings', 'multiple'], field) ? /*#__PURE__*/_react["default"].createElement(_reactFinalFormArrays.FieldArray, {
537
+ }, field.type === 'composite' ? /*#__PURE__*/_react["default"].createElement(_react.Fragment, null, (0, _ramda.includes)((0, _ramda.path)(['settings', 'showLabel'], field), [true, undefined]) ? /*#__PURE__*/_react["default"].createElement("h2", null, language ? (0, _ramda.pathOr)(field.label, ['translations', 'label', language], field) : field.label) : null, (0, _ramda.path)(['settings', 'multiple'], field) ? /*#__PURE__*/_react["default"].createElement(_reactFinalFormArrays.FieldArray, {
538
538
  name: field.field,
539
539
  validate: field.required ? _validation.compositeValidator : undefined,
540
540
  initialValue: _form.fieldArrayInitialValues
@@ -178,7 +178,8 @@ var File = /*#__PURE__*/function (_Component) {
178
178
  var multiple = (0, _ramda.prop)('multiple', settings);
179
179
  var type = (0, _ramda.prop)('type', settings);
180
180
  var fd = new FormData();
181
- var validFileType = (0, _validation.checkFileType)(type, file.type, allowFileExtensions);
181
+ var fileExtenstion = (0, _ramda.last)("".concat(file.name).split('.'));
182
+ var validFileType = (0, _validation.checkFileType)(type, file.type, fileExtenstion, allowFileExtensions);
182
183
  fd.append('file', file);
183
184
  fd.append('name', file.name);
184
185
 
@@ -199,6 +200,9 @@ var File = /*#__PURE__*/function (_Component) {
199
200
  return response.json();
200
201
  }
201
202
  }).then(function (data) {
203
+ var name = _this.props.input.name;
204
+ var fileName = data.filename;
205
+
202
206
  if (data.statusCode === 400) {
203
207
  setInputError((0, _file.getFileErrorText)(data.message));
204
208
  return _this.setState({
@@ -214,8 +218,6 @@ var File = /*#__PURE__*/function (_Component) {
214
218
  });
215
219
  }
216
220
 
217
- var name = _this.props.input.name;
218
- var fileName = data.filename;
219
221
  var url = getFileUrl ? getFileUrl(data.id) : data.id;
220
222
 
221
223
  _this.setState({
@@ -225,6 +227,7 @@ var File = /*#__PURE__*/function (_Component) {
225
227
  var fileItem = {
226
228
  url: url,
227
229
  text: fileName,
230
+ extenstion: fileExtenstion,
228
231
  contentType: file.type,
229
232
  type: type
230
233
  };
@@ -254,6 +257,7 @@ var File = /*#__PURE__*/function (_Component) {
254
257
  } else {
255
258
  var fileItem = {
256
259
  text: file.name,
260
+ extenstion: fileExtenstion,
257
261
  contentType: file.type,
258
262
  type: type
259
263
  };
@@ -386,7 +390,7 @@ var File = /*#__PURE__*/function (_Component) {
386
390
  var allowFileExtensions = _this.props.allowFileExtensions;
387
391
 
388
392
  if (allowFileExtensions) {
389
- return allowFileExtensions[type] ? (0, _ramda.join)(',', (0, _ramda.values)(allowFileExtensions[type])) : _allowFileExtensions.TYPES[type];
393
+ return allowFileExtensions[type] ? ".".concat((0, _ramda.join)(', .', (0, _ramda.keys)(allowFileExtensions[type]))) : _allowFileExtensions.TYPES[type];
390
394
  } else {
391
395
  return _allowFileExtensions.TYPES[type];
392
396
  }
@@ -84,11 +84,15 @@ exports.getHtml = getHtml;
84
84
  var TEXT_FIELDS = ['text', 'email', 'phone', 'date'];
85
85
  var SELECT_FIELDS = ['dictionary', 'company_dictionary', 'list', 'city', 'country', 'region', 'money'];
86
86
  var OPD_DATA_CHECKBOXES = {
87
+ 'accept': 'accept',
87
88
  'acceptCheckbox': 'accept',
88
89
  'opdAccept': 'accept',
90
+ 'purpose': 'purpose',
89
91
  'purposeCheckbox': 'purpose',
90
92
  'opdPurpose': 'purpose',
93
+ 'mailing': 'mailing',
91
94
  'mailingCheckbox': 'mailing',
95
+ 'transmission': 'transmission',
92
96
  'transmissionCheckbox': 'transmission'
93
97
  };
94
98
 
@@ -201,13 +205,22 @@ var HtmlOpdForm = /*#__PURE__*/function (_Component) {
201
205
  }
202
206
  }
203
207
 
204
- var separateField = OPD_DATA_CHECKBOXES[input.getAttribute('data-separate-field') || input.getAttribute('id')];
208
+ var separateField = input.getAttribute('data-separate-field');
205
209
 
206
210
  if (separateField) {
207
211
  var value = input.type === 'checkbox' ? input.checked : input.value;
208
- values[separateField] = value;
212
+ var id = OPD_DATA_CHECKBOXES[separateField];
213
+ values[id] = value;
209
214
  form.change(separateField, value);
210
215
  }
216
+
217
+ var fixedField = OPD_DATA_CHECKBOXES[input.getAttribute('id')];
218
+
219
+ if (fixedField) {
220
+ var _value = input.type === 'checkbox' ? input.checked : input.value;
221
+
222
+ values[separateField] = _value;
223
+ }
211
224
  }, inputs);
212
225
 
213
226
  _this.props.onSubmit(getHtml(_this.form.innerHTML), values);
@@ -11,7 +11,7 @@ var defaultAllowFileExtensions = {
11
11
  html: 'text/html',
12
12
  odt: 'application/vnd.oasis.opendocument.text',
13
13
  pdf: 'application/pdf',
14
- rtf: 'application/rtf, text/rtf, .rtf',
14
+ rtf: 'application/rtf',
15
15
  txt: 'text/plain',
16
16
  xls: 'application/vnd.ms-excel',
17
17
  xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
@@ -32,6 +32,6 @@ var TYPES = {
32
32
  exports.TYPES = TYPES;
33
33
  var VALIDATION_FILE_TYPES = {
34
34
  image: 'jpeg, tiff, png',
35
- document: 'doc, docx, html, odt, pdf, rtf, xls, xlsx'
35
+ document: 'doc, docx, html, odt, pdf, rtf, txt, xls, xlsx'
36
36
  };
37
37
  exports.VALIDATION_FILE_TYPES = VALIDATION_FILE_TYPES;
@@ -29,8 +29,8 @@ var checkDate = function checkDate(value) {
29
29
  return !value || value === 'incomplete';
30
30
  };
31
31
 
32
- var checkFileType = function checkFileType(fileType, mimeType) {
33
- var allowFileExtensions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
32
+ var checkFileType = function checkFileType(fileType, mimeType, extenstion) {
33
+ var allowFileExtensions = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
34
34
 
35
35
  switch (fileType) {
36
36
  case 'audio':
@@ -39,9 +39,12 @@ var checkFileType = function checkFileType(fileType, mimeType) {
39
39
  case 'video':
40
40
  return (0, _ramda.startsWith)('video', mimeType);
41
41
 
42
- default:
42
+ case 'image':
43
43
  var allowFileTypes = (0, _ramda.join)(',', (0, _ramda.values)(allowFileExtensions && !(0, _ramda.isEmpty)(allowFileExtensions[fileType]) ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType]));
44
44
  return allowFileTypes ? (0, _ramda.contains)(mimeType, (0, _ramda.split)(',', (0, _ramda.replace)(/\s/g, '', allowFileTypes))) : true;
45
+
46
+ default:
47
+ return allowFileTypes ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType];
45
48
  }
46
49
  };
47
50
 
@@ -244,12 +247,12 @@ var rules = {
244
247
  var result = true;
245
248
  value.forEach(function (value) {
246
249
  if (result) {
247
- result = checkFileType(value.type, value.contentType, allowFileExtensions);
250
+ result = checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
248
251
  }
249
252
  });
250
253
  return result;
251
254
  } else {
252
- return checkFileType(value.type, value.contentType, allowFileExtensions);
255
+ return checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
253
256
  }
254
257
  }
255
258
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.2.40",
3
+ "version": "1.2.44",
4
4
  "main": "./lib/index.js",
5
5
  "homepage": "https://experium.github.io/findy-form",
6
6
  "repository": "https://github.com/experium/findy-form",
@@ -356,7 +356,9 @@ class Fields extends Component {
356
356
  <div key={field.field}>
357
357
  { field.type === 'composite' ?
358
358
  <Fragment>
359
- <h2>{ language ? pathOr(field.label, ['translations', 'label', language], field) : field.label }</h2>
359
+ { includes(path(['settings', 'showLabel'], field), [true, undefined]) ? (
360
+ <h2>{ language ? pathOr(field.label, ['translations', 'label', language], field) : field.label }</h2>
361
+ ) : null}
360
362
  { path(['settings', 'multiple'], field) ?
361
363
  <FieldArray
362
364
  name={field.field}
@@ -1,5 +1,5 @@
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';
@@ -55,8 +55,8 @@ class File extends Component {
55
55
  const multiple = prop('multiple', settings);
56
56
  const type = prop('type', settings);
57
57
  const fd = new FormData();
58
-
59
- const validFileType = checkFileType(type, file.type, allowFileExtensions);
58
+ const fileExtenstion = last(`${file.name}`.split('.'));
59
+ const validFileType = checkFileType(type, file.type, fileExtenstion, allowFileExtensions);
60
60
 
61
61
  fd.append('file', file);
62
62
  fd.append('name', file.name);
@@ -77,6 +77,9 @@ class File extends Component {
77
77
  }
78
78
  })
79
79
  .then(data => {
80
+ const { input: { name } } = this.props;
81
+ const fileName = data.filename;
82
+
80
83
  if (data.statusCode === 400) {
81
84
  setInputError(getFileErrorText(data.message));
82
85
  return this.setState({ error: data.message || true, loading: false });
@@ -86,14 +89,13 @@ class File extends Component {
86
89
  return this.setState({ error: true, loading: false });
87
90
  }
88
91
 
89
- const { input: { name } } = this.props;
90
- const fileName = data.filename;
91
92
  const url = getFileUrl ? getFileUrl(data.id) : data.id;
92
93
  this.setState({ loading: false });
93
94
 
94
95
  const fileItem = {
95
96
  url,
96
97
  text: fileName,
98
+ extenstion: fileExtenstion,
97
99
  contentType: file.type,
98
100
  type,
99
101
  };
@@ -118,6 +120,7 @@ class File extends Component {
118
120
  } else {
119
121
  const fileItem = {
120
122
  text: file.name,
123
+ extenstion: fileExtenstion,
121
124
  contentType: file.type,
122
125
  type,
123
126
  };
@@ -250,7 +253,7 @@ class File extends Component {
250
253
 
251
254
  if (allowFileExtensions) {
252
255
  return allowFileExtensions[type] ? (
253
- join(',', values(allowFileExtensions[type]))
256
+ `.${join(', .', keys(allowFileExtensions[type]))}`
254
257
  ) : TYPES[type];
255
258
  } else {
256
259
  return TYPES[type];
@@ -127,11 +127,15 @@ export const getHtml = body => `
127
127
  const TEXT_FIELDS = ['text', 'email', 'phone', 'date'];
128
128
  const SELECT_FIELDS = ['dictionary', 'company_dictionary', 'list', 'city', 'country', 'region', 'money'];
129
129
  const OPD_DATA_CHECKBOXES = {
130
+ 'accept': 'accept',
130
131
  'acceptCheckbox': 'accept',
131
132
  'opdAccept': 'accept',
133
+ 'purpose': 'purpose',
132
134
  'purposeCheckbox': 'purpose',
133
135
  'opdPurpose': 'purpose',
136
+ 'mailing': 'mailing',
134
137
  'mailingCheckbox': 'mailing',
138
+ 'transmission': 'transmission',
135
139
  'transmissionCheckbox': 'transmission',
136
140
  };
137
141
 
@@ -239,13 +243,20 @@ class HtmlOpdForm extends Component {
239
243
  }
240
244
  }
241
245
 
242
- const separateField = OPD_DATA_CHECKBOXES[input.getAttribute('data-separate-field') || input.getAttribute('id')];
246
+ const separateField = input.getAttribute('data-separate-field');
243
247
 
244
248
  if (separateField) {
245
249
  const value = input.type === 'checkbox' ? input.checked : input.value;
246
- values[separateField] = value;
250
+ const id = OPD_DATA_CHECKBOXES[separateField];
251
+ values[id] = value;
247
252
  form.change(separateField, value);
248
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
+ }
249
260
  }, inputs);
250
261
 
251
262
  this.props.onSubmit(getHtml(this.form.innerHTML), values);
@@ -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
  };
@@ -11,18 +11,20 @@ import { defaultAllowFileExtensions, VALIDATION_FILE_TYPES } from '../constants/
11
11
 
12
12
  const checkDate = value => !value || value === 'incomplete';
13
13
 
14
- export const checkFileType = (fileType, mimeType, allowFileExtensions = {}) => {
14
+ export const checkFileType = (fileType, mimeType, extenstion, allowFileExtensions = {}) => {
15
15
  switch (fileType) {
16
16
  case 'audio':
17
17
  return startsWith('audio', mimeType);
18
18
  case 'video':
19
19
  return startsWith('video', mimeType);
20
- default:
20
+ case 'image':
21
21
  const allowFileTypes = join(',', values(
22
22
  allowFileExtensions && !isEmpty(allowFileExtensions[fileType]) ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType]
23
23
  ));
24
24
 
25
25
  return allowFileTypes ? contains(mimeType, split(',', replace(/\s/g, '', allowFileTypes))) : true;
26
+ default:
27
+ return allowFileTypes ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType];
26
28
  }
27
29
  };
28
30
  export const getFileTypeMessage = (type, allowFileExtensions = {}) => {
@@ -194,13 +196,13 @@ const rules = {
194
196
 
195
197
  value.forEach(value => {
196
198
  if (result) {
197
- result = checkFileType(value.type, value.contentType, allowFileExtensions);
199
+ result = checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
198
200
  }
199
201
  });
200
202
 
201
203
  return result;
202
204
  } else {
203
- return checkFileType(value.type, value.contentType, allowFileExtensions);
205
+ return checkFileType(value.type, value.contentType, value.extenstion, allowFileExtensions);
204
206
  }
205
207
  },
206
208
  }),