@transferwise/components 46.38.0 → 46.40.0

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.
Files changed (202) hide show
  1. package/build/index.js +198 -461
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +198 -461
  4. package/build/index.mjs.map +1 -1
  5. package/build/types/flowNavigation/backButton/BackButton.d.ts +5 -17
  6. package/build/types/flowNavigation/backButton/BackButton.d.ts.map +1 -1
  7. package/build/types/flowNavigation/backButton/index.d.ts +2 -2
  8. package/build/types/flowNavigation/backButton/index.d.ts.map +1 -1
  9. package/build/types/index.d.ts +3 -1
  10. package/build/types/index.d.ts.map +1 -1
  11. package/build/types/info/Info.d.ts +2 -2
  12. package/build/types/info/Info.d.ts.map +1 -1
  13. package/build/types/info/index.d.ts +1 -1
  14. package/build/types/info/index.d.ts.map +1 -1
  15. package/build/types/overlayHeader/OverlayHeader.d.ts +9 -18
  16. package/build/types/overlayHeader/OverlayHeader.d.ts.map +1 -1
  17. package/build/types/overlayHeader/index.d.ts +2 -1
  18. package/build/types/overlayHeader/index.d.ts.map +1 -1
  19. package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
  20. package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
  21. package/build/types/upload/Upload.d.ts +91 -55
  22. package/build/types/upload/Upload.d.ts.map +1 -1
  23. package/build/types/upload/Upload.messages.d.ts +42 -60
  24. package/build/types/upload/Upload.messages.d.ts.map +1 -1
  25. package/build/types/upload/index.d.ts +2 -2
  26. package/build/types/upload/index.d.ts.map +1 -1
  27. package/build/types/upload/steps/completeStep/completeStep.d.ts +11 -18
  28. package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
  29. package/build/types/upload/steps/completeStep/index.d.ts +2 -1
  30. package/build/types/upload/steps/completeStep/index.d.ts.map +1 -1
  31. package/build/types/upload/steps/index.d.ts +3 -4
  32. package/build/types/upload/steps/index.d.ts.map +1 -1
  33. package/build/types/upload/steps/processingStep/index.d.ts +2 -1
  34. package/build/types/upload/steps/processingStep/index.d.ts.map +1 -1
  35. package/build/types/upload/steps/processingStep/processingStep.d.ts +11 -13
  36. package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
  37. package/build/types/upload/steps/uploadImageStep/index.d.ts +2 -1
  38. package/build/types/upload/steps/uploadImageStep/index.d.ts.map +1 -1
  39. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +14 -18
  40. package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
  41. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts +1 -1
  42. package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts.map +1 -1
  43. package/build/types/upload/utils/asyncFileRead/index.d.ts +1 -1
  44. package/build/types/upload/utils/asyncFileRead/index.d.ts.map +1 -1
  45. package/build/types/upload/utils/getFileType/getFileType.d.ts +1 -1
  46. package/build/types/upload/utils/getFileType/getFileType.d.ts.map +1 -1
  47. package/build/types/upload/utils/getFileType/index.d.ts +1 -1
  48. package/build/types/upload/utils/getFileType/index.d.ts.map +1 -1
  49. package/build/types/upload/utils/index.d.ts +5 -7
  50. package/build/types/upload/utils/index.d.ts.map +1 -1
  51. package/build/types/upload/utils/isSizeValid/index.d.ts +1 -1
  52. package/build/types/upload/utils/isSizeValid/index.d.ts.map +1 -1
  53. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts +1 -1
  54. package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts.map +1 -1
  55. package/build/types/upload/utils/isTypeValid/index.d.ts +1 -1
  56. package/build/types/upload/utils/isTypeValid/index.d.ts.map +1 -1
  57. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts +1 -1
  58. package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts.map +1 -1
  59. package/build/types/upload/utils/postData/index.d.ts +1 -1
  60. package/build/types/upload/utils/postData/index.d.ts.map +1 -1
  61. package/build/types/upload/utils/postData/postData.d.ts +11 -1
  62. package/build/types/upload/utils/postData/postData.d.ts.map +1 -1
  63. package/package.json +24 -26
  64. package/src/accordion/Accordion.spec.js +5 -5
  65. package/src/accordion/AccordionItem/AccordionItem.spec.js +2 -2
  66. package/src/actionButton/ActionButton.spec.tsx +4 -5
  67. package/src/alert/Alert.spec.tsx +4 -4
  68. package/src/alert/Alert.story.tsx +6 -5
  69. package/src/button/Button.spec.js +4 -5
  70. package/src/card/Card.spec.tsx +4 -4
  71. package/src/carousel/Carousel.spec.tsx +17 -17
  72. package/src/checkbox/Checkbox.spec.tsx +0 -2
  73. package/src/checkboxButton/CheckboxButton.spec.tsx +0 -2
  74. package/src/checkboxOption/CheckboxOption.spec.tsx +0 -2
  75. package/src/chevron/Chevron.spec.tsx +0 -1
  76. package/src/chips/Chips.spec.tsx +0 -1
  77. package/src/chips/Chips.story.tsx +5 -3
  78. package/src/circularButton/CircularButton.spec.tsx +4 -5
  79. package/src/common/RadioButton/RadioButton.spec.tsx +2 -2
  80. package/src/common/card/Card.story.tsx +1 -0
  81. package/src/common/closeButton/CloseButton.spec.tsx +0 -1
  82. package/src/common/flowHeader/FlowHeader.spec.tsx +0 -1
  83. package/src/dateInput/DateInput.story.tsx +21 -16
  84. package/src/dateLookup/DateLookup.rtl.spec.tsx +18 -16
  85. package/src/dateLookup/DateLookup.testingLibrary.spec.js +47 -44
  86. package/src/dateLookup/DateLookup.tests.story.tsx +4 -2
  87. package/src/decision/Decision.spec.js +0 -2
  88. package/src/dimmer/Dimmer.rtl.spec.js +10 -10
  89. package/src/drawer/Drawer.rtl.spec.tsx +2 -2
  90. package/src/emphasis/Emphasis.spec.tsx +0 -1
  91. package/src/field/Field.spec.tsx +2 -2
  92. package/src/flowNavigation/FlowNavigation.spec.js +0 -2
  93. package/src/flowNavigation/animatedLabel/AnimatedLabel.spec.js +0 -1
  94. package/src/flowNavigation/backButton/BackButton.tsx +29 -0
  95. package/src/flowNavigation/backButton/index.ts +2 -0
  96. package/src/header/Header.spec.tsx +6 -6
  97. package/src/image/Image.spec.tsx +0 -1
  98. package/src/index.ts +3 -1
  99. package/src/info/Info.story.tsx +15 -9
  100. package/src/info/Info.tsx +2 -2
  101. package/src/info/index.ts +1 -1
  102. package/src/inlineAlert/InlineAlert.spec.tsx +0 -1
  103. package/src/inputs/SelectInput.spec.tsx +26 -47
  104. package/src/link/Link.spec.tsx +0 -1
  105. package/src/listItem/ListItem.spec.tsx +0 -1
  106. package/src/moneyInput/MoneyInput.rtl.spec.tsx +2 -2
  107. package/src/moneyInput/MoneyInput.story.tsx +1 -4
  108. package/src/overlayHeader/{OverlayHeader.spec.js → OverlayHeader.spec.tsx} +1 -1
  109. package/src/overlayHeader/{OverlayHeader.story.js → OverlayHeader.story.tsx} +10 -2
  110. package/src/overlayHeader/{OverlayHeader.js → OverlayHeader.tsx} +12 -19
  111. package/src/overlayHeader/index.ts +2 -0
  112. package/src/phoneNumberInput/PhoneNumberInput.story.tsx +1 -0
  113. package/src/popover/Popover.spec.tsx +10 -10
  114. package/src/processIndicator/ProcessIndicator.tsx +1 -1
  115. package/src/progress/Progress.spec.tsx +0 -1
  116. package/src/progressBar/ProgressBar.spec.tsx +0 -1
  117. package/src/segmentedControl/SegmentedControl.spec.tsx +10 -11
  118. package/src/select/Select.spec.js +71 -71
  119. package/src/test-utils/index.js +1 -1
  120. package/src/test-utils/jest.setup.js +2 -0
  121. package/src/tooltip/Tooltip.spec.tsx +15 -16
  122. package/src/upload/Upload.spec.js +3 -14
  123. package/src/upload/Upload.story.tsx +37 -0
  124. package/src/upload/{Upload.js → Upload.tsx} +164 -169
  125. package/src/upload/index.ts +2 -0
  126. package/src/upload/steps/completeStep/completeStep.spec.js +3 -2
  127. package/src/upload/steps/completeStep/completeStep.tsx +74 -0
  128. package/src/upload/steps/completeStep/index.ts +2 -0
  129. package/src/upload/steps/{index.js → index.ts} +0 -1
  130. package/src/upload/steps/processingStep/index.ts +2 -0
  131. package/src/upload/steps/processingStep/processingStep.tsx +53 -0
  132. package/src/upload/steps/uploadImageStep/index.ts +2 -0
  133. package/src/upload/steps/uploadImageStep/{uploadImageStep.js → uploadImageStep.tsx} +17 -23
  134. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.ts +14 -0
  135. package/src/upload/utils/asyncFileRead/asyncFileRead.ts +12 -0
  136. package/src/upload/utils/getFileType/getFileType.spec.ts +22 -0
  137. package/src/upload/utils/getFileType/getFileType.ts +16 -0
  138. package/src/upload/utils/{index.js → index.ts} +0 -2
  139. package/src/upload/utils/isSizeValid/{isSizeValid.spec.js → isSizeValid.spec.ts} +3 -3
  140. package/src/upload/utils/isSizeValid/isSizeValid.ts +3 -0
  141. package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +62 -0
  142. package/src/upload/utils/isTypeValid/isTypeValid.ts +19 -0
  143. package/src/upload/utils/postData/postData.spec.ts +65 -0
  144. package/src/upload/utils/postData/postData.ts +36 -0
  145. package/src/uploadInput/UploadInput.spec.tsx +9 -10
  146. package/src/uploadInput/UploadInput.story.tsx +8 -180
  147. package/src/uploadInput/UploadInput.tests.story.tsx +212 -0
  148. package/src/uploadInput/UploadInput.tsx +1 -1
  149. package/src/uploadInput/uploadButton/UploadButton.spec.tsx +4 -4
  150. package/src/uploadInput/uploadItem/UploadItem.spec.tsx +4 -4
  151. package/build/types/upload/steps/mediaUploadStep/index.d.ts +0 -2
  152. package/build/types/upload/steps/mediaUploadStep/index.d.ts.map +0 -1
  153. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts +0 -24
  154. package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts.map +0 -1
  155. package/build/types/upload/uploadSteps.d.ts +0 -5
  156. package/build/types/upload/uploadSteps.d.ts.map +0 -1
  157. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts +0 -2
  158. package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts.map +0 -1
  159. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts +0 -2
  160. package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts.map +0 -1
  161. package/build/types/upload/utils/requestMedia/index.d.ts +0 -2
  162. package/build/types/upload/utils/requestMedia/index.d.ts.map +0 -1
  163. package/build/types/upload/utils/requestMedia/requestMedia.d.ts +0 -2
  164. package/build/types/upload/utils/requestMedia/requestMedia.d.ts.map +0 -1
  165. package/src/flowNavigation/backButton/BackButton.js +0 -32
  166. package/src/flowNavigation/backButton/BackButton.spec.js +0 -16
  167. package/src/flowNavigation/backButton/__snapshots__/BackButton.spec.js.snap +0 -37
  168. package/src/flowNavigation/backButton/index.js +0 -3
  169. package/src/overlayHeader/index.js +0 -1
  170. package/src/upload/Upload.story.js +0 -36
  171. package/src/upload/index.js +0 -2
  172. package/src/upload/steps/completeStep/completeStep.js +0 -98
  173. package/src/upload/steps/completeStep/index.js +0 -1
  174. package/src/upload/steps/mediaUploadStep/index.js +0 -1
  175. package/src/upload/steps/mediaUploadStep/mediaUploadStep.js +0 -80
  176. package/src/upload/steps/mediaUploadStep/mediaUploadStep.spec.js +0 -77
  177. package/src/upload/steps/processingStep/index.js +0 -1
  178. package/src/upload/steps/processingStep/processingStep.js +0 -73
  179. package/src/upload/steps/uploadImageStep/index.js +0 -1
  180. package/src/upload/uploadSteps.ts +0 -5
  181. package/src/upload/utils/asyncFileRead/asyncFileRead.js +0 -11
  182. package/src/upload/utils/asyncFileRead/asyncFileRead.spec.js +0 -17
  183. package/src/upload/utils/getFileType/getFileType.js +0 -19
  184. package/src/upload/utils/getFileType/getFileType.spec.js +0 -33
  185. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js +0 -18
  186. package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.spec.js +0 -22
  187. package/src/upload/utils/getSupportedSpotMimeTypes/index.js +0 -1
  188. package/src/upload/utils/isSizeValid/isSizeValid.js +0 -1
  189. package/src/upload/utils/isTypeValid/isTypeValid.js +0 -26
  190. package/src/upload/utils/isTypeValid/isTypeValid.spec.js +0 -68
  191. package/src/upload/utils/postData/postData.js +0 -18
  192. package/src/upload/utils/postData/postData.spec.js +0 -109
  193. package/src/upload/utils/requestMedia/index.js +0 -1
  194. package/src/upload/utils/requestMedia/requestMedia.js +0 -26
  195. package/src/upload/utils/requestMedia/requestMedia.spec.js +0 -44
  196. /package/src/overlayHeader/__snapshots__/{OverlayHeader.spec.js.snap → OverlayHeader.spec.tsx.snap} +0 -0
  197. /package/src/upload/{Upload.messages.js → Upload.messages.ts} +0 -0
  198. /package/src/upload/utils/asyncFileRead/{index.js → index.ts} +0 -0
  199. /package/src/upload/utils/getFileType/{index.js → index.ts} +0 -0
  200. /package/src/upload/utils/isSizeValid/{index.js → index.ts} +0 -0
  201. /package/src/upload/utils/isTypeValid/{index.js → index.ts} +0 -0
  202. /package/src/upload/utils/postData/{index.js → index.ts} +0 -0
package/build/index.js CHANGED
@@ -17,8 +17,8 @@ var mergeProps = require('merge-props');
17
17
  var react = require('@floating-ui/react');
18
18
  var overlays = require('@react-aria/overlays');
19
19
  var reactPopper = require('react-popper');
20
- var PropTypes = require('prop-types');
21
20
  var art = require('@wise/art');
21
+ var PropTypes = require('prop-types');
22
22
  var clamp$2 = require('lodash.clamp');
23
23
  var debounce = require('lodash.debounce');
24
24
  var web = require('@react-spring/web');
@@ -5330,33 +5330,25 @@ const AnimatedLabel = ({
5330
5330
  });
5331
5331
  };
5332
5332
 
5333
- const BackButton = ({
5333
+ function BackButton({
5334
5334
  className,
5335
5335
  onClick,
5336
5336
  'aria-label': ariaLabel
5337
- }) => /*#__PURE__*/jsxRuntime.jsx(Avatar, {
5338
- type: exports.AvatarType.ICON,
5339
- size: 40,
5340
- children: /*#__PURE__*/jsxRuntime.jsx("button", {
5341
- type: "button",
5342
- "aria-label": ariaLabel,
5343
- className: classNames__default.default('np-back-button', 'btn-unstyled', className),
5344
- onClick: onClick,
5345
- children: /*#__PURE__*/jsxRuntime.jsx(icons.ArrowLeft, {
5346
- size: 24
5337
+ }) {
5338
+ return /*#__PURE__*/jsxRuntime.jsx(Avatar, {
5339
+ type: exports.AvatarType.ICON,
5340
+ size: 40,
5341
+ children: /*#__PURE__*/jsxRuntime.jsx("button", {
5342
+ type: "button",
5343
+ "aria-label": ariaLabel,
5344
+ className: classNames__default.default('np-back-button', 'btn-unstyled', className),
5345
+ onClick: onClick,
5346
+ children: /*#__PURE__*/jsxRuntime.jsx(icons.ArrowLeft, {
5347
+ size: 24
5348
+ })
5347
5349
  })
5348
- })
5349
- });
5350
- BackButton.propTypes = {
5351
- 'aria-label': PropTypes__default.default.string.isRequired,
5352
- className: PropTypes__default.default.string,
5353
- label: PropTypes__default.default.element,
5354
- onClick: PropTypes__default.default.func
5355
- };
5356
- BackButton.defaultProps = {
5357
- className: undefined,
5358
- label: undefined
5359
- };
5350
+ });
5351
+ }
5360
5352
 
5361
5353
  const FlowNavigation = ({
5362
5354
  activeStep = 0,
@@ -7763,11 +7755,12 @@ const Nudge = ({
7763
7755
  });
7764
7756
  };
7765
7757
 
7766
- const OverlayHeader = ({
7758
+ const defaultLogo = /*#__PURE__*/jsxRuntime.jsx(Logo, {});
7759
+ function OverlayHeader({
7767
7760
  avatar,
7768
7761
  onClose,
7769
- logo
7770
- }) => {
7762
+ logo = defaultLogo
7763
+ }) {
7771
7764
  const closeButton = onClose && /*#__PURE__*/jsxRuntime.jsx(CloseButton, {
7772
7765
  size: exports.Size.LARGE,
7773
7766
  onClick: onClose
@@ -7785,20 +7778,7 @@ const OverlayHeader = ({
7785
7778
  })
7786
7779
  })
7787
7780
  });
7788
- };
7789
- OverlayHeader.defaultProps = {
7790
- avatar: null,
7791
- logo: /*#__PURE__*/jsxRuntime.jsx(Logo, {}),
7792
- onClose: null
7793
- };
7794
- OverlayHeader.propTypes = {
7795
- /** An Avatar */
7796
- avatar: PropTypes__default.default.element,
7797
- logo: PropTypes__default.default.node,
7798
- /** Function called when the close is clicked */
7799
- onClose: PropTypes__default.default.func
7800
- };
7801
- var OverlayHeader$1 = OverlayHeader;
7781
+ }
7802
7782
 
7803
7783
  var messages$3 = reactIntl.defineMessages({
7804
7784
  selectInputPlaceholder: {
@@ -12108,13 +12088,6 @@ var Typeahead$1 = withInputAttributes(Typeahead, {
12108
12088
  nonLabelable: true
12109
12089
  });
12110
12090
 
12111
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
12112
- exports.UploadStep = void 0;
12113
- (function (UploadStep) {
12114
- UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12115
- UploadStep["MEDIA_UPLOAD_STEP"] = "mediaUploadStep";
12116
- })(exports.UploadStep || (exports.UploadStep = {}));
12117
-
12118
12091
  var messages = reactIntl.defineMessages({
12119
12092
  csButtonText: {
12120
12093
  id: "neptune.Upload.csButtonText"
@@ -12149,16 +12122,13 @@ var messages = reactIntl.defineMessages({
12149
12122
  });
12150
12123
 
12151
12124
  class UploadImageStep extends React.PureComponent {
12152
- constructor() {
12153
- super();
12154
- this.uploadInputRef = /*#__PURE__*/React.createRef();
12155
- }
12125
+ uploadInputRef = /*#__PURE__*/React.createRef();
12156
12126
  onManualUpload = () => {
12157
12127
  const {
12158
12128
  fileDropped
12159
12129
  } = this.props;
12160
- if (this.uploadInputRef && this.uploadInputRef.current) {
12161
- const file = this.uploadInputRef.current.files[0];
12130
+ const file = this.uploadInputRef.current?.files?.[0];
12131
+ if (file != null) {
12162
12132
  fileDropped(file);
12163
12133
  }
12164
12134
  };
@@ -12207,7 +12177,7 @@ class UploadImageStep extends React.PureComponent {
12207
12177
  children: usLabel
12208
12178
  }), usPlaceholder && /*#__PURE__*/jsxRuntime.jsx("p", {
12209
12179
  className: "np-text-body-large m-b-3",
12210
- children: `${usPlaceholder}`
12180
+ children: String(usPlaceholder)
12211
12181
  }), /*#__PURE__*/jsxRuntime.jsxs("label", {
12212
12182
  className: `btn btn-primary btn-md ${usDisabled ? 'disabled' : ''}`,
12213
12183
  children: [usButtonText ? /*#__PURE__*/jsxRuntime.jsx("span", {
@@ -12218,7 +12188,7 @@ class UploadImageStep extends React.PureComponent {
12218
12188
  }), /*#__PURE__*/jsxRuntime.jsx("input", {
12219
12189
  ref: this.uploadInputRef,
12220
12190
  type: "file",
12221
- accept: usAccept === '*' ? null : usAccept,
12191
+ accept: usAccept === '*' ? undefined : usAccept,
12222
12192
  className: "tw-droppable-input hidden",
12223
12193
  disabled: usDisabled,
12224
12194
  name: "file-upload",
@@ -12230,213 +12200,17 @@ class UploadImageStep extends React.PureComponent {
12230
12200
  });
12231
12201
  }
12232
12202
  }
12233
- UploadImageStep.propTypes = {
12234
- fileDropped: PropTypes__default.default.func.isRequired,
12235
- isComplete: PropTypes__default.default.bool.isRequired,
12236
- usAccept: PropTypes__default.default.string.isRequired,
12237
- usButtonText: PropTypes__default.default.string.isRequired,
12238
- usDisabled: PropTypes__default.default.bool.isRequired,
12239
- usHelpImage: PropTypes__default.default.node.isRequired,
12240
- usLabel: PropTypes__default.default.string.isRequired,
12241
- usPlaceholder: PropTypes__default.default.string.isRequired
12242
- };
12243
-
12244
- const postData = (httpOptions, data = {}, fetcher = fetch) => fetcher(`${httpOptions.url}`, {
12245
- method: 'POST',
12246
- body: data,
12247
- ...httpOptions
12248
- }).then(response => {
12249
- if (!response.ok) {
12250
- const error = new Error(response.statusText);
12251
- error.status = response.status;
12252
- error.response = response;
12253
- throw error;
12254
- }
12255
- return response;
12256
- }).catch(error => {
12257
- throw error;
12258
- });
12259
-
12260
- const asyncFileRead = file => new Promise((resolve, reject) => {
12261
- const reader = new FileReader();
12262
- reader.readAsDataURL(file);
12263
- reader.addEventListener('load', event => {
12264
- resolve(event.target.result);
12265
- });
12266
- reader.addEventListener('error', event => {
12267
- reject(event);
12268
- });
12269
- });
12270
-
12271
- const isSizeValid = (file, maxSize) => Number.isInteger(maxSize) && file.size <= maxSize;
12272
-
12273
- const getFileType = (file, file64) => {
12274
- if (!file && !file64) {
12275
- return '';
12276
- }
12277
- if (file && file.type && file.type !== '') {
12278
- return file.type ?? '';
12279
- }
12280
- if (file64) {
12281
- const regex = /^data:([a-z]+\/[a-z]+);/;
12282
- const typeFromEncoded = file64.match(regex);
12283
- if (typeFromEncoded && typeFromEncoded[1]) {
12284
- return typeFromEncoded[1] ?? '';
12285
- }
12286
- }
12287
- return '';
12288
- };
12289
12203
 
12290
- const isTypeValid = (file, rule, file64) => {
12291
- if (!file || !rule) {
12292
- return false;
12293
- }
12294
- const allowedTypes = rule.replace(/\s/g, '').split(',');
12295
- const fileType = getFileType(file, file64);
12296
- if (rule === '*' || allowedTypes.includes(fileType)) {
12297
- return true;
12298
- }
12299
- return allowedTypes.some(type => {
12300
- const splittedRule = type.split('/');
12301
- const typeAllowed = splittedRule[0];
12302
- const extensionAllowed = splittedRule[1];
12303
- if (extensionAllowed !== '*') {
12304
- return false;
12305
- }
12306
- return fileType.includes(typeAllowed);
12307
- });
12308
- };
12309
-
12310
- // Spot Platform's Media API only support these MIME types
12311
- const SUPPORTED_MIME_TYPES = ['image/jpeg', 'video/*', 'application/pdf'];
12312
- const getSupportedSpotMimeTypes = mimeTypes => {
12313
- if (mimeTypes === '*') {
12314
- return SUPPORTED_MIME_TYPES;
12315
- }
12316
- const mimeTypesArray = mimeTypes.split(',');
12317
- const mimeMapping = {
12318
- 'image/*': 'image/jpeg',
12319
- 'application/*': 'application/pdf'
12320
- };
12321
- const mapSupportedMimeTypes = mimeTypesArray.map(type => mimeMapping[type] || type);
12322
- return mapSupportedMimeTypes.filter(type => SUPPORTED_MIME_TYPES.includes(type));
12323
- };
12324
-
12325
- const requestMedia = mediaRequest => new Promise((resolve, reject) => {
12326
- if (typeof window === 'undefined' || typeof window.microapps === 'undefined') {
12327
- reject(`microapps must be available in window to use Spot Platform's Media API`);
12328
- }
12329
- window.microapps.requestMedia(mediaRequest).then(response => {
12330
- const fileByteArray = base64ToByteArray(response.bytes);
12331
- const blob = new Blob([fileByteArray], {
12332
- type: response.mimeType
12333
- });
12334
- resolve(blob);
12335
- }).catch(error => reject(error));
12336
- });
12337
- const base64ToByteArray = base64String => {
12338
- const byteCharacters = atob(base64String);
12339
- const byteCharactersLength = byteCharacters.length;
12340
- const byteArray = new Array(byteCharactersLength);
12341
- for (let i = 0; i < byteCharactersLength; i += 1) {
12342
- byteArray[i] = byteCharacters.charCodeAt(i);
12343
- }
12344
- return new Uint8Array(byteArray);
12345
- };
12346
-
12347
- const MediaUploadStep = ({
12204
+ function ProcessingStep({
12348
12205
  isComplete,
12349
- usAccept,
12350
- usButtonText,
12351
- usDisabled,
12352
- usHelpImage,
12353
- usLabel,
12354
- usPlaceholder,
12355
- fileDropped
12356
- }) => {
12357
- const getMediaFile = () => {
12358
- const allowedMimeTypes = getSupportedSpotMimeTypes(usAccept);
12359
- if (allowedMimeTypes.length === 0) {
12360
- throw new Error('provided mimeTypes not supported');
12361
- }
12362
- const mediaRequest = {
12363
- allowedMimeTypes
12364
- };
12365
- requestMedia(mediaRequest).then(file => fileDropped(file));
12366
- };
12367
- const getImage = () => {
12368
- if (!usHelpImage) {
12369
- return /*#__PURE__*/jsxRuntime.jsx("div", {
12370
- className: "circle circle-sm circle-inverse p-t-1",
12371
- children: /*#__PURE__*/jsxRuntime.jsx(icons.Upload, {
12372
- size: 24
12373
- })
12374
- });
12375
- }
12376
- if (typeof usHelpImage === 'string') {
12377
- return /*#__PURE__*/jsxRuntime.jsx("img", {
12378
- src: usHelpImage,
12379
- alt: usLabel,
12380
- className: "thumbnail text-xs-center"
12381
- });
12382
- }
12383
- return usHelpImage;
12384
- };
12385
- return /*#__PURE__*/jsxRuntime.jsx("div", {
12386
- children: /*#__PURE__*/jsxRuntime.jsx("div", {
12387
- className: "droppable-default-card",
12388
- "aria-hidden": isComplete,
12389
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12390
- className: "droppable-card-content",
12391
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
12392
- className: "m-b-3",
12393
- children: getImage()
12394
- }), usLabel && /*#__PURE__*/jsxRuntime.jsx(Title, {
12395
- type: exports.Typography.TITLE_BODY,
12396
- className: "m-b-1",
12397
- children: usLabel
12398
- }), usPlaceholder && /*#__PURE__*/jsxRuntime.jsx(Body, {
12399
- as: "p",
12400
- type: exports.Typography.BODY_LARGE,
12401
- className: "m-b-3",
12402
- children: `${usPlaceholder}`
12403
- }), /*#__PURE__*/jsxRuntime.jsx(Button, {
12404
- disabled: usDisabled,
12405
- onClick: getMediaFile,
12406
- children: usButtonText || /*#__PURE__*/jsxRuntime.jsx(icons.Upload, {
12407
- size: 24,
12408
- className: "m-r-0"
12409
- })
12410
- })]
12411
- })
12412
- })
12413
- });
12414
- };
12415
- MediaUploadStep.propTypes = {
12416
- fileDropped: PropTypes__default.default.func.isRequired,
12417
- isComplete: PropTypes__default.default.bool.isRequired,
12418
- usAccept: PropTypes__default.default.string.isRequired,
12419
- usButtonText: PropTypes__default.default.string.isRequired,
12420
- usDisabled: PropTypes__default.default.bool.isRequired,
12421
- usHelpImage: PropTypes__default.default.node.isRequired,
12422
- usLabel: PropTypes__default.default.string.isRequired,
12423
- usPlaceholder: PropTypes__default.default.string.isRequired
12424
- };
12425
-
12426
- const ProcessingStep = props => {
12427
- const {
12428
- isComplete,
12429
- isError,
12430
- isSuccess,
12431
- onAnimationCompleted,
12432
- onClear,
12433
- psButtonText,
12434
- psProcessingText,
12435
- psButtonDisabled
12436
- } = props;
12437
- const {
12438
- isModern
12439
- } = componentsTheming.useTheme();
12206
+ isError,
12207
+ isSuccess,
12208
+ onAnimationCompleted,
12209
+ onClear,
12210
+ psButtonText,
12211
+ psProcessingText,
12212
+ psButtonDisabled
12213
+ }) {
12440
12214
  let processStatus = exports.Status.PROCESSING;
12441
12215
  if (isError) {
12442
12216
  processStatus = exports.Status.FAILED;
@@ -12450,53 +12224,33 @@ const ProcessingStep = props => {
12450
12224
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
12451
12225
  className: "droppable-card-content",
12452
12226
  children: [/*#__PURE__*/jsxRuntime.jsx(ProcessIndicator, {
12453
- size: exports.Size.Small,
12454
12227
  status: processStatus,
12455
12228
  onAnimationCompleted: status => onAnimationCompleted(status)
12456
12229
  }), /*#__PURE__*/jsxRuntime.jsx(Title, {
12457
- className: classNames__default.default({
12458
- 'm-t-3': !isModern,
12459
- 'm-b-3': !isModern,
12460
- 'm-t-2': isModern,
12461
- 'm-b-2': isModern
12462
- }),
12230
+ className: "m-y-2",
12463
12231
  type: exports.Typography.TITLE_BODY,
12464
12232
  "aria-live": "polite",
12465
12233
  children: psProcessingText
12466
12234
  }), psButtonText && /*#__PURE__*/jsxRuntime.jsx(Button, {
12467
12235
  disabled: psButtonDisabled,
12468
- onClick: event => onClear(event),
12236
+ onClick: onClear,
12469
12237
  children: psButtonText
12470
12238
  })]
12471
12239
  })
12472
12240
  });
12473
- };
12474
- ProcessingStep.propTypes = {
12475
- isComplete: PropTypes__default.default.bool.isRequired,
12476
- isError: PropTypes__default.default.bool.isRequired,
12477
- isSuccess: PropTypes__default.default.bool.isRequired,
12478
- onAnimationCompleted: PropTypes__default.default.func.isRequired,
12479
- onClear: PropTypes__default.default.func.isRequired,
12480
- psButtonText: PropTypes__default.default.string.isRequired,
12481
- psProcessingText: PropTypes__default.default.string.isRequired,
12482
- psButtonDisabled: PropTypes__default.default.bool.isRequired
12483
- };
12241
+ }
12484
12242
 
12485
- const CompleteStep = props => {
12486
- const {
12487
- isModern
12488
- } = componentsTheming.useTheme();
12489
- const {
12490
- csButtonText,
12491
- csFailureText,
12492
- csSuccessText,
12493
- fileName,
12494
- isComplete,
12495
- isError,
12496
- isImage,
12497
- onClear,
12498
- uploadedImage
12499
- } = props;
12243
+ function CompleteStep({
12244
+ csButtonText,
12245
+ csFailureText,
12246
+ csSuccessText,
12247
+ fileName,
12248
+ isComplete,
12249
+ isError,
12250
+ isImage,
12251
+ onClear,
12252
+ uploadedImage
12253
+ }) {
12500
12254
  return /*#__PURE__*/jsxRuntime.jsx("div", {
12501
12255
  className: "droppable-complete-card droppable-card",
12502
12256
  "aria-hidden": !isComplete,
@@ -12506,16 +12260,11 @@ const CompleteStep = props => {
12506
12260
  className: "droppable-card-content d-flex flex-column align-items-center",
12507
12261
  "aria-live": "polite",
12508
12262
  children: isError ? /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
12509
- children: [isModern ? /*#__PURE__*/jsxRuntime.jsx(StatusIcon, {
12263
+ children: [/*#__PURE__*/jsxRuntime.jsx(StatusIcon, {
12510
12264
  size: exports.Size.LARGE,
12511
12265
  sentiment: exports.Sentiment.NEGATIVE
12512
- }) : /*#__PURE__*/jsxRuntime.jsx(icons.AlertCircle, {
12513
- size: 24,
12514
- className: "text-negative"
12515
12266
  }), csFailureText && /*#__PURE__*/jsxRuntime.jsx("p", {
12516
- className: classNames__default.default('m-t-2', {
12517
- 'm-b-0': isModern
12518
- }),
12267
+ className: "m-t-2 m-b-0",
12519
12268
  children: csFailureText
12520
12269
  })]
12521
12270
  }) : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
@@ -12534,71 +12283,135 @@ const CompleteStep = props => {
12534
12283
  })]
12535
12284
  })
12536
12285
  }), csButtonText && /*#__PURE__*/jsxRuntime.jsx(Button, {
12537
- priority: isModern ? exports.Priority.PRIMARY : exports.Priority.SECONDARY,
12538
- className: classNames__default.default({
12539
- 'm-t-1': isModern && !isError,
12540
- 'm-t-2': isModern && isError,
12541
- 'm-t-3': !isModern
12542
- }),
12543
- onClick: event => onClear(event),
12286
+ className: isError ? 'm-t-2' : 'm-t-1',
12287
+ onClick: onClear,
12544
12288
  children: csButtonText
12545
12289
  })]
12546
12290
  })
12547
12291
  });
12548
- };
12549
- CompleteStep.propTypes = {
12550
- csButtonText: PropTypes__default.default.string.isRequired,
12551
- csSuccessText: PropTypes__default.default.string.isRequired,
12552
- csFailureText: PropTypes__default.default.string.isRequired,
12553
- fileName: PropTypes__default.default.string.isRequired,
12554
- isComplete: PropTypes__default.default.bool.isRequired,
12555
- isError: PropTypes__default.default.bool.isRequired,
12556
- isImage: PropTypes__default.default.bool.isRequired,
12557
- onClear: PropTypes__default.default.func.isRequired,
12558
- uploadedImage: PropTypes__default.default.string
12559
- };
12560
- CompleteStep.defaultProps = {
12561
- uploadedImage: null
12562
- };
12292
+ }
12293
+
12294
+ class ResponseError extends Error {
12295
+ response;
12296
+ status;
12297
+ constructor(response, message) {
12298
+ super(message);
12299
+ this.name = 'ResponseError';
12300
+ this.response = response;
12301
+ this.status = response.status;
12302
+ }
12303
+ }
12304
+ async function postData({
12305
+ url,
12306
+ method = 'POST',
12307
+ ...httpOptions
12308
+ }, data, fetcher = fetch) {
12309
+ const response = await fetcher(url, {
12310
+ method,
12311
+ body: data,
12312
+ ...httpOptions
12313
+ });
12314
+ if (!response.ok) {
12315
+ throw new ResponseError(response, response.statusText);
12316
+ }
12317
+ return response;
12318
+ }
12563
12319
 
12564
- const PROCESS_STATE = ['error', 'success'];
12320
+ async function asyncFileRead(file) {
12321
+ return new Promise((resolve, reject) => {
12322
+ const reader = new FileReader();
12323
+ reader.addEventListener('load', () => {
12324
+ resolve(reader.result);
12325
+ });
12326
+ reader.addEventListener('error', () => {
12327
+ reject(reader.error ?? new Error('Cannot read file'));
12328
+ });
12329
+ reader.readAsDataURL(file);
12330
+ });
12331
+ }
12332
+
12333
+ function isSizeValid(file, maxSize) {
12334
+ return Number.isInteger(maxSize) && file.size <= maxSize;
12335
+ }
12336
+
12337
+ function getFileType(file, file64) {
12338
+ if (file.type) {
12339
+ return file.type;
12340
+ }
12341
+ if (file64) {
12342
+ const regex = /^data:([a-z]+\/[a-z]+);/;
12343
+ const typeFromEncoded = regex.exec(file64);
12344
+ if (typeFromEncoded?.[1]) {
12345
+ return typeFromEncoded[1];
12346
+ }
12347
+ }
12348
+ return '';
12349
+ }
12350
+
12351
+ function isTypeValid(file, rule, file64) {
12352
+ if (!rule) {
12353
+ return false;
12354
+ }
12355
+ const allowedTypes = rule.replace(/\s/g, '').split(',');
12356
+ const fileType = getFileType(file, file64);
12357
+ if (rule === '*' || allowedTypes.includes(fileType)) {
12358
+ return true;
12359
+ }
12360
+ return allowedTypes.some(type => {
12361
+ const [typeAllowed, extensionAllowed] = type.split('/');
12362
+ return extensionAllowed === '*' && fileType.includes(typeAllowed);
12363
+ });
12364
+ }
12565
12365
 
12566
- /*
12567
- * This delay is required for the isError/isSuccess to be fired after isProcessing so the processIndicator, will be
12568
- * rendered first and then updated with the right status.
12569
- */
12570
12366
  const ANIMATION_FIX = 10;
12571
12367
  const MAX_SIZE_DEFAULT = 5000000;
12572
- const UPLOAD_STEP_COMPONENTS = {
12573
- [exports.UploadStep.UPLOAD_IMAGE_STEP]: UploadImageStep,
12574
- [exports.UploadStep.MEDIA_UPLOAD_STEP]: MediaUploadStep
12575
- };
12368
+ exports.UploadStep = void 0;
12369
+ (function (UploadStep) {
12370
+ UploadStep["UPLOAD_IMAGE_STEP"] = "uploadImageStep";
12371
+ })(exports.UploadStep || (exports.UploadStep = {}));
12576
12372
  class Upload extends React.Component {
12373
+ static defaultProps = {
12374
+ animationDelay: 700,
12375
+ maxSize: MAX_SIZE_DEFAULT,
12376
+ psButtonDisabled: false,
12377
+ size: 'md',
12378
+ usAccept: 'image/*',
12379
+ usDisabled: false,
12380
+ usLabel: ''
12381
+ };
12382
+ dragCounter = 0;
12383
+ timeouts = 0;
12577
12384
  constructor(props) {
12578
12385
  super(props);
12579
- this.dragCounter = 0;
12580
- this.timeouts = null;
12581
12386
  this.state = {
12582
12387
  fileName: '',
12388
+ isDroppable: false,
12583
12389
  isComplete: false,
12584
12390
  isError: false,
12585
12391
  isImage: false,
12586
12392
  isProcessing: false,
12587
12393
  isSuccess: false,
12588
- response: null,
12589
- uploadedImage: null
12394
+ response: undefined,
12395
+ uploadedImage: undefined
12590
12396
  };
12591
12397
  }
12592
12398
  getErrorMessage(status) {
12399
+ const {
12400
+ csFailureText,
12401
+ csTooLargeMessage,
12402
+ csWrongTypeMessage,
12403
+ maxSize,
12404
+ intl
12405
+ } = this.props;
12593
12406
  switch (status) {
12594
12407
  case 413:
12595
- return this.props.csTooLargeMessage || this.props.intl.formatMessage(messages.csTooLargeMessage, {
12596
- maxSize: this.props.maxSize / 1000000
12408
+ return csTooLargeMessage || intl.formatMessage(messages.csTooLargeMessage, {
12409
+ maxSize: maxSize / 1000000
12597
12410
  });
12598
12411
  case 415:
12599
- return this.props.csWrongTypeMessage || this.props.intl.formatMessage(messages.csWrongTypeMessage);
12412
+ return csWrongTypeMessage || intl.formatMessage(messages.csWrongTypeMessage);
12600
12413
  default:
12601
- return this.props.csFailureText || this.props.intl.formatMessage(messages.csFailureText);
12414
+ return csFailureText || intl.formatMessage(messages.csFailureText);
12602
12415
  }
12603
12416
  }
12604
12417
  onDragLeave(event) {
@@ -12625,7 +12438,7 @@ class Upload extends React.Component {
12625
12438
  });
12626
12439
  }
12627
12440
  }
12628
- onDrop(event) {
12441
+ async onDrop(event) {
12629
12442
  const {
12630
12443
  isProcessing
12631
12444
  } = this.state;
@@ -12633,8 +12446,8 @@ class Upload extends React.Component {
12633
12446
  if (!isProcessing) {
12634
12447
  this.reset();
12635
12448
  }
12636
- if (event.dataTransfer && event.dataTransfer.files && event.dataTransfer.files[0]) {
12637
- this.fileDropped(event.dataTransfer.files[0]);
12449
+ if (event.dataTransfer?.files?.[0]) {
12450
+ await this.fileDropped(event.dataTransfer.files[0]);
12638
12451
  }
12639
12452
  }
12640
12453
  onAnimationCompleted = async status => {
@@ -12643,77 +12456,70 @@ class Upload extends React.Component {
12643
12456
  isProcessing,
12644
12457
  fileName
12645
12458
  } = this.state;
12646
- // Success.
12647
12459
  const {
12648
12460
  animationDelay
12649
12461
  } = this.props;
12650
- if (isProcessing && status === exports.Status.SUCCEEDED) {
12462
+ if (isProcessing && status === 'succeeded') {
12651
12463
  const {
12652
12464
  onSuccess
12653
12465
  } = this.props;
12654
- this.timeouts = setTimeout(() => {
12466
+ this.timeouts = window.setTimeout(() => {
12655
12467
  this.setState({
12656
12468
  isProcessing: false,
12657
12469
  isComplete: true
12658
- }, () => onSuccess ? onSuccess(response, fileName) : {});
12470
+ }, onSuccess ? () => onSuccess(response, fileName) : undefined);
12659
12471
  }, animationDelay);
12660
12472
  }
12661
- // Failure.
12662
- if (isProcessing && status === exports.Status.FAILED) {
12473
+ if (isProcessing && status === 'failed') {
12663
12474
  const {
12664
12475
  onFailure
12665
12476
  } = this.props;
12666
- this.timeouts = setTimeout(() => {
12477
+ this.timeouts = window.setTimeout(() => {
12667
12478
  this.setState({
12668
12479
  isProcessing: false,
12669
12480
  isComplete: true
12670
- }, () => onFailure ? onFailure(response) : {});
12481
+ }, onFailure ? () => onFailure(response) : undefined);
12671
12482
  }, animationDelay);
12672
12483
  }
12673
12484
  };
12674
- asyncPost = file => {
12485
+ asyncPost = async file => {
12675
12486
  const {
12676
12487
  httpOptions,
12677
12488
  fetcher
12678
12489
  } = this.props;
12490
+ if (httpOptions == null) {
12491
+ throw new Error('Cannot find HTTP options');
12492
+ }
12679
12493
  const {
12680
12494
  fileInputName = file.name,
12681
12495
  data = {}
12682
- } = httpOptions || {};
12496
+ } = httpOptions;
12683
12497
  const formData = new FormData();
12684
12498
  formData.append(fileInputName, file);
12685
12499
  Object.keys(data).forEach(key => formData.append(key, data[key]));
12686
- return postData(this.prepareHttpOptions(httpOptions), formData, fetcher);
12500
+ return postData(httpOptions, formData, fetcher);
12687
12501
  };
12688
12502
  asyncResponse = (response, type) => {
12689
12503
  // Gives time to the animation callback to fire.
12690
- this.timeouts = setTimeout(() => {
12504
+ this.timeouts = window.setTimeout(() => {
12691
12505
  this.setState({
12692
12506
  response,
12693
- isError: type === PROCESS_STATE[0],
12694
- isSuccess: type === PROCESS_STATE[1]
12507
+ isError: type === 'error',
12508
+ isSuccess: type === 'success'
12695
12509
  });
12696
12510
  }, ANIMATION_FIX);
12697
12511
  };
12698
- prepareHttpOptions = httpOptions => {
12699
- if (!httpOptions.url) {
12700
- throw new Error('You must supply a URL to post image data asynchronously');
12701
- }
12702
- return httpOptions;
12703
- };
12704
12512
  handleOnClear = event => {
12705
12513
  event.preventDefault();
12706
12514
  const {
12707
12515
  onCancel
12708
12516
  } = this.props;
12709
- if (onCancel) {
12710
- onCancel();
12711
- }
12517
+ onCancel?.();
12712
12518
  this.reset();
12713
12519
  };
12714
12520
  reset = () => {
12715
12521
  this.dragCounter = 0;
12716
- clearTimeout(this.timeouts);
12522
+ window.clearTimeout(this.timeouts);
12717
12523
  this.setState({
12718
12524
  isComplete: false,
12719
12525
  isError: false,
@@ -12753,14 +12559,12 @@ class Upload extends React.Component {
12753
12559
  isDroppable: false,
12754
12560
  isProcessing: true
12755
12561
  });
12756
- if (onStart) {
12757
- onStart(file);
12758
- }
12562
+ onStart?.(file);
12759
12563
  let file64 = null;
12760
12564
  try {
12761
12565
  file64 = await asyncFileRead(file);
12762
12566
  } catch (error) {
12763
- this.asyncResponse(error, PROCESS_STATE[0]);
12567
+ this.asyncResponse(error, 'error');
12764
12568
  }
12765
12569
  if (!file64) {
12766
12570
  return false;
@@ -12769,30 +12573,31 @@ class Upload extends React.Component {
12769
12573
  isImage: getFileType(file, file64).includes('image')
12770
12574
  });
12771
12575
  if (!isTypeValid(file, usAccept, file64)) {
12772
- const response = {
12576
+ this.asyncResponse(new ResponseError(new Response(null, {
12773
12577
  status: 415,
12774
12578
  statusText: 'Unsupported Media Type'
12775
- };
12776
- this.asyncResponse(response, PROCESS_STATE[0]);
12579
+ })), 'error');
12777
12580
  return false;
12778
12581
  }
12779
12582
  if (!isSizeValid(file, maxSize)) {
12780
- const response = {
12583
+ this.asyncResponse(new ResponseError(new Response(null, {
12781
12584
  status: 413,
12782
12585
  statusText: 'Request Entity Too Large'
12783
- };
12784
- this.asyncResponse(response, PROCESS_STATE[0]);
12586
+ })), 'error');
12785
12587
  return false;
12786
12588
  }
12787
12589
  if (httpOptions) {
12788
12590
  // Post the file to provided endpoint
12789
- return await this.asyncPost(file).then(response => this.asyncResponse(response, 'success')).then(() => {
12790
- this.showDataImage(file64);
12791
- return true;
12792
- }).catch(error => {
12793
- this.asyncResponse(error, PROCESS_STATE[0]);
12591
+ let response;
12592
+ try {
12593
+ response = await this.asyncPost(file);
12594
+ } catch (error) {
12595
+ this.asyncResponse(error, 'error');
12794
12596
  return false;
12795
- });
12597
+ }
12598
+ this.asyncResponse(response, 'success');
12599
+ this.showDataImage(file64);
12600
+ return true;
12796
12601
  }
12797
12602
  // Post on form submit. And return the encoded image.
12798
12603
  this.showDataImage(file64);
@@ -12801,6 +12606,7 @@ class Upload extends React.Component {
12801
12606
  };
12802
12607
  render() {
12803
12608
  const {
12609
+ maxSize,
12804
12610
  usDropMessage,
12805
12611
  usAccept,
12806
12612
  usButtonText,
@@ -12814,7 +12620,6 @@ class Upload extends React.Component {
12814
12620
  csButtonText,
12815
12621
  csSuccessText,
12816
12622
  size,
12817
- uploadStep,
12818
12623
  intl
12819
12624
  } = this.props;
12820
12625
  const {
@@ -12828,7 +12633,6 @@ class Upload extends React.Component {
12828
12633
  isSuccess,
12829
12634
  uploadedImage
12830
12635
  } = this.state;
12831
- const UploadStepComponent = UPLOAD_STEP_COMPONENTS[uploadStep] || UploadImageStep;
12832
12636
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
12833
12637
  className: classNames__default.default('droppable-area', {
12834
12638
  droppable: true,
@@ -12842,10 +12646,10 @@ class Upload extends React.Component {
12842
12646
  }),
12843
12647
  onDragEnter: event => this.onDragEnter(event),
12844
12648
  onDragLeave: event => this.onDragLeave(event),
12845
- onDrop: event => this.onDrop(event),
12649
+ onDrop: async event => this.onDrop(event),
12846
12650
  onDragOver: event => event.preventDefault(),
12847
- children: [!isProcessing && !isComplete && /*#__PURE__*/jsxRuntime.jsx(UploadStepComponent, {
12848
- fileDropped: file => this.fileDropped(file),
12651
+ children: [!isProcessing && !isComplete && /*#__PURE__*/jsxRuntime.jsx(UploadImageStep, {
12652
+ fileDropped: async file => this.fileDropped(file),
12849
12653
  isComplete: isComplete,
12850
12654
  usAccept: usAccept,
12851
12655
  usButtonText: usButtonText || intl.formatMessage(messages.usButtonText),
@@ -12853,7 +12657,7 @@ class Upload extends React.Component {
12853
12657
  usHelpImage: usHelpImage,
12854
12658
  usLabel: usLabel,
12855
12659
  usPlaceholder: usPlaceholder || intl.formatMessage(messages.usPlaceholder, {
12856
- maxSize: this.props.maxSize / 1000000
12660
+ maxSize: maxSize / 1000000
12857
12661
  })
12858
12662
  }), isProcessing && /*#__PURE__*/jsxRuntime.jsx(ProcessingStep, {
12859
12663
  isComplete: isComplete,
@@ -12862,7 +12666,7 @@ class Upload extends React.Component {
12862
12666
  psButtonText: psButtonText || intl.formatMessage(messages.psButtonText),
12863
12667
  psProcessingText: psProcessingText || intl.formatMessage(messages.psProcessingText),
12864
12668
  psButtonDisabled: psButtonDisabled,
12865
- onAnimationCompleted: status => this.onAnimationCompleted(status),
12669
+ onAnimationCompleted: async status => this.onAnimationCompleted(status),
12866
12670
  onClear: event => this.handleOnClear(event)
12867
12671
  }), (isSuccess || isError || isComplete) && /*#__PURE__*/jsxRuntime.jsx(CompleteStep, {
12868
12672
  fileName: fileName,
@@ -12870,7 +12674,7 @@ class Upload extends React.Component {
12870
12674
  isError: isError,
12871
12675
  isImage: isImage,
12872
12676
  csButtonText: csButtonText || intl.formatMessage(messages.csButtonText),
12873
- csFailureText: this.getErrorMessage(response?.status),
12677
+ csFailureText: this.getErrorMessage(response != null && typeof response === 'object' && 'status' in response && typeof response.status === 'number' ? response.status : undefined),
12874
12678
  csSuccessText: csSuccessText || intl.formatMessage(messages.csSuccessText),
12875
12679
  uploadedImage: uploadedImage,
12876
12680
  onClear: event => this.handleOnClear(event)
@@ -12894,73 +12698,6 @@ class Upload extends React.Component {
12894
12698
  });
12895
12699
  }
12896
12700
  }
12897
- Upload.propTypes = {
12898
- animationDelay: PropTypes__default.default.number,
12899
- csButtonText: PropTypes__default.default.string,
12900
- csFailureText: PropTypes__default.default.string,
12901
- csSuccessText: PropTypes__default.default.string,
12902
- csTooLargeMessage: PropTypes__default.default.string,
12903
- csWrongTypeMessage: PropTypes__default.default.string,
12904
- httpOptions: PropTypes__default.default.shape({
12905
- url: PropTypes__default.default.string.isRequired,
12906
- method: PropTypes__default.default.oneOf(['POST', 'PUT', 'PATCH']),
12907
- fileInputName: PropTypes__default.default.string,
12908
- data: PropTypes__default.default.object,
12909
- headers: PropTypes__default.default.object
12910
- }),
12911
- /**
12912
- * You can provide a fetcher function with the same interface as the global fetch function, which is used by default.
12913
- * function fetcher(input: RequestInfo, init?: RequestInit): Promise<Response>
12914
- */
12915
- fetcher: PropTypes__default.default.func,
12916
- maxSize: PropTypes__default.default.number,
12917
- onCancel: PropTypes__default.default.func,
12918
- onFailure: PropTypes__default.default.func,
12919
- onStart: PropTypes__default.default.func,
12920
- onSuccess: PropTypes__default.default.func,
12921
- psButtonText: PropTypes__default.default.string,
12922
- psButtonDisabled: PropTypes__default.default.bool,
12923
- psProcessingText: PropTypes__default.default.string,
12924
- size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
12925
- /**
12926
- * You can provide multiple rules separated by comma, e.g.: "application/pdf,image/*".
12927
- * Using "*" will allow every file type to be uploaded.
12928
- */
12929
- usAccept: PropTypes__default.default.string,
12930
- usButtonText: PropTypes__default.default.string,
12931
- usDisabled: PropTypes__default.default.bool,
12932
- usDropMessage: PropTypes__default.default.string,
12933
- usHelpImage: PropTypes__default.default.node,
12934
- usLabel: PropTypes__default.default.string,
12935
- usPlaceholder: PropTypes__default.default.string,
12936
- uploadStep: PropTypes__default.default.oneOf(['uploadImageStep', 'mediaUploadStep'])
12937
- };
12938
- Upload.defaultProps = {
12939
- animationDelay: 700,
12940
- csButtonText: undefined,
12941
- csFailureText: undefined,
12942
- csSuccessText: undefined,
12943
- csTooLargeMessage: undefined,
12944
- csWrongTypeMessage: undefined,
12945
- httpOptions: null,
12946
- maxSize: MAX_SIZE_DEFAULT,
12947
- onCancel: null,
12948
- onFailure: null,
12949
- onStart: null,
12950
- onSuccess: null,
12951
- psButtonText: undefined,
12952
- psButtonDisabled: false,
12953
- psProcessingText: undefined,
12954
- size: 'md',
12955
- usAccept: 'image/*',
12956
- usButtonText: undefined,
12957
- usDisabled: false,
12958
- usDropMessage: undefined,
12959
- usHelpImage: '',
12960
- usLabel: '',
12961
- usPlaceholder: undefined,
12962
- uploadStep: exports.UploadStep.UPLOAD_IMAGE_STEP
12963
- };
12964
12701
  var Upload$1 = reactIntl.injectIntl(Upload);
12965
12702
 
12966
12703
  var MESSAGES$2 = reactIntl.defineMessages({
@@ -13491,7 +13228,7 @@ const UploadInput = ({
13491
13228
  name
13492
13229
  } = file;
13493
13230
  const id = generateFileId(file);
13494
- const allowedFileTypes = Array.isArray(fileTypes) ? fileTypes.join(',') : fileTypes;
13231
+ const allowedFileTypes = typeof fileTypes === 'string' ? fileTypes : fileTypes.join(',');
13495
13232
  // Check if file type is valid
13496
13233
  if (!isTypeValid(file, allowedFileTypes)) {
13497
13234
  handleFileUploadFailure(file, formatMessage(MESSAGES$2.fileTypeNotSupported));
@@ -14675,7 +14412,7 @@ exports.NavigationOption = NavigationOption;
14675
14412
  exports.NavigationOptionsList = NavigationOptionList;
14676
14413
  exports.Nudge = Nudge;
14677
14414
  exports.Option = Option$2;
14678
- exports.OverlayHeader = OverlayHeader$1;
14415
+ exports.OverlayHeader = OverlayHeader;
14679
14416
  exports.PhoneNumberInput = PhoneNumberInput;
14680
14417
  exports.Popover = Popover$1;
14681
14418
  exports.ProcessIndicator = ProcessIndicator;