@experium/findy-form 1.2.51 → 1.2.52

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,8 +35,6 @@ var _reactI18next = require("react-i18next");
35
35
 
36
36
  var _getusermedia = _interopRequireDefault(require("getusermedia"));
37
37
 
38
- var _axios = _interopRequireDefault(require("axios"));
39
-
40
38
  var _withFieldWrapper = _interopRequireDefault(require("../hocs/withFieldWrapper"));
41
39
 
42
40
  var _ImageFile = _interopRequireDefault(require("./ImageFile"));
@@ -193,13 +191,16 @@ var File = /*#__PURE__*/function (_Component) {
193
191
  });
194
192
 
195
193
  setInputError(undefined);
196
-
197
- _axios["default"].post(postFileUrl, fd, {
198
- headers: {
199
- 'Content-Type': 'multipart/form-data'
200
- }
194
+ fetch(postFileUrl, {
195
+ method: 'POST',
196
+ body: fd
201
197
  }).then(function (response) {
202
- var data = response.data;
198
+ if (!response.ok && response.status !== 400) {
199
+ throw new Error();
200
+ } else {
201
+ return response.json();
202
+ }
203
+ }).then(function (data) {
203
204
  var name = _this.props.input.name;
204
205
  var fileName = data.filename;
205
206
 
@@ -248,7 +249,7 @@ var File = /*#__PURE__*/function (_Component) {
248
249
  onChange(fileItem);
249
250
  }
250
251
  })["catch"](function (error) {
251
- setInputError((0, _file.getFileErrorText)((0, _ramda.pathOr)('', ['response', 'data', 'message'], error)));
252
+ setInputError((0, _file.getFileErrorText)(error));
252
253
 
253
254
  _this.setState({
254
255
  error: true
@@ -420,6 +421,7 @@ var File = /*#__PURE__*/function (_Component) {
420
421
  var _this$state = this.state,
421
422
  loading = _this$state.loading,
422
423
  error = _this$state.error;
424
+ var isLoading = loading && !error;
423
425
  return /*#__PURE__*/_react["default"].createElement("div", {
424
426
  id: "".concat(name, "-file")
425
427
  }, !(0, _ramda.isEmpty)(value) && /*#__PURE__*/_react["default"].createElement("div", {
@@ -451,16 +453,17 @@ var File = /*#__PURE__*/function (_Component) {
451
453
  className: styles.fileInput,
452
454
  id: name,
453
455
  type: "file",
456
+ value: "",
454
457
  onChange: this.onChange,
455
458
  accept: this.getAccept(type),
456
- disabled: disabled || loading && !error
459
+ disabled: disabled || isLoading
457
460
  }), /*#__PURE__*/_react["default"].createElement("label", {
458
461
  htmlFor: name,
459
462
  className: "".concat(disabled ? 'disabled' : '')
460
- }, loading && !error && /*#__PURE__*/_react["default"].createElement(_Spinner["default"], null), /*#__PURE__*/_react["default"].createElement("span", {
463
+ }, isLoading && /*#__PURE__*/_react["default"].createElement(_Spinner["default"], null), /*#__PURE__*/_react["default"].createElement("span", {
461
464
  className: "button-text"
462
465
  }, t('upload')))), !multiple && value.length > 1 || !BTN_TEXT[type] ? null : type && /*#__PURE__*/_react["default"].createElement("button", {
463
- disabled: loading && !error || disabled,
466
+ disabled: isLoading || disabled,
464
467
  className: formStyles.formBtn,
465
468
  type: "button",
466
469
  onClick: this.openModal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@experium/findy-form",
3
- "version": "1.2.51",
3
+ "version": "1.2.52",
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,7 +10,6 @@
10
10
  },
11
11
  "dependencies": {
12
12
  "@ant-design/icons": "^4.2.2",
13
- "axios": "^0.26.0",
14
13
  "class-validator": "^0.12.2",
15
14
  "classnames": "^2.2.6",
16
15
  "final-form": "^4.20.2",
@@ -3,7 +3,6 @@ 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';
7
6
 
8
7
  import withFieldWrapper from '../hocs/withFieldWrapper';
9
8
  import ImageFile from './ImageFile';
@@ -67,13 +66,18 @@ class File extends Component {
67
66
  this.setState({ loading: true, error: false });
68
67
  setInputError(undefined);
69
68
 
70
- axios.post(postFileUrl, fd, {
71
- headers: {
72
- 'Content-Type': 'multipart/form-data',
73
- },
69
+ fetch(postFileUrl, {
70
+ method: 'POST',
71
+ body: fd
74
72
  })
75
73
  .then(response => {
76
- const { data } = response;
74
+ if (!response.ok && response.status !== 400) {
75
+ throw new Error();
76
+ } else {
77
+ return response.json();
78
+ }
79
+ })
80
+ .then(data => {
77
81
  const { input: { name } } = this.props;
78
82
  const fileName = data.filename;
79
83
 
@@ -111,7 +115,7 @@ class File extends Component {
111
115
  }
112
116
  })
113
117
  .catch((error) => {
114
- setInputError(getFileErrorText(pathOr('', ['response', 'data', 'message'], error)));
118
+ setInputError(getFileErrorText(error));
115
119
  this.setState({ error: true });
116
120
  });
117
121
  } else {
@@ -264,6 +268,8 @@ class File extends Component {
264
268
  const ModalContent = MODAL_CONTENT[type];
265
269
  const { loading, error } = this.state;
266
270
 
271
+ const isLoading = loading && !error;
272
+
267
273
  return <div id={`${name}-file`}>
268
274
  { !isEmpty(value) && (
269
275
  <div className={styles.fileList}>
@@ -302,12 +308,13 @@ class File extends Component {
302
308
  className={styles.fileInput}
303
309
  id={name}
304
310
  type='file'
311
+ value=''
305
312
  onChange={this.onChange}
306
313
  accept={this.getAccept(type)}
307
- disabled={disabled || (loading && !error)}
314
+ disabled={disabled || isLoading}
308
315
  />
309
316
  <label htmlFor={name} className={`${disabled ? 'disabled' : ''}`}>
310
- { (loading && !error) && <Spinner /> }
317
+ { isLoading && <Spinner /> }
311
318
  <span className='button-text'>
312
319
  {t('upload')}
313
320
  </span>
@@ -316,7 +323,7 @@ class File extends Component {
316
323
  }
317
324
  { (!multiple && value.length > 1) || !BTN_TEXT[type] ? null : (
318
325
  type && (
319
- <button disabled={loading && !error || disabled} className={formStyles.formBtn} type='button' onClick={this.openModal}>
326
+ <button disabled={isLoading || disabled} className={formStyles.formBtn} type='button' onClick={this.openModal}>
320
327
  { t(BTN_TEXT[type]) }
321
328
  </button>
322
329
  )