@tap-payments/auth-jsconnect 2.3.5-test → 2.3.7-test

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.
@@ -193,3 +193,30 @@ export declare const BUSINESS_FLOW_SUCCESS: {
193
193
  status: string;
194
194
  url: string;
195
195
  }[];
196
+ export declare enum FileType {
197
+ IMAGES = "images",
198
+ FILES = "files"
199
+ }
200
+ export declare enum FileStatus {
201
+ INIT = "init",
202
+ UPLOADING = "uploading",
203
+ DOWNLOADING = "downloading",
204
+ SUCCESS = "success",
205
+ ERROR = "error",
206
+ ALREADY_UPLOADED = "already_uploaded"
207
+ }
208
+ export declare enum DeleteFileStatus {
209
+ NONE = "none",
210
+ DELETING = "deleting",
211
+ ERROR = "error",
212
+ SUCCESS = "success"
213
+ }
214
+ export declare type FileInfo = {
215
+ fileId: string;
216
+ docId: string;
217
+ name: string;
218
+ status: FileStatus;
219
+ progress: number;
220
+ error: string;
221
+ deleteStatus: DeleteFileStatus;
222
+ };
@@ -696,3 +696,24 @@ export var PASSWORD_OPERATION_TYPE = {
696
696
  RESET_PASSWORD: 'reset_password'
697
697
  };
698
698
  export var BUSINESS_FLOW_SUCCESS = [{ name: 'business', status: 'completed', url: '' }];
699
+ export var FileType;
700
+ (function (FileType) {
701
+ FileType["IMAGES"] = "images";
702
+ FileType["FILES"] = "files";
703
+ })(FileType || (FileType = {}));
704
+ export var FileStatus;
705
+ (function (FileStatus) {
706
+ FileStatus["INIT"] = "init";
707
+ FileStatus["UPLOADING"] = "uploading";
708
+ FileStatus["DOWNLOADING"] = "downloading";
709
+ FileStatus["SUCCESS"] = "success";
710
+ FileStatus["ERROR"] = "error";
711
+ FileStatus["ALREADY_UPLOADED"] = "already_uploaded";
712
+ })(FileStatus || (FileStatus = {}));
713
+ export var DeleteFileStatus;
714
+ (function (DeleteFileStatus) {
715
+ DeleteFileStatus["NONE"] = "none";
716
+ DeleteFileStatus["DELETING"] = "deleting";
717
+ DeleteFileStatus["ERROR"] = "error";
718
+ DeleteFileStatus["SUCCESS"] = "success";
719
+ })(DeleteFileStatus || (DeleteFileStatus = {}));
@@ -264,7 +264,7 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
264
264
  if (!((params.certificateId || []).length > 0)) return [3, 4];
265
265
  if (!(document === null || document === void 0 ? void 0 : document.id)) return [3, 2];
266
266
  documentBody = {
267
- id: document === null || document === void 0 ? void 0 : document.id,
267
+ id: document.id,
268
268
  images: params.certificateId
269
269
  };
270
270
  return [4, API.documentService.addFilesToExistingDocument(documentBody)];
@@ -7,6 +7,7 @@ import { useController, useFormContext } from 'react-hook-form';
7
7
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
8
8
  import { DocumentPurpose } from '../../../../@types';
9
9
  import { getFileDetailsFromDocument } from '../../../../utils';
10
+ import { FileType } from '../../../../constants';
10
11
  import { bankSelector, bankStatementUploadingStatus } from '../../../app/bank/bankStore';
11
12
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
12
13
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
@@ -31,6 +32,6 @@ var BankStatement = function (_a) {
31
32
  bankStatementIdControl.field.onChange(ids);
32
33
  };
33
34
  var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(document ? [document] : [], DocumentPurpose.BANK_STATEMENT); }, [document]);
34
- return (_jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'bankStatementId', control: control, label: t('title_bank_statement'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleBankStatementChange, isSubmitting: loading, required: required, onDeleteFile: handleReset, purpose: DocumentPurpose.BANK_STATEMENT, defaultFiles: defaultFiles, maxLimit: 4, fileUploadingStatus: function (uploading) { return dispatch(bankStatementUploadingStatus(uploading)); } }) }));
35
+ return (_jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'bankStatementId', control: control, label: t('title_bank_statement'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleBankStatementChange, isSubmitting: loading, required: required, onDeleteFile: handleReset, purpose: DocumentPurpose.BANK_STATEMENT, defaultFiles: defaultFiles, maxLimit: 4, fileUploadingStatus: function (uploading) { return dispatch(bankStatementUploadingStatus(uploading)); }, fileType: FileType.FILES }) }));
35
36
  };
36
37
  export default BankStatement;
@@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next';
14
14
  import { useController, useFormContext } from 'react-hook-form';
15
15
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
16
16
  import { DocumentPurpose } from '../../../../@types';
17
+ import { FileType } from '../../../../constants';
17
18
  import { styled } from '@mui/material/styles';
18
19
  import Collapse from '../../../../components/Collapse';
19
20
  import { ScreenContainer } from '../../../shared/Containers';
@@ -38,6 +39,6 @@ var LicenseCertificate = function (_a) {
38
39
  var handleReset = function (ids) {
39
40
  certificateIdControl.field.onChange(ids);
40
41
  };
41
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'certificateId', control: control, label: t('title_license_certificate'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_certificate'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleLicenseCertificateChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, purpose: DocumentPurpose.CR, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); } }) }) })));
42
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'certificateId', control: control, label: t('title_license_certificate'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_certificate'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleLicenseCertificateChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, purpose: DocumentPurpose.CR, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); }, fileType: FileType.IMAGES }) }) })));
42
43
  };
43
44
  export default LicenseCertificate;
@@ -16,6 +16,7 @@ import { useController, useFormContext } from 'react-hook-form';
16
16
  import { styled } from '@mui/material/styles';
17
17
  import Collapse from '../../../../components/Collapse';
18
18
  import { DocumentPurpose } from '../../../../@types';
19
+ import { FileType } from '../../../../constants';
19
20
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
20
21
  import { getFileDetailsFromDocument } from '../../../../utils';
21
22
  import { ScreenContainer } from '../../../shared/Containers';
@@ -43,6 +44,6 @@ var LicenseCertificate = function (_a) {
43
44
  certificateIdControl.field.onChange(ids);
44
45
  };
45
46
  var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.CR); }, [documents]);
46
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'certificateId', control: control, label: t('title_license_certificate'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_certificate'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleLicenseCertificateChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.CR, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); } }) }) })));
47
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'certificateId', control: control, label: t('title_license_certificate'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_certificate'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleLicenseCertificateChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.CR, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); }, fileType: FileType.IMAGES }) }) })));
47
48
  };
48
49
  export default LicenseCertificate;
@@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
6
6
  import { useController, useFormContext } from 'react-hook-form';
7
7
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
8
8
  import { DocumentPurpose } from '../../../../@types';
9
+ import { FileType } from '../../../../constants';
9
10
  import { getFileDetailsFromDocument } from '../../../../utils';
10
11
  import { civilIDUploadingStatus, individualSelector } from '../../../app/individual/individualStore';
11
12
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
@@ -30,6 +31,6 @@ var CivilIDFile = function () {
30
31
  civilIDFileIdControl.field.onChange(ids);
31
32
  };
32
33
  var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.IDENTITY_DOCUMENT); }, [documents]);
33
- return (_jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'civilID', control: control, label: t('title_civil_id'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_civilID'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_civil_id'), onFileUploaded: handleCivilIDChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.IDENTITY_DOCUMENT, fileUploadingStatus: function (uploading) { return dispatch(civilIDUploadingStatus(uploading)); } }) }));
34
+ return (_jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'civilID', control: control, label: t('title_civil_id'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_civilID'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_civil_id'), onFileUploaded: handleCivilIDChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.IDENTITY_DOCUMENT, fileUploadingStatus: function (uploading) { return dispatch(civilIDUploadingStatus(uploading)); }, fileType: FileType.IMAGES }) }));
34
35
  };
35
36
  export default CivilIDFile;
@@ -16,6 +16,7 @@ import { useController, useFormContext } from 'react-hook-form';
16
16
  import { styled } from '@mui/material/styles';
17
17
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
18
18
  import { DocumentPurpose } from '../../../../@types';
19
+ import { FileType } from '../../../../constants';
19
20
  import { getFileDetailsFromDocument } from '../../../../utils';
20
21
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
21
22
  import { ScreenContainer } from '../../../shared/Containers';
@@ -43,6 +44,6 @@ var SignatureFile = function (_a) {
43
44
  signatureFileIdControl.field.onChange(ids);
44
45
  };
45
46
  var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.CUSTOMER_SIGNATURE); }, [documents]);
46
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'signatureFileId', control: control, label: t('title_signature_file'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_signature'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_signature_file'), onFileUploaded: handleSignatureChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.CUSTOMER_SIGNATURE, fileUploadingStatus: function (uploading) { return dispatch(signatureFileUploadingStatus(uploading)); } }) }) })));
47
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { id: 'signatureFileId', control: control, label: t('title_signature_file'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_signature'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_signature_file'), onFileUploaded: handleSignatureChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.CUSTOMER_SIGNATURE, fileUploadingStatus: function (uploading) { return dispatch(signatureFileUploadingStatus(uploading)); }, fileType: FileType.IMAGES }) }) })));
47
48
  };
48
49
  export default SignatureFile;
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { SxProps, Theme } from '@mui/material/styles';
3
+ import { FileInfo, FileType } from '../../../constants';
3
4
  export declare const InputContainerStyled: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<Theme> & {
4
5
  children?: React.ReactNode;
5
6
  component?: React.ElementType<any> | undefined;
@@ -8,41 +9,19 @@ export declare const InputContainerStyled: import("@emotion/styled").StyledCompo
8
9
  } & import("@mui/material/OverridableComponent").CommonProps & Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
9
10
  ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
10
11
  }, keyof import("@mui/material/OverridableComponent").CommonProps | ("border" | "borderTop" | "borderRight" | "borderBottom" | "borderLeft" | "borderColor" | "borderRadius" | "display" | "displayPrint" | "overflow" | "textOverflow" | "visibility" | "whiteSpace" | "flexBasis" | "flexDirection" | "flexWrap" | "justifyContent" | "alignItems" | "alignContent" | "order" | "flex" | "flexGrow" | "flexShrink" | "alignSelf" | "justifyItems" | "justifySelf" | "gap" | "columnGap" | "rowGap" | "gridColumn" | "gridRow" | "gridAutoFlow" | "gridAutoColumns" | "gridAutoRows" | "gridTemplateColumns" | "gridTemplateRows" | "gridTemplateAreas" | "gridArea" | "bgcolor" | "color" | "zIndex" | "position" | "top" | "right" | "bottom" | "left" | "boxShadow" | "width" | "maxWidth" | "minWidth" | "height" | "maxHeight" | "minHeight" | "boxSizing" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "my" | "p" | "pt" | "pr" | "pb" | "pl" | "px" | "py" | "margin" | "marginTop" | "marginRight" | "marginBottom" | "marginLeft" | "marginX" | "marginY" | "padding" | "paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft" | "paddingX" | "paddingY" | "typography" | "fontFamily" | "fontSize" | "fontStyle" | "fontWeight" | "letterSpacing" | "lineHeight" | "textAlign" | "textTransform") | "ref" | "children" | "component" | "sx"> & import("@mui/system").MUIStyledCommonProps<Theme>, {}, {}>;
11
- export declare enum FileStatus {
12
- INIT = "init",
13
- UPLOADING = "uploading",
14
- DOWNLOADING = "downloading",
15
- SUCCESS = "success",
16
- ERROR = "error",
17
- ALREADY_UPLOADED = "already_uploaded"
18
- }
19
- export declare enum DeleteFileStatus {
20
- NONE = "none",
21
- DELETING = "deleting",
22
- ERROR = "error",
23
- SUCCESS = "success"
24
- }
25
- export declare type FileInfo = {
26
- fileId: string;
27
- docId: string;
28
- name: string;
29
- status: FileStatus;
30
- progress: number;
31
- error: string;
32
- deleteStatus: DeleteFileStatus;
33
- };
34
12
  export declare type UploadFileProps = {
35
13
  index: number;
36
14
  purpose: string;
37
15
  file: File;
16
+ fileType: FileType;
38
17
  required?: boolean;
39
18
  title?: string;
40
19
  uploadedFiles: Array<FileInfo>;
41
20
  onSuccess: (index: number, file: FileInfo) => void;
42
- onFailure: (index: number, file: FileInfo) => void;
43
21
  onDelete: (index: number) => void;
44
- onProgress: (index: number, file: FileInfo) => void;
22
+ onUpdate: (index: number, file: FileInfo, loadingStatus: boolean) => void;
45
23
  sx?: SxProps<Theme> | undefined;
24
+ isSubmitting?: boolean;
46
25
  };
47
- declare const UploadFile: ({ index, title, file, uploadedFiles, onSuccess, onFailure, onDelete, onProgress, sx, purpose, required }: UploadFileProps) => JSX.Element;
26
+ declare const UploadFile: ({ index, title, file, fileType, uploadedFiles, onSuccess, onDelete, onUpdate, sx, purpose, required, isSubmitting }: UploadFileProps) => JSX.Element;
48
27
  export default UploadFile;
@@ -45,7 +45,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
48
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
49
49
  import React from 'react';
50
50
  import { useTranslation } from 'react-i18next';
51
51
  import { alpha, styled, useTheme } from '@mui/material/styles';
@@ -57,9 +57,8 @@ import { CircularProgress } from '../../../components/ProgressBar';
57
57
  import Text from '../../../components/Text';
58
58
  import Icon from '../../../components/Icon';
59
59
  import { maskFileName } from '../../../utils';
60
- import { DocumentPurpose } from '../../../@types';
61
60
  import API from '../../../api';
62
- import { ICONS_NAMES, MAX_FILE_SIZE_FOUR_MB, VALID_FILE_FORMATS } from '../../../constants';
61
+ import { DeleteFileStatus, FileStatus, ICONS_NAMES, MAX_FILE_SIZE_FOUR_MB, VALID_FILE_FORMATS } from '../../../constants';
63
62
  import CheckIcon from '../../shared/CheckIcon';
64
63
  var BoxStyled = styled(Box)(function (_a) {
65
64
  var theme = _a.theme;
@@ -108,29 +107,16 @@ var WarningContainer = styled(Box)(function (_a) {
108
107
  var theme = _a.theme;
109
108
  return (__assign({ background: alpha(theme.palette.warning.main, 0.1), paddingBlock: theme.spacing(1.5), paddingInlineStart: theme.spacing(2.5), flexDirection: 'row', display: 'flex', justifyContent: 'center', color: theme.palette.warning.light, padding: theme.spacing(0.5, 1), borderRadius: '101px', alignItems: 'center', marginTop: theme.spacing(1.25) }, theme.typography.caption));
110
109
  });
111
- export var FileStatus;
112
- (function (FileStatus) {
113
- FileStatus["INIT"] = "init";
114
- FileStatus["UPLOADING"] = "uploading";
115
- FileStatus["DOWNLOADING"] = "downloading";
116
- FileStatus["SUCCESS"] = "success";
117
- FileStatus["ERROR"] = "error";
118
- FileStatus["ALREADY_UPLOADED"] = "already_uploaded";
119
- })(FileStatus || (FileStatus = {}));
120
- export var DeleteFileStatus;
121
- (function (DeleteFileStatus) {
122
- DeleteFileStatus["NONE"] = "none";
123
- DeleteFileStatus["DELETING"] = "deleting";
124
- DeleteFileStatus["ERROR"] = "error";
125
- DeleteFileStatus["SUCCESS"] = "success";
126
- })(DeleteFileStatus || (DeleteFileStatus = {}));
127
110
  var UploadFile = function (_a) {
128
- var index = _a.index, title = _a.title, file = _a.file, uploadedFiles = _a.uploadedFiles, onSuccess = _a.onSuccess, onFailure = _a.onFailure, onDelete = _a.onDelete, onProgress = _a.onProgress, sx = _a.sx, purpose = _a.purpose, required = _a.required;
111
+ var index = _a.index, title = _a.title, file = _a.file, fileType = _a.fileType, uploadedFiles = _a.uploadedFiles, onSuccess = _a.onSuccess, onDelete = _a.onDelete, onUpdate = _a.onUpdate, sx = _a.sx, purpose = _a.purpose, required = _a.required, isSubmitting = _a.isSubmitting;
129
112
  var theme = useTheme();
130
113
  var t = useTranslation().t;
131
114
  var _b = file || {}, name = _b.name, size = _b.size, type = _b.type;
132
115
  var uploadedFile = (uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles[index]) || {};
133
116
  var status = uploadedFile.status, progress = uploadedFile.progress, error = uploadedFile.error, deleteStatus = uploadedFile.deleteStatus;
117
+ var isAnyFileDoingDeleteUploadDownload = React.useMemo(function () {
118
+ return (uploadedFiles || []).find(function (f) { return f.deleteStatus === DeleteFileStatus.DELETING || f.status === FileStatus.UPLOADING || f.status === FileStatus.DOWNLOADING; });
119
+ }, [uploadedFiles]);
134
120
  var uploadFile = function () { return __awaiter(void 0, void 0, void 0, function () {
135
121
  var uploadPayload, onUploadProgress, data, fileId;
136
122
  return __generator(this, function (_a) {
@@ -144,48 +130,59 @@ var UploadFile = function (_a) {
144
130
  };
145
131
  onUploadProgress = function (progressEvent) {
146
132
  var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
147
- uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.UPLOADING });
148
- onProgress(index, uploadedFile);
133
+ uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.UPLOADING, error: '' });
134
+ onUpdate(index, uploadedFile, true);
149
135
  };
150
136
  return [4, API.fileService.uploadFile(uploadPayload, { onUploadProgress: onUploadProgress })];
151
137
  case 1:
152
138
  data = (_a.sent()).data;
153
139
  fileId = (data || {}).id;
154
140
  if (fileId) {
155
- uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS, fileId: fileId });
141
+ uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS, fileId: fileId, error: '' });
156
142
  onSuccess(index, uploadedFile);
157
143
  }
158
144
  else {
159
145
  uploadedFile = __assign(__assign({}, uploadedFile), { progress: 0, status: FileStatus.ERROR, error: 'file_upload_error' });
160
- onFailure(index, uploadedFile);
146
+ onUpdate(index, uploadedFile, false);
161
147
  }
162
148
  return [2];
163
149
  }
164
150
  });
165
151
  }); };
166
- var deleteFile = function () { return __awaiter(void 0, void 0, void 0, function () {
167
- var files, payload, data, docId;
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
152
+ var deleteFile = function (index) { return __awaiter(void 0, void 0, void 0, function () {
153
+ var payload, data, docId, _a;
154
+ var _b;
155
+ return __generator(this, function (_c) {
156
+ switch (_c.label) {
170
157
  case 0:
171
- uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.DELETING });
172
- onProgress(index, uploadedFile);
173
- files = purpose === DocumentPurpose.BANK_STATEMENT ? { files: [uploadedFile.fileId] } : { images: [uploadedFile.fileId] };
174
- payload = __assign({ id: uploadedFile.docId }, files);
158
+ _c.trys.push([0, 2, , 3]);
159
+ uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.DELETING, error: '' });
160
+ onUpdate(index, uploadedFile, true);
161
+ payload = (_b = {
162
+ id: uploadedFile.docId
163
+ },
164
+ _b[fileType] = [uploadedFile.fileId],
165
+ _b);
175
166
  return [4, API.documentService.removeFilesFromDocument(payload)];
176
167
  case 1:
177
- data = (_a.sent()).data;
168
+ data = (_c.sent()).data;
178
169
  docId = (data || {}).id;
179
170
  if (docId) {
180
- uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.SUCCESS, fileId: '' });
181
- onSuccess(index, uploadedFile);
171
+ uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.SUCCESS, fileId: '', error: '', docId: '' });
172
+ onUpdate(index, uploadedFile, false);
182
173
  onDelete(index);
183
174
  }
184
175
  else {
185
176
  uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.ERROR, error: 'file_delete_error' });
186
- onFailure(index, uploadedFile);
177
+ onUpdate(index, uploadedFile, false);
187
178
  }
188
- return [2];
179
+ return [3, 3];
180
+ case 2:
181
+ _a = _c.sent();
182
+ uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.ERROR, error: 'file_delete_error' });
183
+ onUpdate(index, uploadedFile, false);
184
+ return [3, 3];
185
+ case 3: return [2];
189
186
  }
190
187
  });
191
188
  }); };
@@ -196,24 +193,26 @@ var UploadFile = function (_a) {
196
193
  case 0:
197
194
  onDownloadProgress = function (progressEvent) {
198
195
  var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
199
- uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.DOWNLOADING });
200
- onProgress(index, uploadedFile);
196
+ uploadedFile = __assign(__assign({}, uploadedFile), { progress: Math.floor(progress), status: FileStatus.DOWNLOADING, error: '' });
197
+ onUpdate(index, uploadedFile, true);
201
198
  };
202
199
  _b.label = 1;
203
200
  case 1:
204
201
  _b.trys.push([1, 3, , 4]);
202
+ uploadedFile = __assign(__assign({}, uploadedFile), { progress: 0, status: FileStatus.DOWNLOADING, error: '' });
203
+ onUpdate(index, uploadedFile, true);
205
204
  return [4, API.fileService.downloadFile(uploadedFile.fileId, uploadedFile.name, { onDownloadProgress: onDownloadProgress })];
206
205
  case 2:
207
206
  data = (_b.sent()).data;
208
207
  if (data) {
209
- uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS });
208
+ uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS, error: '' });
210
209
  onSuccess(index, uploadedFile);
211
210
  }
212
211
  return [3, 4];
213
212
  case 3:
214
213
  _a = _b.sent();
215
214
  uploadedFile = __assign(__assign({}, uploadedFile), { error: 'file_download_error', status: FileStatus.SUCCESS });
216
- onFailure(index, uploadedFile);
215
+ onUpdate(index, uploadedFile, false);
217
216
  return [3, 4];
218
217
  case 4: return [2];
219
218
  }
@@ -222,38 +221,50 @@ var UploadFile = function (_a) {
222
221
  var handleDeleteFile = function (index) {
223
222
  var canDeleteFile = required ? uploadedFiles.length > 1 : true;
224
223
  if (canDeleteFile && uploadedFile.docId) {
225
- deleteFile();
224
+ deleteFile(index);
226
225
  return;
227
226
  }
228
227
  onDelete(index);
229
228
  };
229
+ var getProgressComponent = function () {
230
+ if (status === FileStatus.ERROR)
231
+ return _jsx(ErrorIconStyled, { src: ICONS_NAMES.ERROR_ICON });
232
+ if (status === FileStatus.SUCCESS)
233
+ return _jsx(CheckIcon, {});
234
+ if (status === FileStatus.DOWNLOADING && !progress)
235
+ return _jsx(MUICircularProgress, { size: 25, thickness: 5 });
236
+ if (progress)
237
+ return (_jsx(CircularProgress, { sx: { backgroundColor: alpha(theme.palette.primary.main, 0.05), borderRadius: '32px' }, textSx: { fontSize: theme.spacing(1.125) }, value: progress, size: 35 }));
238
+ return _jsx(_Fragment, {});
239
+ };
230
240
  React.useEffect(function () {
231
241
  if (!file)
232
242
  return;
233
243
  else if (!VALID_FILE_FORMATS.includes(type)) {
234
244
  uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.ERROR, error: 'file_not_supported_alert' });
235
- onFailure(index, uploadedFile);
245
+ onUpdate(index, uploadedFile, false);
236
246
  }
237
247
  else if (size > MAX_FILE_SIZE_FOUR_MB) {
238
248
  uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.ERROR, error: 'file_size_alert' });
239
- onFailure(index, uploadedFile);
249
+ onUpdate(index, uploadedFile, false);
240
250
  }
241
251
  else if (status === FileStatus.ALREADY_UPLOADED) {
242
252
  uploadedFile = __assign(__assign({}, uploadedFile), { error: 'file_already_exist', progress: 0 });
243
- onFailure(index, uploadedFile);
253
+ onUpdate(index, uploadedFile, false);
244
254
  }
245
255
  else {
246
- if (uploadedFile.status !== FileStatus.UPLOADING && uploadedFile.status !== FileStatus.SUCCESS) {
256
+ if (uploadedFile.status === FileStatus.INIT || uploadedFile.status === FileStatus.ERROR) {
247
257
  uploadFile();
248
258
  }
249
259
  }
250
260
  }, []);
251
261
  var canDownloadFile = uploadedFile.fileId && status !== FileStatus.DOWNLOADING;
252
- return (_jsx(Box, { children: _jsxs(InputContainerStyled, __assign({ sx: __assign({ borderTop: "1px solid ".concat(alpha(theme.palette.divider, 0.8)) }, sx) }, { children: [_jsxs(BoxStyled, { children: [_jsxs(Box, __assign({ sx: {
262
+ var canDeleteFile = !isAnyFileDoingDeleteUploadDownload;
263
+ return (_jsx(Box, __assign({ sx: { pointerEvents: isSubmitting ? 'none' : 'auto' } }, { children: _jsxs(InputContainerStyled, __assign({ sx: __assign({ borderTop: "1px solid ".concat(alpha(theme.palette.divider, 0.8)) }, sx) }, { children: [_jsxs(BoxStyled, { children: [_jsxs(Box, __assign({ sx: {
253
264
  display: 'flex',
254
265
  flexDirection: 'column',
255
266
  padding: theme.spacing(1.5, 0, 1.5),
256
267
  width: '100%'
257
- } }, { children: [_jsxs(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', cursor: canDownloadFile ? 'pointer' : 'auto' }, onClick: canDownloadFile ? function () { return downloadFile(); } : undefined }, { children: [_jsx(Icon, { src: ICONS_NAMES.DOC_ICON }), _jsx(Text, { children: maskFileName(name) })] })), _jsx(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', justifyContent: 'center' } }, { children: _jsx(Collapse, __assign({ in: !!error, timeout: 400 }, { children: _jsxs(WarningContainer, { children: [_jsx(WarningIconStyled, { src: ICONS_NAMES.WARNING_ICON }), _jsx(Text, { children: t(error) })] }) })) }))] })), _jsx(ProgressBoxStyled, { children: status === FileStatus.ERROR ? (_jsx(ErrorIconStyled, { src: ICONS_NAMES.ERROR_ICON })) : status === FileStatus.SUCCESS ? (_jsx(CheckIcon, {})) : progress ? (_jsx(CircularProgress, { sx: { backgroundColor: alpha(theme.palette.primary.main, 0.05), borderRadius: '32px' }, textSx: { fontSize: theme.spacing(1.125) }, value: progress, size: 35 })) : (_jsx(_Fragment, {})) })] }), _jsx(UploadBoxStyled, __assign({ uploading: status === FileStatus.UPLOADING, onClick: status === FileStatus.UPLOADING || deleteStatus === DeleteFileStatus.DELETING ? undefined : function () { return handleDeleteFile(index); } }, { children: deleteStatus === DeleteFileStatus.DELETING ? (_jsx(MUICircularProgress, { size: 25, thickness: 5, sx: { color: theme.palette.common.white } })) : (_jsx(ClearIconStyled, {})) }))] })) }, index));
268
+ } }, { children: [_jsxs(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', cursor: canDownloadFile ? 'pointer' : 'auto' }, onClick: canDownloadFile ? function () { return downloadFile(); } : undefined }, { children: [_jsx(Icon, { src: ICONS_NAMES.DOC_ICON }), _jsx(Text, { children: maskFileName(name) })] })), _jsx(Box, __assign({ sx: { display: 'flex', flexDirection: 'row', justifyContent: 'center' } }, { children: _jsx(Collapse, __assign({ in: !!error, timeout: 400 }, { children: _jsxs(WarningContainer, { children: [_jsx(WarningIconStyled, { src: ICONS_NAMES.WARNING_ICON }), _jsx(Text, { children: t(error) })] }) })) }))] })), _jsx(ProgressBoxStyled, { children: getProgressComponent() })] }), _jsx(UploadBoxStyled, __assign({ uploading: status === FileStatus.UPLOADING || (!!isAnyFileDoingDeleteUploadDownload && deleteStatus !== DeleteFileStatus.DELETING), onClick: canDeleteFile ? function () { return handleDeleteFile(index); } : undefined }, { children: deleteStatus === DeleteFileStatus.DELETING ? (_jsx(MUICircularProgress, { size: 25, thickness: 5, sx: { color: theme.palette.common.white } })) : (_jsx(ClearIconStyled, {})) }))] })) }), index));
258
269
  };
259
270
  export default UploadFile;
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
- import { FileDetails } from '../../../@types';
3
2
  import { Control, FieldValues } from 'react-hook-form';
3
+ import { FileDetails } from '../../../@types';
4
+ import { FileType } from '../../../constants';
4
5
  export declare const InputContainerStyled: import("@emotion/styled").StyledComponent<import("@mui/system").SystemProps<import("@mui/material/styles").Theme> & {
5
6
  children?: React.ReactNode;
6
7
  component?: React.ElementType<any> | undefined;
@@ -14,6 +15,7 @@ interface UploadMultipleFileProps {
14
15
  control: Control<FieldValues, any>;
15
16
  label: string;
16
17
  purpose: string;
18
+ fileType: FileType;
17
19
  fileTitle?: string;
18
20
  required?: boolean;
19
21
  title: string;
@@ -28,5 +30,5 @@ interface UploadMultipleFileProps {
28
30
  maxLimit?: number;
29
31
  defaultFiles?: Array<FileDetails>;
30
32
  }
31
- declare const UploadMultipleFile: ({ id, label, control, required, title, subTitle, dragDescription, uploadingTitle, successTitle, isSubmitting, onFileUploaded, fileUploadingStatus, onDeleteFile, maxLimit, purpose, fileTitle, defaultFiles }: UploadMultipleFileProps) => JSX.Element;
33
+ declare const UploadMultipleFile: ({ id, label, control, required, fileType, title, subTitle, dragDescription, uploadingTitle, successTitle, isSubmitting, onFileUploaded, fileUploadingStatus, onDeleteFile, maxLimit, purpose, fileTitle, defaultFiles }: UploadMultipleFileProps) => JSX.Element;
32
34
  export default UploadMultipleFile;
@@ -21,16 +21,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
21
21
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
22
22
  import React from 'react';
23
23
  import { useTranslation } from 'react-i18next';
24
+ import { useController } from 'react-hook-form';
24
25
  import { alpha, styled, useTheme } from '@mui/material/styles';
25
26
  import Box from '@mui/material/Box';
26
27
  import { DragAndDrop } from '../../../components/FileInput';
27
28
  import Collapse from '../../../components/Collapse';
29
+ import { getFileType } from '../../../utils';
30
+ import { DeleteFileStatus, FileStatus } from '../../../constants';
28
31
  import { InputLabelStyled } from '../../shared/Input/Input';
29
32
  import { ScreenContainer } from '../../shared/Containers';
30
33
  import Mandatory from '../../shared/Mandatory';
31
- import UploadFile, { DeleteFileStatus, FileStatus } from './UploadFile';
32
- import { useController } from 'react-hook-form';
33
- import { getFileType } from '../../../utils';
34
+ import UploadFile from './UploadFile';
34
35
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
35
36
  var theme = _a.theme;
36
37
  return ({
@@ -61,7 +62,7 @@ var UploadCountBox = styled(Box)(function (_a) {
61
62
  });
62
63
  });
63
64
  var UploadMultipleFile = function (_a) {
64
- var id = _a.id, label = _a.label, control = _a.control, required = _a.required, title = _a.title, subTitle = _a.subTitle, dragDescription = _a.dragDescription, uploadingTitle = _a.uploadingTitle, successTitle = _a.successTitle, isSubmitting = _a.isSubmitting, onFileUploaded = _a.onFileUploaded, fileUploadingStatus = _a.fileUploadingStatus, onDeleteFile = _a.onDeleteFile, maxLimit = _a.maxLimit, purpose = _a.purpose, fileTitle = _a.fileTitle, defaultFiles = _a.defaultFiles;
65
+ var id = _a.id, label = _a.label, control = _a.control, required = _a.required, fileType = _a.fileType, title = _a.title, subTitle = _a.subTitle, dragDescription = _a.dragDescription, uploadingTitle = _a.uploadingTitle, successTitle = _a.successTitle, isSubmitting = _a.isSubmitting, onFileUploaded = _a.onFileUploaded, fileUploadingStatus = _a.fileUploadingStatus, onDeleteFile = _a.onDeleteFile, maxLimit = _a.maxLimit, purpose = _a.purpose, fileTitle = _a.fileTitle, defaultFiles = _a.defaultFiles;
65
66
  var t = useTranslation().t;
66
67
  var theme = useTheme();
67
68
  var _b = React.useState(''), error = _b[0], setError = _b[1];
@@ -160,25 +161,18 @@ var UploadMultipleFile = function (_a) {
160
161
  fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(false);
161
162
  }
162
163
  };
163
- var handleFailure = function (index, file) {
164
- if (fileInfoArray.length > 0) {
165
- fileInfoArray[index] = file;
166
- fileInfoControl.field.onChange(__spreadArray([], fileInfoArray, true));
167
- fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(false);
168
- }
169
- };
170
- var handleProgress = function (index, file) {
164
+ var handleUpdate = function (index, file, loadingStatus) {
171
165
  if (fileInfoArray.length > 0) {
172
166
  fileInfoArray[index] = file;
173
167
  fileInfoControl.field.onChange(__spreadArray([], fileInfoArray, true));
174
- fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(true);
168
+ fileUploadingStatus === null || fileUploadingStatus === void 0 ? void 0 : fileUploadingStatus(loadingStatus);
175
169
  }
176
170
  };
177
171
  var fileExists = fileInfoArray.length > 0;
178
172
  return (_jsxs(FeatureStyled, { children: [_jsxs(LabelContainerStyled, { children: [_jsx(InputLabelStyled, { children: _jsxs(_Fragment, { children: [label, required && _jsx(Mandatory, {})] }) }), _jsx(Collapse, __assign({ in: !!uploadedFileCount, timeout: 100, unmountOnExit: true }, { children: _jsx(UploadCountBox, { children: "".concat(uploadedFileCount, " ").concat(t('uploaded_file')) }) }))] }), _jsx(InputContainerStyled, __assign({ sx: { mb: 2.5 } }, { children: _jsx(DragAndDrop, { title: title, subTitle: subTitle, description: dragDescription, fileExists: fileExists, uploadingTitle: uploadingTitle, successTitle: successTitle, onSuccess: handleFileChange, multiple: true, error: error }) })), _jsx(Collapse, __assign({ in: fileExists, timeout: 300 }, { children: (fileArray || []).map(function (file, index) {
179
- return (_jsx(UploadFile, { required: required, purpose: purpose, title: fileTitle, uploadedFiles: fileInfoArray, index: index, file: file, sx: {
173
+ return (_jsx(UploadFile, { required: required, purpose: purpose, fileType: fileType, title: fileTitle, isSubmitting: isSubmitting, uploadedFiles: fileInfoArray, index: index, file: file, sx: {
180
174
  borderBottom: index === fileArray.length - 1 ? "1px solid ".concat(alpha(theme.palette.divider, 0.8)) : ''
181
- }, onSuccess: handleSuccess, onDelete: handleDelete, onFailure: handleFailure, onProgress: handleProgress }, index));
175
+ }, onSuccess: handleSuccess, onDelete: handleDelete, onUpdate: handleUpdate }, index));
182
176
  }) }))] }));
183
177
  };
184
178
  export default UploadMultipleFile;
@@ -18,6 +18,7 @@ import { DocumentPurpose } from '../../../../@types';
18
18
  import { styled } from '@mui/material/styles';
19
19
  import Collapse from '../../../../components/Collapse';
20
20
  import { getFileDetailsFromDocument } from '../../../../utils';
21
+ import { FileType } from '../../../../constants';
21
22
  import { ScreenContainer } from '../../../shared/Containers';
22
23
  import { taxSelector, uploadingStatus } from '../../../app/tax/taxStore';
23
24
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
@@ -43,6 +44,6 @@ var TaxDocument = function (_a) {
43
44
  documentIdControl.field.onChange(ids);
44
45
  };
45
46
  var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.TAX_DOCUMENT); }, [documents]);
46
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, __assign({ sx: { mb: 2.5 } }, { children: _jsx(UploadMultipleFile, { id: 'documentId', control: control, label: t('title_tax_document'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_tax_document'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleTaxDocumentChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.TAX_DOCUMENT, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); } }) })) })));
47
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, __assign({ sx: { mb: 2.5 } }, { children: _jsx(UploadMultipleFile, { id: 'documentId', control: control, label: t('title_tax_document'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('desc_drag_and_drop_tax_document'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleTaxDocumentChange, isSubmitting: loading, onDeleteFile: handleReset, maxLimit: 4, defaultFiles: defaultFiles, purpose: DocumentPurpose.TAX_DOCUMENT, fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); }, fileType: FileType.IMAGES }) })) })));
47
48
  };
48
49
  export default TaxDocument;
@@ -153,10 +153,17 @@ export var getFileDetailsFromDocument = function (documents, purpose) {
153
153
  export var getRecentDocumentBasedOnPurpose = function (documents, purpose) {
154
154
  if ((documents || []).length === 0)
155
155
  return [];
156
- return (documents
157
- .filter(function (doc) { var _a; return ((_a = doc.file_details) === null || _a === void 0 ? void 0 : _a.length) > 0; })
158
- .filter(function (doc) { return doc.file_details.find(function (file) { return file.purpose === purpose; }); })
159
- .sort(function (a, b) { return b.created - a.created; })[0]);
156
+ var filteredByPurpose = documents.filter(function (doc) {
157
+ return doc.file_details && doc.file_details.find(function (file) { return file.purpose === purpose; });
158
+ });
159
+ if ((filteredByPurpose || []).length > 0) {
160
+ return filteredByPurpose.sort(function (a, b) { return b.created - a.created; })[0];
161
+ }
162
+ else {
163
+ return documents
164
+ .filter(function (doc) { var _a; return ((_a = doc.file_details) === null || _a === void 0 ? void 0 : _a.length) === 0 && doc.id; })
165
+ .sort(function (a, b) { return b.created - a.created; })[0];
166
+ }
160
167
  };
161
168
  export var findInArrayOrSubArray = function (items, value) {
162
169
  var found = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.3.5-test",
3
+ "version": "2.3.7-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",