@experium/findy-form 1.2.45 → 1.2.49
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.
|
@@ -35,6 +35,8 @@ var _reactI18next = require("react-i18next");
|
|
|
35
35
|
|
|
36
36
|
var _getusermedia = _interopRequireDefault(require("getusermedia"));
|
|
37
37
|
|
|
38
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
39
|
+
|
|
38
40
|
var _withFieldWrapper = _interopRequireDefault(require("../hocs/withFieldWrapper"));
|
|
39
41
|
|
|
40
42
|
var _ImageFile = _interopRequireDefault(require("./ImageFile"));
|
|
@@ -181,8 +183,9 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
181
183
|
var fileExtenstion = (0, _ramda.last)("".concat(file.name).split('.'));
|
|
182
184
|
var fileType = file.type || (0, _ramda.path)([type, fileExtenstion], _allowFileExtensions.defaultAllowFileExtensions);
|
|
183
185
|
var validFileType = (0, _validation.checkFileType)(type, file.type, fileExtenstion, allowFileExtensions);
|
|
184
|
-
|
|
186
|
+
console.log(file);
|
|
185
187
|
fd.append('name', file.name);
|
|
188
|
+
fd.append('mimetype', fileType);
|
|
186
189
|
|
|
187
190
|
if (validFileType) {
|
|
188
191
|
_this.setState({
|
|
@@ -191,16 +194,13 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
191
194
|
});
|
|
192
195
|
|
|
193
196
|
setInputError(undefined);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!response.ok && response.status !== 400) {
|
|
199
|
-
throw new Error();
|
|
200
|
-
} else {
|
|
201
|
-
return response.json();
|
|
197
|
+
|
|
198
|
+
_axios["default"].post(postFileUrl, fd, {
|
|
199
|
+
headers: {
|
|
200
|
+
'Content-Type': 'multipart/form-data'
|
|
202
201
|
}
|
|
203
|
-
}).then(function (
|
|
202
|
+
}).then(function (response) {
|
|
203
|
+
var data = response.data;
|
|
204
204
|
var name = _this.props.input.name;
|
|
205
205
|
var fileName = data.filename;
|
|
206
206
|
|
|
@@ -249,7 +249,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
249
249
|
onChange(fileItem);
|
|
250
250
|
}
|
|
251
251
|
})["catch"](function (error) {
|
|
252
|
-
setInputError((0, _file.getFileErrorText)(error));
|
|
252
|
+
setInputError((0, _file.getFileErrorText)((0, _ramda.pathOr)('', ['response', 'data', 'message'], error)));
|
|
253
253
|
|
|
254
254
|
_this.setState({
|
|
255
255
|
error: true
|
|
@@ -285,6 +285,7 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
285
285
|
}
|
|
286
286
|
});
|
|
287
287
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onChange", function (e) {
|
|
288
|
+
console.log(e, e.target);
|
|
288
289
|
var file = e.target.files[0];
|
|
289
290
|
|
|
290
291
|
_this.onSave(file);
|
|
@@ -452,7 +453,6 @@ var File = /*#__PURE__*/function (_Component) {
|
|
|
452
453
|
className: styles.fileInput,
|
|
453
454
|
id: name,
|
|
454
455
|
type: "file",
|
|
455
|
-
value: "",
|
|
456
456
|
onChange: this.onChange,
|
|
457
457
|
accept: this.getAccept(type),
|
|
458
458
|
disabled: disabled || loading && !error
|
package/lib/utils/validation.js
CHANGED
|
@@ -44,7 +44,7 @@ var checkFileType = function checkFileType(fileType, mimeType, extenstion) {
|
|
|
44
44
|
return allowFileTypes ? (0, _ramda.contains)(mimeType, (0, _ramda.split)(',', (0, _ramda.replace)(/\s/g, '', allowFileTypes))) : true;
|
|
45
45
|
|
|
46
46
|
default:
|
|
47
|
-
return allowFileTypes ? allowFileExtensions[fileType] : _allowFileExtensions.defaultAllowFileExtensions[fileType];
|
|
47
|
+
return !fileType || (allowFileTypes ? allowFileExtensions[fileType][extenstion] : _allowFileExtensions.defaultAllowFileExtensions[fileType][extenstion]);
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@experium/findy-form",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.49",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"homepage": "https://experium.github.io/findy-form",
|
|
6
6
|
"repository": "https://github.com/experium/findy-form",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@ant-design/icons": "^4.2.2",
|
|
13
|
+
"axios": "^0.26.0",
|
|
13
14
|
"class-validator": "^0.12.2",
|
|
14
15
|
"classnames": "^2.2.6",
|
|
15
16
|
"final-form": "^4.20.2",
|
|
@@ -3,6 +3,7 @@ import { prop, append, remove, isEmpty, path, pathOr, join, values, keys, last }
|
|
|
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';
|
|
@@ -59,25 +60,22 @@ class File extends Component {
|
|
|
59
60
|
const fileType = file.type || path([type, fileExtenstion], defaultAllowFileExtensions);
|
|
60
61
|
const validFileType = checkFileType(type, file.type, fileExtenstion, allowFileExtensions);
|
|
61
62
|
|
|
62
|
-
|
|
63
|
+
console.log(file);
|
|
64
|
+
|
|
63
65
|
fd.append('name', file.name);
|
|
66
|
+
fd.append('mimetype', fileType);
|
|
64
67
|
|
|
65
68
|
if (validFileType) {
|
|
66
69
|
this.setState({ loading: true, error: false });
|
|
67
70
|
setInputError(undefined);
|
|
68
71
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
axios.post(postFileUrl, fd, {
|
|
73
|
+
headers: {
|
|
74
|
+
'Content-Type': 'multipart/form-data',
|
|
75
|
+
},
|
|
72
76
|
})
|
|
73
77
|
.then(response => {
|
|
74
|
-
|
|
75
|
-
throw new Error();
|
|
76
|
-
} else {
|
|
77
|
-
return response.json();
|
|
78
|
-
}
|
|
79
|
-
})
|
|
80
|
-
.then(data => {
|
|
78
|
+
const { data } = response;
|
|
81
79
|
const { input: { name } } = this.props;
|
|
82
80
|
const fileName = data.filename;
|
|
83
81
|
|
|
@@ -115,7 +113,7 @@ class File extends Component {
|
|
|
115
113
|
}
|
|
116
114
|
})
|
|
117
115
|
.catch((error) => {
|
|
118
|
-
setInputError(getFileErrorText(error));
|
|
116
|
+
setInputError(getFileErrorText(pathOr('', ['response', 'data', 'message'], error)));
|
|
119
117
|
this.setState({ error: true });
|
|
120
118
|
});
|
|
121
119
|
} else {
|
|
@@ -150,6 +148,7 @@ class File extends Component {
|
|
|
150
148
|
}
|
|
151
149
|
|
|
152
150
|
onChange = e => {
|
|
151
|
+
console.log(e, e.target);
|
|
153
152
|
const file = e.target.files[0];
|
|
154
153
|
|
|
155
154
|
this.onSave(file);
|
|
@@ -306,13 +305,12 @@ class File extends Component {
|
|
|
306
305
|
className={styles.fileInput}
|
|
307
306
|
id={name}
|
|
308
307
|
type='file'
|
|
309
|
-
value=''
|
|
310
308
|
onChange={this.onChange}
|
|
311
309
|
accept={this.getAccept(type)}
|
|
312
|
-
disabled={disabled || loading && !error}
|
|
310
|
+
disabled={disabled || (loading && !error)}
|
|
313
311
|
/>
|
|
314
312
|
<label htmlFor={name} className={`${disabled ? 'disabled' : ''}`}>
|
|
315
|
-
{ loading && !error && <Spinner /> }
|
|
313
|
+
{ (loading && !error) && <Spinner /> }
|
|
316
314
|
<span className='button-text'>
|
|
317
315
|
{t('upload')}
|
|
318
316
|
</span>
|
package/src/utils/validation.js
CHANGED
|
@@ -24,7 +24,7 @@ export const checkFileType = (fileType, mimeType, extenstion, allowFileExtension
|
|
|
24
24
|
|
|
25
25
|
return allowFileTypes ? contains(mimeType, split(',', replace(/\s/g, '', allowFileTypes))) : true;
|
|
26
26
|
default:
|
|
27
|
-
return allowFileTypes ? allowFileExtensions[fileType] : defaultAllowFileExtensions[fileType];
|
|
27
|
+
return !fileType || (allowFileTypes ? allowFileExtensions[fileType][extenstion] : defaultAllowFileExtensions[fileType][extenstion]);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
export const getFileTypeMessage = (type, allowFileExtensions = {}) => {
|