@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.
- package/build/index.js +198 -461
- package/build/index.js.map +1 -1
- package/build/index.mjs +198 -461
- package/build/index.mjs.map +1 -1
- package/build/types/flowNavigation/backButton/BackButton.d.ts +5 -17
- package/build/types/flowNavigation/backButton/BackButton.d.ts.map +1 -1
- package/build/types/flowNavigation/backButton/index.d.ts +2 -2
- package/build/types/flowNavigation/backButton/index.d.ts.map +1 -1
- package/build/types/index.d.ts +3 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/info/Info.d.ts +2 -2
- package/build/types/info/Info.d.ts.map +1 -1
- package/build/types/info/index.d.ts +1 -1
- package/build/types/info/index.d.ts.map +1 -1
- package/build/types/overlayHeader/OverlayHeader.d.ts +9 -18
- package/build/types/overlayHeader/OverlayHeader.d.ts.map +1 -1
- package/build/types/overlayHeader/index.d.ts +2 -1
- package/build/types/overlayHeader/index.d.ts.map +1 -1
- package/build/types/processIndicator/ProcessIndicator.d.ts +1 -1
- package/build/types/processIndicator/ProcessIndicator.d.ts.map +1 -1
- package/build/types/upload/Upload.d.ts +91 -55
- package/build/types/upload/Upload.d.ts.map +1 -1
- package/build/types/upload/Upload.messages.d.ts +42 -60
- package/build/types/upload/Upload.messages.d.ts.map +1 -1
- package/build/types/upload/index.d.ts +2 -2
- package/build/types/upload/index.d.ts.map +1 -1
- package/build/types/upload/steps/completeStep/completeStep.d.ts +11 -18
- package/build/types/upload/steps/completeStep/completeStep.d.ts.map +1 -1
- package/build/types/upload/steps/completeStep/index.d.ts +2 -1
- package/build/types/upload/steps/completeStep/index.d.ts.map +1 -1
- package/build/types/upload/steps/index.d.ts +3 -4
- package/build/types/upload/steps/index.d.ts.map +1 -1
- package/build/types/upload/steps/processingStep/index.d.ts +2 -1
- package/build/types/upload/steps/processingStep/index.d.ts.map +1 -1
- package/build/types/upload/steps/processingStep/processingStep.d.ts +11 -13
- package/build/types/upload/steps/processingStep/processingStep.d.ts.map +1 -1
- package/build/types/upload/steps/uploadImageStep/index.d.ts +2 -1
- package/build/types/upload/steps/uploadImageStep/index.d.ts.map +1 -1
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts +14 -18
- package/build/types/upload/steps/uploadImageStep/uploadImageStep.d.ts.map +1 -1
- package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts +1 -1
- package/build/types/upload/utils/asyncFileRead/asyncFileRead.d.ts.map +1 -1
- package/build/types/upload/utils/asyncFileRead/index.d.ts +1 -1
- package/build/types/upload/utils/asyncFileRead/index.d.ts.map +1 -1
- package/build/types/upload/utils/getFileType/getFileType.d.ts +1 -1
- package/build/types/upload/utils/getFileType/getFileType.d.ts.map +1 -1
- package/build/types/upload/utils/getFileType/index.d.ts +1 -1
- package/build/types/upload/utils/getFileType/index.d.ts.map +1 -1
- package/build/types/upload/utils/index.d.ts +5 -7
- package/build/types/upload/utils/index.d.ts.map +1 -1
- package/build/types/upload/utils/isSizeValid/index.d.ts +1 -1
- package/build/types/upload/utils/isSizeValid/index.d.ts.map +1 -1
- package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts +1 -1
- package/build/types/upload/utils/isSizeValid/isSizeValid.d.ts.map +1 -1
- package/build/types/upload/utils/isTypeValid/index.d.ts +1 -1
- package/build/types/upload/utils/isTypeValid/index.d.ts.map +1 -1
- package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts +1 -1
- package/build/types/upload/utils/isTypeValid/isTypeValid.d.ts.map +1 -1
- package/build/types/upload/utils/postData/index.d.ts +1 -1
- package/build/types/upload/utils/postData/index.d.ts.map +1 -1
- package/build/types/upload/utils/postData/postData.d.ts +11 -1
- package/build/types/upload/utils/postData/postData.d.ts.map +1 -1
- package/package.json +24 -26
- package/src/accordion/Accordion.spec.js +5 -5
- package/src/accordion/AccordionItem/AccordionItem.spec.js +2 -2
- package/src/actionButton/ActionButton.spec.tsx +4 -5
- package/src/alert/Alert.spec.tsx +4 -4
- package/src/alert/Alert.story.tsx +6 -5
- package/src/button/Button.spec.js +4 -5
- package/src/card/Card.spec.tsx +4 -4
- package/src/carousel/Carousel.spec.tsx +17 -17
- package/src/checkbox/Checkbox.spec.tsx +0 -2
- package/src/checkboxButton/CheckboxButton.spec.tsx +0 -2
- package/src/checkboxOption/CheckboxOption.spec.tsx +0 -2
- package/src/chevron/Chevron.spec.tsx +0 -1
- package/src/chips/Chips.spec.tsx +0 -1
- package/src/chips/Chips.story.tsx +5 -3
- package/src/circularButton/CircularButton.spec.tsx +4 -5
- package/src/common/RadioButton/RadioButton.spec.tsx +2 -2
- package/src/common/card/Card.story.tsx +1 -0
- package/src/common/closeButton/CloseButton.spec.tsx +0 -1
- package/src/common/flowHeader/FlowHeader.spec.tsx +0 -1
- package/src/dateInput/DateInput.story.tsx +21 -16
- package/src/dateLookup/DateLookup.rtl.spec.tsx +18 -16
- package/src/dateLookup/DateLookup.testingLibrary.spec.js +47 -44
- package/src/dateLookup/DateLookup.tests.story.tsx +4 -2
- package/src/decision/Decision.spec.js +0 -2
- package/src/dimmer/Dimmer.rtl.spec.js +10 -10
- package/src/drawer/Drawer.rtl.spec.tsx +2 -2
- package/src/emphasis/Emphasis.spec.tsx +0 -1
- package/src/field/Field.spec.tsx +2 -2
- package/src/flowNavigation/FlowNavigation.spec.js +0 -2
- package/src/flowNavigation/animatedLabel/AnimatedLabel.spec.js +0 -1
- package/src/flowNavigation/backButton/BackButton.tsx +29 -0
- package/src/flowNavigation/backButton/index.ts +2 -0
- package/src/header/Header.spec.tsx +6 -6
- package/src/image/Image.spec.tsx +0 -1
- package/src/index.ts +3 -1
- package/src/info/Info.story.tsx +15 -9
- package/src/info/Info.tsx +2 -2
- package/src/info/index.ts +1 -1
- package/src/inlineAlert/InlineAlert.spec.tsx +0 -1
- package/src/inputs/SelectInput.spec.tsx +26 -47
- package/src/link/Link.spec.tsx +0 -1
- package/src/listItem/ListItem.spec.tsx +0 -1
- package/src/moneyInput/MoneyInput.rtl.spec.tsx +2 -2
- package/src/moneyInput/MoneyInput.story.tsx +1 -4
- package/src/overlayHeader/{OverlayHeader.spec.js → OverlayHeader.spec.tsx} +1 -1
- package/src/overlayHeader/{OverlayHeader.story.js → OverlayHeader.story.tsx} +10 -2
- package/src/overlayHeader/{OverlayHeader.js → OverlayHeader.tsx} +12 -19
- package/src/overlayHeader/index.ts +2 -0
- package/src/phoneNumberInput/PhoneNumberInput.story.tsx +1 -0
- package/src/popover/Popover.spec.tsx +10 -10
- package/src/processIndicator/ProcessIndicator.tsx +1 -1
- package/src/progress/Progress.spec.tsx +0 -1
- package/src/progressBar/ProgressBar.spec.tsx +0 -1
- package/src/segmentedControl/SegmentedControl.spec.tsx +10 -11
- package/src/select/Select.spec.js +71 -71
- package/src/test-utils/index.js +1 -1
- package/src/test-utils/jest.setup.js +2 -0
- package/src/tooltip/Tooltip.spec.tsx +15 -16
- package/src/upload/Upload.spec.js +3 -14
- package/src/upload/Upload.story.tsx +37 -0
- package/src/upload/{Upload.js → Upload.tsx} +164 -169
- package/src/upload/index.ts +2 -0
- package/src/upload/steps/completeStep/completeStep.spec.js +3 -2
- package/src/upload/steps/completeStep/completeStep.tsx +74 -0
- package/src/upload/steps/completeStep/index.ts +2 -0
- package/src/upload/steps/{index.js → index.ts} +0 -1
- package/src/upload/steps/processingStep/index.ts +2 -0
- package/src/upload/steps/processingStep/processingStep.tsx +53 -0
- package/src/upload/steps/uploadImageStep/index.ts +2 -0
- package/src/upload/steps/uploadImageStep/{uploadImageStep.js → uploadImageStep.tsx} +17 -23
- package/src/upload/utils/asyncFileRead/asyncFileRead.spec.ts +14 -0
- package/src/upload/utils/asyncFileRead/asyncFileRead.ts +12 -0
- package/src/upload/utils/getFileType/getFileType.spec.ts +22 -0
- package/src/upload/utils/getFileType/getFileType.ts +16 -0
- package/src/upload/utils/{index.js → index.ts} +0 -2
- package/src/upload/utils/isSizeValid/{isSizeValid.spec.js → isSizeValid.spec.ts} +3 -3
- package/src/upload/utils/isSizeValid/isSizeValid.ts +3 -0
- package/src/upload/utils/isTypeValid/isTypeValid.spec.ts +62 -0
- package/src/upload/utils/isTypeValid/isTypeValid.ts +19 -0
- package/src/upload/utils/postData/postData.spec.ts +65 -0
- package/src/upload/utils/postData/postData.ts +36 -0
- package/src/uploadInput/UploadInput.spec.tsx +9 -10
- package/src/uploadInput/UploadInput.story.tsx +8 -180
- package/src/uploadInput/UploadInput.tests.story.tsx +212 -0
- package/src/uploadInput/UploadInput.tsx +1 -1
- package/src/uploadInput/uploadButton/UploadButton.spec.tsx +4 -4
- package/src/uploadInput/uploadItem/UploadItem.spec.tsx +4 -4
- package/build/types/upload/steps/mediaUploadStep/index.d.ts +0 -2
- package/build/types/upload/steps/mediaUploadStep/index.d.ts.map +0 -1
- package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts +0 -24
- package/build/types/upload/steps/mediaUploadStep/mediaUploadStep.d.ts.map +0 -1
- package/build/types/upload/uploadSteps.d.ts +0 -5
- package/build/types/upload/uploadSteps.d.ts.map +0 -1
- package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts +0 -2
- package/build/types/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.d.ts.map +0 -1
- package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts +0 -2
- package/build/types/upload/utils/getSupportedSpotMimeTypes/index.d.ts.map +0 -1
- package/build/types/upload/utils/requestMedia/index.d.ts +0 -2
- package/build/types/upload/utils/requestMedia/index.d.ts.map +0 -1
- package/build/types/upload/utils/requestMedia/requestMedia.d.ts +0 -2
- package/build/types/upload/utils/requestMedia/requestMedia.d.ts.map +0 -1
- package/src/flowNavigation/backButton/BackButton.js +0 -32
- package/src/flowNavigation/backButton/BackButton.spec.js +0 -16
- package/src/flowNavigation/backButton/__snapshots__/BackButton.spec.js.snap +0 -37
- package/src/flowNavigation/backButton/index.js +0 -3
- package/src/overlayHeader/index.js +0 -1
- package/src/upload/Upload.story.js +0 -36
- package/src/upload/index.js +0 -2
- package/src/upload/steps/completeStep/completeStep.js +0 -98
- package/src/upload/steps/completeStep/index.js +0 -1
- package/src/upload/steps/mediaUploadStep/index.js +0 -1
- package/src/upload/steps/mediaUploadStep/mediaUploadStep.js +0 -80
- package/src/upload/steps/mediaUploadStep/mediaUploadStep.spec.js +0 -77
- package/src/upload/steps/processingStep/index.js +0 -1
- package/src/upload/steps/processingStep/processingStep.js +0 -73
- package/src/upload/steps/uploadImageStep/index.js +0 -1
- package/src/upload/uploadSteps.ts +0 -5
- package/src/upload/utils/asyncFileRead/asyncFileRead.js +0 -11
- package/src/upload/utils/asyncFileRead/asyncFileRead.spec.js +0 -17
- package/src/upload/utils/getFileType/getFileType.js +0 -19
- package/src/upload/utils/getFileType/getFileType.spec.js +0 -33
- package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.js +0 -18
- package/src/upload/utils/getSupportedSpotMimeTypes/getSupportedSpotMimeTypes.spec.js +0 -22
- package/src/upload/utils/getSupportedSpotMimeTypes/index.js +0 -1
- package/src/upload/utils/isSizeValid/isSizeValid.js +0 -1
- package/src/upload/utils/isTypeValid/isTypeValid.js +0 -26
- package/src/upload/utils/isTypeValid/isTypeValid.spec.js +0 -68
- package/src/upload/utils/postData/postData.js +0 -18
- package/src/upload/utils/postData/postData.spec.js +0 -109
- package/src/upload/utils/requestMedia/index.js +0 -1
- package/src/upload/utils/requestMedia/requestMedia.js +0 -26
- package/src/upload/utils/requestMedia/requestMedia.spec.js +0 -44
- /package/src/overlayHeader/__snapshots__/{OverlayHeader.spec.js.snap → OverlayHeader.spec.tsx.snap} +0 -0
- /package/src/upload/{Upload.messages.js → Upload.messages.ts} +0 -0
- /package/src/upload/utils/asyncFileRead/{index.js → index.ts} +0 -0
- /package/src/upload/utils/getFileType/{index.js → index.ts} +0 -0
- /package/src/upload/utils/isSizeValid/{index.js → index.ts} +0 -0
- /package/src/upload/utils/isTypeValid/{index.js → index.ts} +0 -0
- /package/src/upload/utils/postData/{index.js → index.ts} +0 -0
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { action } from '@storybook/addon-actions';
|
|
2
|
-
import { boolean, number, select, text } from '@storybook/addon-knobs';
|
|
3
|
-
|
|
4
|
-
import Upload from '.';
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
component: Upload,
|
|
8
|
-
title: 'Forms/Upload',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export const Basic = () => {
|
|
12
|
-
const size = select('size', ['sm', 'md', 'lg'], 'md');
|
|
13
|
-
const maxSize = number('max file size', 4000000);
|
|
14
|
-
const usAccept = text('accepted format', '*');
|
|
15
|
-
const usDisabled = boolean('disabled', false);
|
|
16
|
-
const psButtonDisabled = boolean('psButtonDisabled', false);
|
|
17
|
-
|
|
18
|
-
return (
|
|
19
|
-
<Upload
|
|
20
|
-
maxSize={maxSize}
|
|
21
|
-
size={size}
|
|
22
|
-
usAccept={usAccept}
|
|
23
|
-
usLabel="Front of your ID document"
|
|
24
|
-
usDisabled={usDisabled}
|
|
25
|
-
psButtonDisabled={psButtonDisabled}
|
|
26
|
-
httpOptions={{
|
|
27
|
-
url: 'https://httpbin.org/post',
|
|
28
|
-
method: 'POST',
|
|
29
|
-
}}
|
|
30
|
-
onStart={(file) => action('onStart', file)}
|
|
31
|
-
onSuccess={(httpResponse, fileName) => action('onSuccess', httpResponse, fileName)}
|
|
32
|
-
onFailure={(httpResponse) => action('onFailure', httpResponse)}
|
|
33
|
-
onCancel={() => action('onCancel')}
|
|
34
|
-
/>
|
|
35
|
-
);
|
|
36
|
-
};
|
package/src/upload/index.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { AlertCircle as AlertCircleIcon, Document as DocumentIcon } from '@transferwise/icons';
|
|
2
|
-
import { useTheme } from '@wise/components-theming';
|
|
3
|
-
import classNames from 'classnames';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
|
|
6
|
-
import { Priority, Typography } from '../../..';
|
|
7
|
-
import Body from '../../../body';
|
|
8
|
-
import Button from '../../../button';
|
|
9
|
-
import { Sentiment, Size } from '../../../common';
|
|
10
|
-
import StatusIcon from '../../../statusIcon';
|
|
11
|
-
import Title from '../../../title';
|
|
12
|
-
|
|
13
|
-
const CompleteStep = (props) => {
|
|
14
|
-
const { isModern } = useTheme();
|
|
15
|
-
const {
|
|
16
|
-
csButtonText,
|
|
17
|
-
csFailureText,
|
|
18
|
-
csSuccessText,
|
|
19
|
-
fileName,
|
|
20
|
-
isComplete,
|
|
21
|
-
isError,
|
|
22
|
-
isImage,
|
|
23
|
-
onClear,
|
|
24
|
-
uploadedImage,
|
|
25
|
-
} = props;
|
|
26
|
-
return (
|
|
27
|
-
<div className="droppable-complete-card droppable-card" aria-hidden={!isComplete}>
|
|
28
|
-
<div className="droppable-card-content">
|
|
29
|
-
<div
|
|
30
|
-
className="droppable-card-content d-flex flex-column align-items-center"
|
|
31
|
-
aria-live="polite"
|
|
32
|
-
>
|
|
33
|
-
{isError ? (
|
|
34
|
-
<>
|
|
35
|
-
{isModern ? (
|
|
36
|
-
<StatusIcon size={Size.LARGE} sentiment={Sentiment.NEGATIVE} />
|
|
37
|
-
) : (
|
|
38
|
-
<AlertCircleIcon size={24} className="text-negative" />
|
|
39
|
-
)}
|
|
40
|
-
{csFailureText && (
|
|
41
|
-
<p className={classNames('m-t-2', { 'm-b-0': isModern })}>{csFailureText}</p>
|
|
42
|
-
)}
|
|
43
|
-
</>
|
|
44
|
-
) : (
|
|
45
|
-
<>
|
|
46
|
-
{isImage && uploadedImage ? (
|
|
47
|
-
<img src={uploadedImage} alt="OK" className="thumbnail " />
|
|
48
|
-
) : (
|
|
49
|
-
<DocumentIcon />
|
|
50
|
-
)}
|
|
51
|
-
|
|
52
|
-
{fileName && (
|
|
53
|
-
<Body as="p" className="m-b-0">
|
|
54
|
-
{fileName}
|
|
55
|
-
</Body>
|
|
56
|
-
)}
|
|
57
|
-
{csSuccessText && (
|
|
58
|
-
<Title className="caption m-t-1" type={Typography.TITLE_BODY}>
|
|
59
|
-
{csSuccessText}
|
|
60
|
-
</Title>
|
|
61
|
-
)}
|
|
62
|
-
</>
|
|
63
|
-
)}
|
|
64
|
-
</div>
|
|
65
|
-
{csButtonText && (
|
|
66
|
-
<Button
|
|
67
|
-
priority={isModern ? Priority.PRIMARY : Priority.SECONDARY}
|
|
68
|
-
className={classNames({
|
|
69
|
-
'm-t-1': isModern && !isError,
|
|
70
|
-
'm-t-2': isModern && isError,
|
|
71
|
-
'm-t-3': !isModern,
|
|
72
|
-
})}
|
|
73
|
-
onClick={(event) => onClear(event)}
|
|
74
|
-
>
|
|
75
|
-
{csButtonText}
|
|
76
|
-
</Button>
|
|
77
|
-
)}
|
|
78
|
-
</div>
|
|
79
|
-
</div>
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
CompleteStep.propTypes = {
|
|
84
|
-
csButtonText: PropTypes.string.isRequired,
|
|
85
|
-
csSuccessText: PropTypes.string.isRequired,
|
|
86
|
-
csFailureText: PropTypes.string.isRequired,
|
|
87
|
-
fileName: PropTypes.string.isRequired,
|
|
88
|
-
isComplete: PropTypes.bool.isRequired,
|
|
89
|
-
isError: PropTypes.bool.isRequired,
|
|
90
|
-
isImage: PropTypes.bool.isRequired,
|
|
91
|
-
onClear: PropTypes.func.isRequired,
|
|
92
|
-
uploadedImage: PropTypes.string,
|
|
93
|
-
};
|
|
94
|
-
CompleteStep.defaultProps = {
|
|
95
|
-
uploadedImage: null,
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
export default CompleteStep;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './completeStep';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './mediaUploadStep';
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { Upload as UploadIcon } from '@transferwise/icons';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
|
|
4
|
-
import Body from '../../../body';
|
|
5
|
-
import Button from '../../../button/Button';
|
|
6
|
-
import { Typography } from '../../../common';
|
|
7
|
-
import Title from '../../../title';
|
|
8
|
-
import { getSupportedSpotMimeTypes, requestMedia } from '../../utils';
|
|
9
|
-
|
|
10
|
-
const MediaUploadStep = ({
|
|
11
|
-
isComplete,
|
|
12
|
-
usAccept,
|
|
13
|
-
usButtonText,
|
|
14
|
-
usDisabled,
|
|
15
|
-
usHelpImage,
|
|
16
|
-
usLabel,
|
|
17
|
-
usPlaceholder,
|
|
18
|
-
fileDropped,
|
|
19
|
-
}) => {
|
|
20
|
-
const getMediaFile = () => {
|
|
21
|
-
const allowedMimeTypes = getSupportedSpotMimeTypes(usAccept);
|
|
22
|
-
|
|
23
|
-
if (allowedMimeTypes.length === 0) {
|
|
24
|
-
throw new Error('provided mimeTypes not supported');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const mediaRequest = { allowedMimeTypes };
|
|
28
|
-
requestMedia(mediaRequest).then((file) => fileDropped(file));
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const getImage = () => {
|
|
32
|
-
if (!usHelpImage) {
|
|
33
|
-
return (
|
|
34
|
-
<div className="circle circle-sm circle-inverse p-t-1">
|
|
35
|
-
<UploadIcon size={24} />
|
|
36
|
-
</div>
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (typeof usHelpImage === 'string') {
|
|
41
|
-
return <img src={usHelpImage} alt={usLabel} className="thumbnail text-xs-center" />;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return usHelpImage;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
return (
|
|
48
|
-
<div>
|
|
49
|
-
<div className="droppable-default-card" aria-hidden={isComplete}>
|
|
50
|
-
<div className="droppable-card-content">
|
|
51
|
-
<div className="m-b-3">{getImage()}</div>
|
|
52
|
-
{usLabel && (
|
|
53
|
-
<Title type={Typography.TITLE_BODY} className="m-b-1">
|
|
54
|
-
{usLabel}
|
|
55
|
-
</Title>
|
|
56
|
-
)}
|
|
57
|
-
{usPlaceholder && (
|
|
58
|
-
<Body as="p" type={Typography.BODY_LARGE} className="m-b-3">{`${usPlaceholder}`}</Body>
|
|
59
|
-
)}
|
|
60
|
-
<Button disabled={usDisabled} onClick={getMediaFile}>
|
|
61
|
-
{usButtonText || <UploadIcon size={24} className="m-r-0" />}
|
|
62
|
-
</Button>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
MediaUploadStep.propTypes = {
|
|
70
|
-
fileDropped: PropTypes.func.isRequired,
|
|
71
|
-
isComplete: PropTypes.bool.isRequired,
|
|
72
|
-
usAccept: PropTypes.string.isRequired,
|
|
73
|
-
usButtonText: PropTypes.string.isRequired,
|
|
74
|
-
usDisabled: PropTypes.bool.isRequired,
|
|
75
|
-
usHelpImage: PropTypes.node.isRequired,
|
|
76
|
-
usLabel: PropTypes.string.isRequired,
|
|
77
|
-
usPlaceholder: PropTypes.string.isRequired,
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export default MediaUploadStep;
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { render, fireEvent, screen } from '../../../test-utils';
|
|
2
|
-
|
|
3
|
-
import MediaUploadStep from '.';
|
|
4
|
-
|
|
5
|
-
describe('mediaUploadStep', () => {
|
|
6
|
-
const defaultProps = {
|
|
7
|
-
fileDropped: jest.fn(),
|
|
8
|
-
isComplete: false,
|
|
9
|
-
usAccept: '*',
|
|
10
|
-
usButtonText: '',
|
|
11
|
-
usDisabled: false,
|
|
12
|
-
usLabel: '',
|
|
13
|
-
usHelpImage: '',
|
|
14
|
-
usPlaceholder: '',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const renderMediaUploadStep = (props = {}) =>
|
|
18
|
-
render(<MediaUploadStep {...defaultProps} {...props} />);
|
|
19
|
-
|
|
20
|
-
const originalMicroApps = window.microapps;
|
|
21
|
-
const image64 = {
|
|
22
|
-
bytes:
|
|
23
|
-
'iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAAAA1BMVEX/AAAZ4gk3AAAASElEQVR4nO3BgQAAAADDoPlTX+AIVQEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADwDcaiAAFXD1ujAAAAAElFTkSuQmCC',
|
|
24
|
-
mimeType: 'image/jpeg',
|
|
25
|
-
};
|
|
26
|
-
const requestMedia = jest.fn().mockImplementation(() => Promise.resolve(image64));
|
|
27
|
-
|
|
28
|
-
beforeAll(() => {
|
|
29
|
-
window.microapps = { requestMedia };
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
afterAll(() => {
|
|
33
|
-
window.microapps = originalMicroApps;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('renders help image passed as url string', () => {
|
|
37
|
-
renderMediaUploadStep({
|
|
38
|
-
usHelpImage: 'usHelpImage',
|
|
39
|
-
usLabel: 'usLabel',
|
|
40
|
-
});
|
|
41
|
-
expect(screen.getByAltText('usLabel')).toBeInTheDocument();
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('renders help images passed as image node', () => {
|
|
45
|
-
const usHelpImage = (
|
|
46
|
-
<span role="img" aria-label="rocket">
|
|
47
|
-
🚀
|
|
48
|
-
</span>
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
renderMediaUploadStep({ usHelpImage });
|
|
52
|
-
expect(screen.getByLabelText('rocket')).toBeInTheDocument();
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('renders label', () => {
|
|
56
|
-
renderMediaUploadStep({ usLabel: 'usLabel' });
|
|
57
|
-
expect(screen.getByText('usLabel')).toBeInTheDocument();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('renders placeholder', () => {
|
|
61
|
-
renderMediaUploadStep({ usPlaceholder: 'usPlaceholder' });
|
|
62
|
-
expect(screen.getByText('usPlaceholder')).toBeInTheDocument();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('renders buttonText', () => {
|
|
66
|
-
renderMediaUploadStep({ usButtonText: 'usButtonText' });
|
|
67
|
-
expect(screen.getByText('usButtonText')).toBeInTheDocument();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it(`calls microapps' requestMedia API to get file while upload button is clicked`, () => {
|
|
71
|
-
const allowedMimeTypes = ['image/jpeg', 'video/*', 'application/pdf'];
|
|
72
|
-
renderMediaUploadStep({ usButtonText: 'usButtonText' });
|
|
73
|
-
expect(requestMedia).not.toHaveBeenCalled();
|
|
74
|
-
fireEvent.click(screen.getByText('usButtonText'));
|
|
75
|
-
expect(requestMedia).toHaveBeenCalledWith({ allowedMimeTypes });
|
|
76
|
-
});
|
|
77
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './processingStep';
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { useTheme } from '@wise/components-theming';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
|
|
5
|
-
import Button from '../../../button';
|
|
6
|
-
import { Status, Size, Typography } from '../../../common';
|
|
7
|
-
import ProcessIndicator from '../../../processIndicator';
|
|
8
|
-
import Title from '../../../title';
|
|
9
|
-
|
|
10
|
-
const ProcessingStep = (props) => {
|
|
11
|
-
const {
|
|
12
|
-
isComplete,
|
|
13
|
-
isError,
|
|
14
|
-
isSuccess,
|
|
15
|
-
onAnimationCompleted,
|
|
16
|
-
onClear,
|
|
17
|
-
psButtonText,
|
|
18
|
-
psProcessingText,
|
|
19
|
-
psButtonDisabled,
|
|
20
|
-
} = props;
|
|
21
|
-
|
|
22
|
-
const { isModern } = useTheme();
|
|
23
|
-
|
|
24
|
-
let processStatus = Status.PROCESSING;
|
|
25
|
-
if (isError) {
|
|
26
|
-
processStatus = Status.FAILED;
|
|
27
|
-
}
|
|
28
|
-
if (isSuccess) {
|
|
29
|
-
processStatus = Status.SUCCEEDED;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<div className="droppable-processing-card droppable-card" aria-hidden={isComplete}>
|
|
34
|
-
<div className="droppable-card-content">
|
|
35
|
-
<ProcessIndicator
|
|
36
|
-
size={Size.Small}
|
|
37
|
-
status={processStatus}
|
|
38
|
-
onAnimationCompleted={(status) => onAnimationCompleted(status)}
|
|
39
|
-
/>
|
|
40
|
-
<Title
|
|
41
|
-
className={classNames({
|
|
42
|
-
'm-t-3': !isModern,
|
|
43
|
-
'm-b-3': !isModern,
|
|
44
|
-
'm-t-2': isModern,
|
|
45
|
-
'm-b-2': isModern,
|
|
46
|
-
})}
|
|
47
|
-
type={Typography.TITLE_BODY}
|
|
48
|
-
aria-live="polite"
|
|
49
|
-
>
|
|
50
|
-
{psProcessingText}
|
|
51
|
-
</Title>
|
|
52
|
-
{psButtonText && (
|
|
53
|
-
<Button disabled={psButtonDisabled} onClick={(event) => onClear(event)}>
|
|
54
|
-
{psButtonText}
|
|
55
|
-
</Button>
|
|
56
|
-
)}
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
ProcessingStep.propTypes = {
|
|
63
|
-
isComplete: PropTypes.bool.isRequired,
|
|
64
|
-
isError: PropTypes.bool.isRequired,
|
|
65
|
-
isSuccess: PropTypes.bool.isRequired,
|
|
66
|
-
onAnimationCompleted: PropTypes.func.isRequired,
|
|
67
|
-
onClear: PropTypes.func.isRequired,
|
|
68
|
-
psButtonText: PropTypes.string.isRequired,
|
|
69
|
-
psProcessingText: PropTypes.string.isRequired,
|
|
70
|
-
psButtonDisabled: PropTypes.bool.isRequired,
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export default ProcessingStep;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './uploadImageStep';
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const asyncFileRead = (file) =>
|
|
2
|
-
new Promise((resolve, reject) => {
|
|
3
|
-
const reader = new FileReader();
|
|
4
|
-
reader.readAsDataURL(file);
|
|
5
|
-
reader.addEventListener('load', (event) => {
|
|
6
|
-
resolve(event.target.result);
|
|
7
|
-
});
|
|
8
|
-
reader.addEventListener('error', (event) => {
|
|
9
|
-
reject(event);
|
|
10
|
-
});
|
|
11
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { asyncFileRead } from '.';
|
|
2
|
-
|
|
3
|
-
describe('asyncFileRead', () => {
|
|
4
|
-
it('should resolve with data64', () => {
|
|
5
|
-
const file = new Blob(['foo'], { type: 'text/plain' });
|
|
6
|
-
expect.assertions(1);
|
|
7
|
-
return asyncFileRead(file).then((data) =>
|
|
8
|
-
expect(data).toStrictEqual('data:text/plain;base64,Zm9v'),
|
|
9
|
-
);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('should reject if wrong file is given', () => {
|
|
13
|
-
const file = 'Not a blob';
|
|
14
|
-
expect.assertions(1);
|
|
15
|
-
return asyncFileRead(file).catch((error) => expect(error).toBeTruthy());
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export const getFileType = (file, file64) => {
|
|
2
|
-
if (!file && !file64) {
|
|
3
|
-
return '';
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
if (file && file.type && file.type !== '') {
|
|
7
|
-
return file.type ?? '';
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (file64) {
|
|
11
|
-
const regex = /^data:([a-z]+\/[a-z]+);/;
|
|
12
|
-
const typeFromEncoded = file64.match(regex);
|
|
13
|
-
|
|
14
|
-
if (typeFromEncoded && typeFromEncoded[1]) {
|
|
15
|
-
return typeFromEncoded[1] ?? '';
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return '';
|
|
19
|
-
};
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { getFileType } from '.';
|
|
2
|
-
|
|
3
|
-
const imageFile = {
|
|
4
|
-
type: 'image/png',
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const data64Img = 'data:image/png;something';
|
|
8
|
-
|
|
9
|
-
describe('getFileType', () => {
|
|
10
|
-
describe('returns null', () => {
|
|
11
|
-
it(`when both file and file64 haven't been provided`, () => {
|
|
12
|
-
expect(getFileType('', '')).toBe('');
|
|
13
|
-
});
|
|
14
|
-
it(`when file has no type and file64 hasn't been provided`, () => {
|
|
15
|
-
expect(getFileType({}, '')).toBe('');
|
|
16
|
-
});
|
|
17
|
-
it(`when file has empty type and file64 hasn't been provided`, () => {
|
|
18
|
-
expect(getFileType({ type: '' }, '')).toBe('');
|
|
19
|
-
});
|
|
20
|
-
it(`when file hasn't been provided and file64 is not supported`, () => {
|
|
21
|
-
expect(getFileType('', 'data:something-unexpected')).toBe('');
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
describe('returns file-type', () => {
|
|
26
|
-
it('when file has type defined', () => {
|
|
27
|
-
expect(getFileType(imageFile, '')).toBe(imageFile.type);
|
|
28
|
-
});
|
|
29
|
-
it('when file has no type and file64 is supported', () => {
|
|
30
|
-
expect(getFileType('', data64Img)).toBe('image/png');
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// Spot Platform's Media API only support these MIME types
|
|
2
|
-
const SUPPORTED_MIME_TYPES = ['image/jpeg', 'video/*', 'application/pdf'];
|
|
3
|
-
|
|
4
|
-
export const getSupportedSpotMimeTypes = (mimeTypes) => {
|
|
5
|
-
if (mimeTypes === '*') {
|
|
6
|
-
return SUPPORTED_MIME_TYPES;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const mimeTypesArray = mimeTypes.split(',');
|
|
10
|
-
const mimeMapping = {
|
|
11
|
-
'image/*': 'image/jpeg',
|
|
12
|
-
'application/*': 'application/pdf',
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const mapSupportedMimeTypes = mimeTypesArray.map((type) => mimeMapping[type] || type);
|
|
16
|
-
|
|
17
|
-
return mapSupportedMimeTypes.filter((type) => SUPPORTED_MIME_TYPES.includes(type));
|
|
18
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { getSupportedSpotMimeTypes } from '.';
|
|
2
|
-
|
|
3
|
-
describe(getSupportedSpotMimeTypes, () => {
|
|
4
|
-
it('returns all supported mime types when * is passed', () => {
|
|
5
|
-
expect(getSupportedSpotMimeTypes('*')).toStrictEqual([
|
|
6
|
-
'image/jpeg',
|
|
7
|
-
'video/*',
|
|
8
|
-
'application/pdf',
|
|
9
|
-
]);
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
it('maps image/* and application/* according to the supported', () => {
|
|
13
|
-
expect(getSupportedSpotMimeTypes('image/*,application/*')).toStrictEqual([
|
|
14
|
-
'image/jpeg',
|
|
15
|
-
'application/pdf',
|
|
16
|
-
]);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('filters out unsupported mime types', () => {
|
|
20
|
-
expect(getSupportedSpotMimeTypes('image/jpeg,text/csv')).toStrictEqual(['image/jpeg']);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { getSupportedSpotMimeTypes } from './getSupportedSpotMimeTypes';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isSizeValid = (file, maxSize) => Number.isInteger(maxSize) && file.size <= maxSize;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { getFileType } from '../getFileType';
|
|
2
|
-
|
|
3
|
-
export const isTypeValid = (file, rule, file64) => {
|
|
4
|
-
if (!file || !rule) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const allowedTypes = rule.replace(/\s/g, '').split(',');
|
|
9
|
-
const fileType = getFileType(file, file64);
|
|
10
|
-
|
|
11
|
-
if (rule === '*' || allowedTypes.includes(fileType)) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return allowedTypes.some((type) => {
|
|
16
|
-
const splittedRule = type.split('/');
|
|
17
|
-
const typeAllowed = splittedRule[0];
|
|
18
|
-
const extensionAllowed = splittedRule[1];
|
|
19
|
-
|
|
20
|
-
if (extensionAllowed !== '*') {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return fileType.includes(typeAllowed);
|
|
25
|
-
});
|
|
26
|
-
};
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { isTypeValid } from '.';
|
|
2
|
-
|
|
3
|
-
const pdfFile = {
|
|
4
|
-
type: 'application/pdf',
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
const pngFile = {
|
|
8
|
-
type: 'image/png',
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const data64Img = 'data:image/png;something';
|
|
12
|
-
|
|
13
|
-
describe('isTypeValid', () => {
|
|
14
|
-
describe('when file or rule are not provided', () => {
|
|
15
|
-
it('returns false for matching format', () => {
|
|
16
|
-
expect(isTypeValid('', '*', null)).toBe(false);
|
|
17
|
-
expect(isTypeValid(data64Img, '', null)).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
describe('when type is provided', () => {
|
|
21
|
-
it.each([pdfFile, pngFile])('returns true for wildcard rule %s', (file) => {
|
|
22
|
-
expect(isTypeValid(file, '*', null)).toBe(true);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('returns true for matching type', () => {
|
|
26
|
-
expect(isTypeValid(pdfFile, 'application/*', null)).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('returns true for matching type when multiple rules provided', () => {
|
|
30
|
-
expect(isTypeValid(pdfFile, 'application/*, image/*', null)).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns true for matching subtype', () => {
|
|
34
|
-
expect(isTypeValid(pdfFile, 'application/pdf', null)).toBe(true);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('returns true for matching subtype when multiple rules provided', () => {
|
|
38
|
-
expect(isTypeValid(pngFile, 'application/xls, image/png', null)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('can parse multiple types with extra whitespace', () => {
|
|
42
|
-
expect(isTypeValid(pngFile, ' application/xls, image/png ', null)).toBe(true);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('returns false for unsupported type', () => {
|
|
46
|
-
expect(isTypeValid(pngFile, 'application/*', null)).toBe(false);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it('returns false for unsupported subtype', () => {
|
|
50
|
-
expect(isTypeValid(pdfFile, 'application/xls', null)).toBe(false);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it('returns false for unsupported subtype when multiple rules provided', () => {
|
|
54
|
-
expect(isTypeValid(pngFile, 'application/xls, image/jpeg', null)).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
describe('when type is not provided', () => {
|
|
58
|
-
it('returns true for supported file', () => {
|
|
59
|
-
expect(isTypeValid({ type: '' }, 'image/png', data64Img)).toBe(true);
|
|
60
|
-
expect(isTypeValid({ type: '' }, 'image/*', data64Img)).toBe(true);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('returns false for unsupported file', () => {
|
|
64
|
-
expect(isTypeValid({ type: '' }, 'image/jpeg', data64Img)).toBe(false);
|
|
65
|
-
expect(isTypeValid({ type: '' }, 'application/*', data64Img)).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export const postData = (httpOptions, data = {}, fetcher = fetch) =>
|
|
2
|
-
fetcher(`${httpOptions.url}`, {
|
|
3
|
-
method: 'POST',
|
|
4
|
-
body: data,
|
|
5
|
-
...httpOptions,
|
|
6
|
-
})
|
|
7
|
-
.then((response) => {
|
|
8
|
-
if (!response.ok) {
|
|
9
|
-
const error = new Error(response.statusText);
|
|
10
|
-
error.status = response.status;
|
|
11
|
-
error.response = response;
|
|
12
|
-
throw error;
|
|
13
|
-
}
|
|
14
|
-
return response;
|
|
15
|
-
})
|
|
16
|
-
.catch((error) => {
|
|
17
|
-
throw error;
|
|
18
|
-
});
|