@experium/findy-form 1.2.42 → 1.2.43
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/dist/app.js +1 -1
- package/lib/components/formComponents/File.js +9 -4
- package/lib/constants/allowFileExtensions.js +2 -2
- package/lib/utils/validation.js +8 -5
- package/package.json +1 -1
- package/src/components/formComponents/File.js +10 -7
- package/src/constants/allowFileExtensions.js +2 -2
- package/src/utils/validation.js +6 -4
|
@@ -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
|
|
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.
|
|
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
|
}
|
|
@@ -416,6 +420,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
416
420
|
var _this$state = this.state,
|
|
417
421
|
loading = _this$state.loading,
|
|
418
422
|
error = _this$state.error;
|
|
423
|
+
console.log(this.getAccept(type));
|
|
419
424
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
420
425
|
id: "".concat(name, "-file")
|
|
421
426
|
}, !(0, _ramda.isEmpty)(value) && /*#__PURE__*/_react["default"].createElement("div", {
|
|
@@ -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
|
|
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;
|
package/lib/utils/validation.js
CHANGED
|
@@ -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 >
|
|
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
|
-
|
|
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,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(',',
|
|
256
|
+
`.${join(', .', keys(allowFileExtensions[type]))}`
|
|
254
257
|
) : TYPES[type];
|
|
255
258
|
} else {
|
|
256
259
|
return TYPES[type];
|
|
@@ -263,7 +266,7 @@ class File extends Component {
|
|
|
263
266
|
const values = value ? (multiple ? value : [value]) : [];
|
|
264
267
|
const ModalContent = MODAL_CONTENT[type];
|
|
265
268
|
const { loading, error } = this.state;
|
|
266
|
-
|
|
269
|
+
console.log(this.getAccept(type));
|
|
267
270
|
return <div id={`${name}-file`}>
|
|
268
271
|
{ !isEmpty(value) && (
|
|
269
272
|
<div className={styles.fileList}>
|
|
@@ -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
|
|
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
|
};
|
package/src/utils/validation.js
CHANGED
|
@@ -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
|
-
|
|
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
|
}),
|