@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
@@ -1,10 +1,7 @@
1
- import { action } from '@storybook/addon-actions';
2
- import { Story, Meta } from '@storybook/react';
3
-
4
- import { Status } from '../common';
1
+ import { StoryFn, Meta } from '@storybook/react';
5
2
 
6
3
  import UploadInput, { UploadInputProps } from './UploadInput';
7
- import { UploadedFile, UploadResponse } from './types';
4
+ import { UploadResponse } from './types';
8
5
 
9
6
  const meta: Meta<typeof UploadInput> = {
10
7
  title: 'Forms/UploadInput',
@@ -13,36 +10,7 @@ const meta: Meta<typeof UploadInput> = {
13
10
  };
14
11
 
15
12
  export default meta;
16
-
17
- const files = [
18
- {
19
- id: 1,
20
- filename: 'purchase-receipt-0.pdf',
21
- url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
22
- },
23
- {
24
- id: 2,
25
- filename: 'purchase-receipt-1.pdf',
26
- url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
27
- },
28
- {
29
- id: 2,
30
- filename: 'receipt failed.png',
31
- status: Status.FAILED,
32
- },
33
- {
34
- id: 3,
35
- filename: 'receipt failed with error string.png',
36
- status: Status.FAILED,
37
- error: 'Something went wrong',
38
- },
39
- {
40
- id: 4,
41
- filename: 'receipt failed with error object.png',
42
- status: Status.FAILED,
43
- error: { message: 'Something went wrong' },
44
- },
45
- ] satisfies UploadedFile[];
13
+ type Story = StoryFn<UploadInputProps>;
46
14
 
47
15
  const createDelayedPromise = async ({
48
16
  successful = true,
@@ -61,158 +29,18 @@ const createDelayedPromise = async ({
61
29
  });
62
30
 
63
31
  const props = {
64
- onUploadFile: async (formData: FormData) => {
32
+ onUploadFile: async () => {
65
33
  return createDelayedPromise();
66
34
  },
67
- onDeleteFile: async (id: string | number) => {
35
+ onDeleteFile: async () => {
68
36
  return createDelayedPromise();
69
37
  },
70
38
  };
71
39
 
72
- const Template: Story<UploadInputProps> = (args: UploadInputProps) => <UploadInput {...args} />;
40
+ const Template: Story = (args: UploadInputProps) => <UploadInput {...args} />;
73
41
 
74
- export const SingleFile: Story<UploadInputProps> = Template.bind({});
42
+ export const SingleFile: Story = Template.bind({});
75
43
  SingleFile.args = { ...props };
76
44
 
77
- export const MultipleFiles: Story<UploadInputProps> = Template.bind({});
45
+ export const MultipleFiles: Story = Template.bind({});
78
46
  MultipleFiles.args = { ...props, multiple: true };
79
-
80
- export const UploadInputWithDescriptionFromProps: Story<UploadInputProps> = Template.bind({});
81
- UploadInputWithDescriptionFromProps.args = {
82
- ...props,
83
- multiple: true,
84
- description: 'Custom file description from prop',
85
- };
86
-
87
- export const Disabled: Story<UploadInputProps> = Template.bind({});
88
- Disabled.args = { ...props, disabled: true };
89
-
90
- export const WithAnyFileType: Story<UploadInputProps> = Template.bind({});
91
- WithAnyFileType.args = { ...props, fileTypes: '*' };
92
-
93
- export const WithSingleFileType: Story<UploadInputProps> = Template.bind({});
94
- WithSingleFileType.args = { ...props, fileTypes: '.zip,application/zip' };
95
-
96
- export const WithMultipleExistingFiles: Story<UploadInputProps> = Template.bind({});
97
- WithMultipleExistingFiles.args = {
98
- ...props,
99
- files,
100
- multiple: true,
101
- };
102
-
103
- export const WithFileErrors: Story<UploadInputProps> = Template.bind({});
104
- WithFileErrors.args = {
105
- ...props,
106
- files: [
107
- {
108
- id: 1,
109
- filename: 'Error with default message.png',
110
- status: Status.FAILED,
111
- },
112
- {
113
- id: 2,
114
- filename: 'Error with `string` error.png',
115
- status: Status.FAILED,
116
- error: 'Single string error',
117
- },
118
- {
119
- id: 3,
120
- filename: 'Error with `obj` error ({ message : `string` }).png',
121
- status: Status.FAILED,
122
- error: { message: 'Single obj error' },
123
- },
124
- {
125
- id: 4,
126
- filename: 'Error with single error passed in `array`.png',
127
- status: Status.FAILED,
128
- errors: ['Single error in array'],
129
- },
130
- {
131
- id: 5,
132
- filename: 'Error with multiple `string` errors passed in `array`.png',
133
- status: Status.FAILED,
134
- errors: ['Error 1', 'Error 2', 'Error 3'],
135
- },
136
- {
137
- id: 6,
138
- filename: 'Error with multiple `obj` errors passed in `array`.png',
139
- status: Status.FAILED,
140
- errors: [{ message: 'Error 1' }, { message: 'Error 2' }, { message: 'Error 3' }],
141
- },
142
- ],
143
- multiple: true,
144
- };
145
-
146
- export const WithoutDelete: Story<UploadInputProps> = Template.bind({});
147
- WithoutDelete.args = {
148
- ...props,
149
- files,
150
- onDeleteFile: undefined,
151
- multiple: true,
152
- };
153
-
154
- export const WithUploadFailed: Story<UploadInputProps> = Template.bind({});
155
- WithUploadFailed.args = {
156
- ...props,
157
- files: files.slice(0),
158
- onUploadFile: async () => createDelayedPromise({ successful: false }),
159
- multiple: true,
160
- };
161
-
162
- export const WithDeleteFailed: Story<UploadInputProps> = Template.bind({});
163
- WithDeleteFailed.args = {
164
- ...props,
165
- files: files.slice(0),
166
- onDeleteFile: async () => createDelayedPromise({ successful: false }),
167
- multiple: true,
168
- };
169
-
170
- export const CustomConfirmMessage: Story<UploadInputProps> = Template.bind({});
171
- CustomConfirmMessage.args = {
172
- ...props,
173
- files: files.slice(0),
174
- deleteConfirm: {
175
- title: 'Sure you want to remove this invoice?',
176
- body: (
177
- <img
178
- alt="brand logo"
179
- src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
180
- />
181
- ),
182
- },
183
- };
184
-
185
- export const withManualDownloadHandler: Story<UploadInputProps> = Template.bind({});
186
- withManualDownloadHandler.args = {
187
- ...props,
188
- files,
189
- onDownload: action('Manual download handler'),
190
- };
191
-
192
- export const withFilesChangeHandler: Story<UploadInputProps> = Template.bind({});
193
- withFilesChangeHandler.args = {
194
- ...props,
195
- files,
196
- onFilesChange: action('Files change handler'),
197
- };
198
-
199
- export const withMaxFilesToUploadLimit: Story<UploadInputProps> = Template.bind({});
200
- withMaxFilesToUploadLimit.args = {
201
- ...props,
202
- multiple: true,
203
- maxFiles: 5,
204
- maxFilesErrorMessage: "Can't upload as maximum number of files allowed are already uploaded",
205
- };
206
-
207
- export const withFileSizeErrorMessage: Story<UploadInputProps> = Template.bind({});
208
- withFileSizeErrorMessage.args = {
209
- ...props,
210
- sizeLimit: 1,
211
- sizeLimitErrorMessage: 'The file is oversized',
212
- };
213
-
214
- export const withCustomUploadButtonTitle: Story<UploadInputProps> = Template.bind({});
215
- withCustomUploadButtonTitle.args = {
216
- ...props,
217
- uploadButtonTitle: 'Upload the VAT receipts for FY 2022-23',
218
- };
@@ -0,0 +1,212 @@
1
+ import { action } from '@storybook/addon-actions';
2
+ import { StoryFn, Meta } from '@storybook/react';
3
+
4
+ import { Status } from '../common';
5
+
6
+ import UploadInput, { UploadInputProps } from './UploadInput';
7
+ import { UploadedFile, UploadResponse } from './types';
8
+
9
+ const meta: Meta<typeof UploadInput> = {
10
+ title: 'Forms/UploadInput/Tests',
11
+ component: UploadInput,
12
+ };
13
+
14
+ export default meta;
15
+ type Story = StoryFn<UploadInputProps>;
16
+
17
+ const files = [
18
+ {
19
+ id: 1,
20
+ filename: 'purchase-receipt-0.pdf',
21
+ url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
22
+ },
23
+ {
24
+ id: 2,
25
+ filename: 'purchase-receipt-1.pdf',
26
+ url: 'https://wise.com/public-resources/assets/logos/wise/brand_logo_inverse.svg',
27
+ },
28
+ {
29
+ id: 2,
30
+ filename: 'receipt failed.png',
31
+ status: Status.FAILED,
32
+ },
33
+ {
34
+ id: 3,
35
+ filename: 'receipt failed With error string.png',
36
+ status: Status.FAILED,
37
+ error: 'Something went wrong',
38
+ },
39
+ {
40
+ id: 4,
41
+ filename: 'receipt failed With error object.png',
42
+ status: Status.FAILED,
43
+ error: { message: 'Something went wrong' },
44
+ },
45
+ ] satisfies UploadedFile[];
46
+
47
+ const createDelayedPromise = async ({
48
+ successful = true,
49
+ delaySeconds = 3,
50
+ response = { id: Math.round(Math.random() * 10000), url: '#' },
51
+ }: {
52
+ successful?: boolean;
53
+ delaySeconds?: number;
54
+ response?: UploadResponse;
55
+ } = {}): Promise<UploadResponse> =>
56
+ new Promise((resolve, reject) => {
57
+ setTimeout(
58
+ () => (successful ? resolve(response) : reject(new Error('Unexpected error'))),
59
+ delaySeconds * 1000,
60
+ );
61
+ });
62
+
63
+ const props = {
64
+ onUploadFile: async (formData: FormData) => {
65
+ return createDelayedPromise();
66
+ },
67
+ onDeleteFile: async (id: string | number) => {
68
+ return createDelayedPromise();
69
+ },
70
+ };
71
+
72
+ const Template: Story = (args: UploadInputProps) => <UploadInput {...args} />;
73
+
74
+ export const UploadInputWithDescriptionFromProps: Story = Template.bind({});
75
+ UploadInputWithDescriptionFromProps.args = {
76
+ ...props,
77
+ multiple: true,
78
+ description: 'Custom file description from prop',
79
+ };
80
+
81
+ export const Disabled: Story = Template.bind({});
82
+ Disabled.args = { ...props, disabled: true };
83
+
84
+ export const WithAnyFileType: Story = Template.bind({});
85
+ WithAnyFileType.args = { ...props, fileTypes: '*' };
86
+
87
+ export const WithSingleFileType: Story = Template.bind({});
88
+ WithSingleFileType.args = { ...props, fileTypes: '.zip,application/zip' };
89
+
90
+ export const WithMultipleExistingFiles: Story = Template.bind({});
91
+ WithMultipleExistingFiles.args = {
92
+ ...props,
93
+ files,
94
+ multiple: true,
95
+ };
96
+
97
+ export const WithFileErrors: Story = Template.bind({});
98
+ WithFileErrors.args = {
99
+ ...props,
100
+ files: [
101
+ {
102
+ id: 1,
103
+ filename: 'Error with default message.png',
104
+ status: Status.FAILED,
105
+ },
106
+ {
107
+ id: 2,
108
+ filename: 'Error with `string` error.png',
109
+ status: Status.FAILED,
110
+ error: 'Single string error',
111
+ },
112
+ {
113
+ id: 3,
114
+ filename: 'Error with `obj` error ({ message : `string` }).png',
115
+ status: Status.FAILED,
116
+ error: { message: 'Single obj error' },
117
+ },
118
+ {
119
+ id: 4,
120
+ filename: 'Error with single error passed in `array`.png',
121
+ status: Status.FAILED,
122
+ errors: ['Single error in array'],
123
+ },
124
+ {
125
+ id: 5,
126
+ filename: 'Error with multiple `string` errors passed in `array`.png',
127
+ status: Status.FAILED,
128
+ errors: ['Error 1', 'Error 2', 'Error 3'],
129
+ },
130
+ {
131
+ id: 6,
132
+ filename: 'Error with multiple `obj` errors passed in `array`.png',
133
+ status: Status.FAILED,
134
+ errors: [{ message: 'Error 1' }, { message: 'Error 2' }, { message: 'Error 3' }],
135
+ },
136
+ ],
137
+ multiple: true,
138
+ };
139
+
140
+ export const WithoutDelete: Story = Template.bind({});
141
+ WithoutDelete.args = {
142
+ ...props,
143
+ files,
144
+ onDeleteFile: undefined,
145
+ multiple: true,
146
+ };
147
+
148
+ export const WithUploadFailed: Story = Template.bind({});
149
+ WithUploadFailed.args = {
150
+ ...props,
151
+ files: files.slice(0),
152
+ onUploadFile: async () => createDelayedPromise({ successful: false }),
153
+ multiple: true,
154
+ };
155
+
156
+ export const WithDeleteFailed: Story = Template.bind({});
157
+ WithDeleteFailed.args = {
158
+ ...props,
159
+ files: files.slice(0),
160
+ onDeleteFile: async () => createDelayedPromise({ successful: false }),
161
+ multiple: true,
162
+ };
163
+
164
+ export const CustomConfirmMessage: Story = Template.bind({});
165
+ CustomConfirmMessage.args = {
166
+ ...props,
167
+ files: files.slice(0),
168
+ deleteConfirm: {
169
+ title: 'Sure you want to remove this invoice?',
170
+ body: (
171
+ <img
172
+ alt="brand logo"
173
+ src="https://wise.com/public-resources/assets/logos/wise/brand_logo.svg"
174
+ />
175
+ ),
176
+ },
177
+ };
178
+
179
+ export const WithManualDownloadHandler: Story = Template.bind({});
180
+ WithManualDownloadHandler.args = {
181
+ ...props,
182
+ files,
183
+ onDownload: action('Manual download handler'),
184
+ };
185
+
186
+ export const WithFilesChangeHandler: Story = Template.bind({});
187
+ WithFilesChangeHandler.args = {
188
+ ...props,
189
+ files,
190
+ onFilesChange: action('Files change handler'),
191
+ };
192
+
193
+ export const WithMaxFilesToUploadLimit: Story = Template.bind({});
194
+ WithMaxFilesToUploadLimit.args = {
195
+ ...props,
196
+ multiple: true,
197
+ maxFiles: 5,
198
+ maxFilesErrorMessage: "Can't upload as maximum number of files allowed are already uploaded",
199
+ };
200
+
201
+ export const WithFileSizeErrorMessage: Story = Template.bind({});
202
+ WithFileSizeErrorMessage.args = {
203
+ ...props,
204
+ sizeLimit: 1,
205
+ sizeLimitErrorMessage: 'The file is oversized',
206
+ };
207
+
208
+ export const WithCustomUploadButtonTitle: Story = Template.bind({});
209
+ WithCustomUploadButtonTitle.args = {
210
+ ...props,
211
+ uploadButtonTitle: 'Upload the VAT receipts for FY 2022-23',
212
+ };
@@ -236,7 +236,7 @@ const UploadInput = ({
236
236
  const { name } = file;
237
237
  const id = generateFileId(file);
238
238
 
239
- const allowedFileTypes = Array.isArray(fileTypes) ? fileTypes.join(',') : fileTypes;
239
+ const allowedFileTypes = typeof fileTypes === 'string' ? fileTypes : fileTypes.join(',');
240
240
 
241
241
  // Check if file type is valid
242
242
  if (!isTypeValid(file, allowedFileTypes)) {
@@ -35,9 +35,9 @@ describe('UploadButton', () => {
35
35
  );
36
36
  });
37
37
 
38
- it('trigger onChange callback with a FileList', () => {
38
+ it('trigger onChange callback with a FileList', async () => {
39
39
  const input = screen.getByTestId(TEST_IDS.uploadInput);
40
- userEvent.upload(input, [pngFile, jpgFile]);
40
+ await userEvent.upload(input, [pngFile, jpgFile]);
41
41
 
42
42
  expect(props.onChange).toHaveBeenCalledTimes(1);
43
43
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -55,9 +55,9 @@ describe('UploadButton', () => {
55
55
  expect(screen.getByTestId(TEST_IDS.uploadInput)).toHaveAttribute('multiple');
56
56
  });
57
57
 
58
- it('trigger onChange callback with a FileList', () => {
58
+ it('trigger onChange callback with a FileList', async () => {
59
59
  const input = screen.getByTestId(TEST_IDS.uploadInput);
60
- userEvent.upload(input, [pngFile, jpgFile]);
60
+ await userEvent.upload(input, [pngFile, jpgFile]);
61
61
 
62
62
  expect(props.onChange).toHaveBeenCalledTimes(1);
63
63
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -1,9 +1,9 @@
1
- import userEvent from '@testing-library/user-event';
1
+ import { userEvent } from '@testing-library/user-event';
2
2
 
3
3
  import { Status } from '../../common';
4
4
  import { render, screen } from '../../test-utils';
5
5
 
6
- import UploadItem, { UploadItemProps, TEST_IDS } from './UploadItem';
6
+ import UploadItem, { UploadItemProps } from './UploadItem';
7
7
 
8
8
  describe('UploadItem', () => {
9
9
  const props: UploadItemProps = {
@@ -111,10 +111,10 @@ describe('UploadItem', () => {
111
111
  });
112
112
 
113
113
  describe('manual file download handler', () => {
114
- it('calls onDownload handler provided through props', () => {
114
+ it('calls onDownload handler provided through props', async () => {
115
115
  const onDownload = jest.fn();
116
116
  renderComponent({ ...props, onDownload });
117
- userEvent.click(screen.getAllByRole('link')[0]);
117
+ await userEvent.click(screen.getAllByRole('link')[0]);
118
118
  expect(onDownload).toHaveBeenCalledTimes(1);
119
119
  expect(onDownload).toHaveBeenCalledWith(props.file);
120
120
  });
@@ -1,2 +0,0 @@
1
- export { default } from "./mediaUploadStep";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/mediaUploadStep/index.js"],"names":[],"mappings":""}
@@ -1,24 +0,0 @@
1
- export default MediaUploadStep;
2
- declare function MediaUploadStep({ isComplete, usAccept, usButtonText, usDisabled, usHelpImage, usLabel, usPlaceholder, fileDropped, }: {
3
- isComplete: any;
4
- usAccept: any;
5
- usButtonText: any;
6
- usDisabled: any;
7
- usHelpImage: any;
8
- usLabel: any;
9
- usPlaceholder: any;
10
- fileDropped: any;
11
- }): import("react").JSX.Element;
12
- declare namespace MediaUploadStep {
13
- namespace propTypes {
14
- let fileDropped: any;
15
- let isComplete: any;
16
- let usAccept: any;
17
- let usButtonText: any;
18
- let usDisabled: any;
19
- let usHelpImage: any;
20
- let usLabel: any;
21
- let usPlaceholder: any;
22
- }
23
- }
24
- //# sourceMappingURL=mediaUploadStep.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mediaUploadStep.d.ts","sourceRoot":"","sources":["../../../../../src/upload/steps/mediaUploadStep/mediaUploadStep.js"],"names":[],"mappings":";AASA;;;;;;;;;gCAyDC"}
@@ -1,5 +0,0 @@
1
- export declare enum UploadStep {
2
- UPLOAD_IMAGE_STEP = "uploadImageStep",
3
- MEDIA_UPLOAD_STEP = "mediaUploadStep"
4
- }
5
- //# sourceMappingURL=uploadSteps.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"uploadSteps.d.ts","sourceRoot":"","sources":["../../../src/upload/uploadSteps.ts"],"names":[],"mappings":"AACA,oBAAY,UAAU;IACpB,iBAAiB,oBAAoB;IACrC,iBAAiB,oBAAoB;CACtC"}
@@ -1,2 +0,0 @@
1
- export function getSupportedSpotMimeTypes(mimeTypes: any): any;
2
- //# sourceMappingURL=getSupportedSpotMimeTypes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getSupportedSpotMimeTypes.d.ts","sourceRoot":"","sources":["../../../../../src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js"],"names":[],"mappings":"AAGO,+DAcN"}
@@ -1,2 +0,0 @@
1
- export { getSupportedSpotMimeTypes } from "./getSupportedSpotMimeTypes";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/upload/utils/getSupportedSpotMimeTypes/index.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export { requestMedia } from "./requestMedia";
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/upload/utils/requestMedia/index.js"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export function requestMedia(mediaRequest: any): Promise<any>;
2
- //# sourceMappingURL=requestMedia.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"requestMedia.d.ts","sourceRoot":"","sources":["../../../../../src/upload/utils/requestMedia/requestMedia.js"],"names":[],"mappings":"AAAO,8DAcH"}
@@ -1,32 +0,0 @@
1
- import { ArrowLeft as ArrowLeftIcon } from '@transferwise/icons';
2
- import classNames from 'classnames';
3
- import PropTypes from 'prop-types';
4
-
5
- import Avatar, { AvatarType } from '../../avatar';
6
-
7
- const BackButton = ({ className, onClick, 'aria-label': ariaLabel }) => (
8
- <Avatar type={AvatarType.ICON} size={40}>
9
- <button
10
- type="button"
11
- aria-label={ariaLabel}
12
- className={classNames('np-back-button', 'btn-unstyled', className)}
13
- onClick={onClick}
14
- >
15
- <ArrowLeftIcon size={24} />
16
- </button>
17
- </Avatar>
18
- );
19
-
20
- BackButton.propTypes = {
21
- 'aria-label': PropTypes.string.isRequired,
22
- className: PropTypes.string,
23
- label: PropTypes.element,
24
- onClick: PropTypes.func,
25
- };
26
-
27
- BackButton.defaultProps = {
28
- className: undefined,
29
- label: undefined,
30
- };
31
-
32
- export default BackButton;
@@ -1,16 +0,0 @@
1
- import { render } from '../../test-utils';
2
- import messages from '../FlowNavigation.messages';
3
-
4
- import BackButton from '.';
5
-
6
- const props = {
7
- label: <>label</>,
8
- className: 'className',
9
- onClick: jest.fn(),
10
- 'aria-label': messages.back.defaultMessage,
11
- };
12
- describe('BackButton', () => {
13
- it(`renders as expected`, () => {
14
- expect(render(<BackButton {...props} />).container).toMatchSnapshot();
15
- });
16
- });
@@ -1,37 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`BackButton renders as expected 1`] = `
4
- <div>
5
- <div
6
- class="tw-avatar tw-avatar--40 tw-avatar--icon"
7
- >
8
- <div
9
- class="tw-avatar__content"
10
- >
11
- <button
12
- class="np-back-button btn-unstyled className"
13
- type="button"
14
- >
15
- <span
16
- aria-hidden="true"
17
- class="tw-icon tw-icon-arrow-left "
18
- data-testid="arrow-left-icon"
19
- role="presentation"
20
- >
21
- <svg
22
- fill="currentColor"
23
- focusable="false"
24
- height="24"
25
- viewBox="0 0 24 24"
26
- width="24"
27
- >
28
- <path
29
- d="M22.286 11.316H4.629l7.114-7.114-1.2-1.2-8.572 8.571a.829.829 0 0 0 0 1.2l8.572 8.572 1.2-1.2-7.114-7.114h17.657v-1.715Z"
30
- />
31
- </svg>
32
- </span>
33
- </button>
34
- </div>
35
- </div>
36
- </div>
37
- `;
@@ -1,3 +0,0 @@
1
- import BackButton from './BackButton';
2
-
3
- export default BackButton;
@@ -1 +0,0 @@
1
- export { default } from './OverlayHeader';