@tap-payments/auth-jsconnect 2.3.2-test → 2.3.4-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.
Files changed (30) hide show
  1. package/build/@types/app.d.ts +1 -0
  2. package/build/api/document.d.ts +25 -0
  3. package/build/api/document.js +38 -0
  4. package/build/api/entity.d.ts +0 -15
  5. package/build/api/entity.js +0 -8
  6. package/build/api/file.d.ts +1 -0
  7. package/build/api/file.js +13 -1
  8. package/build/api/index.d.ts +9 -3
  9. package/build/api/index.js +3 -1
  10. package/build/api/individual.d.ts +1 -1
  11. package/build/assets/locales/ar.json +3 -1
  12. package/build/assets/locales/en.json +3 -1
  13. package/build/features/app/bank/bankStore.d.ts +1 -1
  14. package/build/features/app/bank/bankStore.js +23 -9
  15. package/build/features/app/brand/brandStore.js +25 -12
  16. package/build/features/app/business/businessStore.js +1 -1
  17. package/build/features/app/entity/entityStore.js +39 -26
  18. package/build/features/app/individual/individualStore.js +1 -1
  19. package/build/features/app/tax/taxStore.js +28 -15
  20. package/build/features/bank/screens/BankDetails/BankStatement.js +2 -2
  21. package/build/features/entity/screens/EntityName/LicenseCertificate.js +2 -2
  22. package/build/features/individual/screens/AdditionalIndividualInfo/CivilIDFile.js +2 -2
  23. package/build/features/individual/screens/AdditionalIndividualInfo/SignatureFile.js +2 -2
  24. package/build/features/shared/UploadMultipleFile/UploadFile.d.ts +11 -1
  25. package/build/features/shared/UploadMultipleFile/UploadFile.js +77 -4
  26. package/build/features/shared/UploadMultipleFile/UploadMultipleFile.js +19 -6
  27. package/build/features/tax/screens/TaxDetails/TaxDocument.js +2 -2
  28. package/build/utils/array.d.ts +2 -1
  29. package/build/utils/array.js +14 -6
  30. package/package.json +1 -1
@@ -341,5 +341,6 @@ export type FileDetails = {
341
341
  size: string;
342
342
  title: string;
343
343
  type: string;
344
+ docId?: string;
344
345
  };
345
346
  export {};
@@ -0,0 +1,25 @@
1
+ export type DocumentInfo = {
2
+ type?: string;
3
+ number?: string;
4
+ issuing_country?: string;
5
+ issuing_date?: string;
6
+ expiry_date?: string;
7
+ images: Array<string>;
8
+ };
9
+ export type DocumentUpdateBody = {
10
+ entity_id?: boolean;
11
+ individual_type_id?: number;
12
+ country?: string;
13
+ documents: Array<DocumentInfo>;
14
+ };
15
+ export interface DocumentBody {
16
+ id: string;
17
+ images?: Array<string>;
18
+ files?: Array<string>;
19
+ }
20
+ declare const documentService: {
21
+ updateDocumentInfo: (data: DocumentUpdateBody) => Promise<any>;
22
+ addFilesToExistingDocument: ({ id, ...data }: DocumentBody) => Promise<any>;
23
+ removeFilesFromDocument: ({ id, ...data }: DocumentBody) => Promise<import("axios").AxiosResponse<any, any>>;
24
+ };
25
+ export { documentService };
@@ -0,0 +1,38 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { ENDPOINT_PATHS } from '../constants';
13
+ import instance, { httpClient } from './axios';
14
+ var updateDocumentInfo = function (data) {
15
+ return httpClient({
16
+ method: 'post',
17
+ url: "".concat(ENDPOINT_PATHS.DOCUMENT),
18
+ data: data
19
+ });
20
+ };
21
+ var addFilesToExistingDocument = function (_a) {
22
+ var id = _a.id, data = __rest(_a, ["id"]);
23
+ return httpClient({
24
+ method: 'put',
25
+ url: "".concat(ENDPOINT_PATHS.DOCUMENT, "/").concat(id, "/files/add"),
26
+ data: data
27
+ });
28
+ };
29
+ var removeFilesFromDocument = function (_a) {
30
+ var id = _a.id, data = __rest(_a, ["id"]);
31
+ return instance.put("".concat(ENDPOINT_PATHS.DOCUMENT, "/").concat(id, "/files/remove"), data);
32
+ };
33
+ var documentService = {
34
+ updateDocumentInfo: updateDocumentInfo,
35
+ addFilesToExistingDocument: addFilesToExistingDocument,
36
+ removeFilesFromDocument: removeFilesFromDocument
37
+ };
38
+ export { documentService };
@@ -102,20 +102,6 @@ export type UpdateEntityCapitalBody = {
102
102
  };
103
103
  };
104
104
  };
105
- export type DocumentInfo = {
106
- type?: string;
107
- number?: string;
108
- issuing_country?: string;
109
- issuing_date?: string;
110
- expiry_date?: string;
111
- images: Array<string>;
112
- };
113
- export type DocumentUpdateBody = {
114
- entity_id?: boolean;
115
- individual_type_id?: number;
116
- country?: string;
117
- documents: Array<DocumentInfo>;
118
- };
119
105
  declare const entityService: {
120
106
  createEntityInfo: ({ id, ...data }: EntityInfoBody, config?: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
121
107
  updateEntityInfo: ({ id, ...data }: EntityInfoBody, config?: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
@@ -123,7 +109,6 @@ declare const entityService: {
123
109
  retrieveBankAccount: (id: string) => Promise<any>;
124
110
  retrieveEntityInfo: (entity_id: string, config?: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
125
111
  updateIndividualInfo: ({ id, ...data }: EntityInfoBody) => Promise<any>;
126
- updateDocumentInfo: (data: DocumentUpdateBody) => Promise<any>;
127
112
  retrieveEntity: (entity_id: string) => Promise<any>;
128
113
  updateEntity: ({ id, ...data }: UpdateEntityBody) => Promise<any>;
129
114
  updateEntityActivity: ({ id, ...data }: UpdateEntityActivityBody) => Promise<any>;
@@ -69,13 +69,6 @@ var updateIndividualInfo = function (_a) {
69
69
  data: data
70
70
  });
71
71
  };
72
- var updateDocumentInfo = function (data) {
73
- return httpClient({
74
- method: 'post',
75
- url: "".concat(ENDPOINT_PATHS.DOCUMENT),
76
- data: data
77
- });
78
- };
79
72
  var retrieveEntityType = function () {
80
73
  return httpClient({
81
74
  method: 'get',
@@ -89,7 +82,6 @@ var entityService = {
89
82
  retrieveBankAccount: retrieveBankAccount,
90
83
  retrieveEntityInfo: retrieveEntityInfo,
91
84
  updateIndividualInfo: updateIndividualInfo,
92
- updateDocumentInfo: updateDocumentInfo,
93
85
  retrieveEntity: retrieveEntity,
94
86
  updateEntity: updateEntity,
95
87
  updateEntityActivity: updateEntityActivity,
@@ -9,5 +9,6 @@ export type UploadFileBody = {
9
9
  declare const fileService: {
10
10
  uploadFile: (data: UploadFileBody, config?: AxiosRequestConfig) => Promise<import("axios").AxiosResponse<any, any>>;
11
11
  uploadFileInfo: (data: UploadFileBody, config?: AxiosRequestConfig) => Promise<any>;
12
+ downloadFile: (id: string, name: string, config?: AxiosRequestConfig) => Promise<void>;
12
13
  };
13
14
  export { fileService };
package/build/api/file.js CHANGED
@@ -17,8 +17,20 @@ var uploadFileInfo = function (data, config) {
17
17
  var uploadFile = function (data, config) {
18
18
  return instance.post("".concat(ENDPOINT_PATHS.FILES_PATH), data, __assign({ headers: { 'Content-Type': 'multipart/form-data' } }, config));
19
19
  };
20
+ var downloadFile = function (id, name, config) {
21
+ return instance.get("".concat(ENDPOINT_PATHS.FILES_PATH, "/").concat(id, "/download"), __assign({ responseType: 'blob' }, config)).then(function (response) {
22
+ var url = window.URL.createObjectURL(response.data);
23
+ var link = document.createElement('a');
24
+ link.href = url;
25
+ link.download = name;
26
+ document.body.appendChild(link);
27
+ link.click();
28
+ window.URL.revokeObjectURL(url);
29
+ });
30
+ };
20
31
  var fileService = {
21
32
  uploadFile: uploadFile,
22
- uploadFileInfo: uploadFileInfo
33
+ uploadFileInfo: uploadFileInfo,
34
+ downloadFile: downloadFile
23
35
  };
24
36
  export { fileService };
@@ -3,13 +3,14 @@ import { ValidateOperatorBody } from './operator';
3
3
  import { CreateAuthBody, VerifyAuthBody, CreatePasswordBody, VerifyOperationAuthBody, ResetPasswordVerifyAuthBody, VerifyAuthExpressOTPBody } from './auth';
4
4
  import { UpdateLeadBody, LeadVerifyBody, CreateLeadBody, LeadOTPVerifyBody, LeadIdentityUpdateBody } from './lead';
5
5
  import { CheckEmailBody, CheckBrandBody } from './availabilityServices';
6
- import { EntityInfoBody, EntityBankUpdateBody, BankDocumentInfo, UpdateEntityBody, DocumentUpdateBody, DocumentInfo, UpdateEntityActivityBody, UpdateEntityCapitalBody } from './entity';
6
+ import { EntityInfoBody, EntityBankUpdateBody, BankDocumentInfo, UpdateEntityBody, UpdateEntityActivityBody, UpdateEntityCapitalBody } from './entity';
7
7
  import { CreateAccountBody, ExpressCreateAccountBody } from './account';
8
8
  import { DataElementBody } from './data';
9
9
  import { BrandListBody, UpdateBrandBody, UpdateIndividualBody, GetIndividualListBody } from './individual';
10
10
  import { UpdateBoardBody, RequestEmailBody } from './board';
11
11
  import { GetUserListBody } from './user';
12
12
  import { UploadFileBody } from './file';
13
+ import { DocumentUpdateBody, DocumentInfo, DocumentBody } from './document';
13
14
  declare const API: {
14
15
  locationService: {
15
16
  getIP: () => Promise<any>;
@@ -54,7 +55,6 @@ declare const API: {
54
55
  retrieveBankAccount: (id: string) => Promise<any>;
55
56
  retrieveEntityInfo: (entity_id: string, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("axios").AxiosResponse<any, any>>;
56
57
  updateIndividualInfo: ({ id, ...data }: EntityInfoBody) => Promise<any>;
57
- updateDocumentInfo: (data: DocumentUpdateBody) => Promise<any>;
58
58
  retrieveEntity: (entity_id: string) => Promise<any>;
59
59
  updateEntity: ({ id, ...data }: UpdateEntityBody) => Promise<any>;
60
60
  updateEntityActivity: ({ id, ...data }: UpdateEntityActivityBody) => Promise<any>;
@@ -133,8 +133,14 @@ declare const API: {
133
133
  fileService: {
134
134
  uploadFile: (data: UploadFileBody, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("axios").AxiosResponse<any, any>>;
135
135
  uploadFileInfo: (data: UploadFileBody, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<any>;
136
+ downloadFile: (id: string, name: string, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<void>;
137
+ };
138
+ documentService: {
139
+ updateDocumentInfo: (data: DocumentUpdateBody) => Promise<any>;
140
+ addFilesToExistingDocument: ({ id, ...data }: DocumentBody) => Promise<any>;
141
+ removeFilesFromDocument: ({ id, ...data }: DocumentBody) => Promise<import("axios").AxiosResponse<any, any>>;
136
142
  };
137
143
  };
138
- export type { ValidateOperatorBody, CreateAuthBody, ExpressCreateAccountBody, VerifyAuthBody, CreateLeadBody, UpdateLeadBody, LeadVerifyBody, LeadOTPVerifyBody, CheckEmailBody, CheckBrandBody, LeadIdentityUpdateBody, EntityInfoBody, CreateAccountBody, EntityBankUpdateBody, CreatePasswordBody, BrandListBody, VerifyOperationAuthBody, ResetPasswordVerifyAuthBody, UpdateBoardBody, UpdateBrandBody, DataElementBody, UploadFileBody, UpdateEntityBody, DocumentUpdateBody, DocumentInfo, VerifyAuthExpressOTPBody, UpdateIndividualBody, UpdateEntityActivityBody, UpdateEntityCapitalBody, BankDocumentInfo, GetUserListBody, GetIndividualListBody, RequestEmailBody };
144
+ export type { ValidateOperatorBody, CreateAuthBody, ExpressCreateAccountBody, VerifyAuthBody, CreateLeadBody, UpdateLeadBody, LeadVerifyBody, LeadOTPVerifyBody, CheckEmailBody, CheckBrandBody, LeadIdentityUpdateBody, EntityInfoBody, CreateAccountBody, EntityBankUpdateBody, CreatePasswordBody, BrandListBody, VerifyOperationAuthBody, ResetPasswordVerifyAuthBody, UpdateBoardBody, UpdateBrandBody, DataElementBody, UploadFileBody, UpdateEntityBody, DocumentUpdateBody, DocumentInfo, VerifyAuthExpressOTPBody, UpdateIndividualBody, UpdateEntityActivityBody, UpdateEntityCapitalBody, BankDocumentInfo, GetUserListBody, GetIndividualListBody, RequestEmailBody, DocumentBody };
139
145
  export { setAxiosGlobalHeaders, removeAxiosGlobalHeaders, axiosInstance, getAxiosHeaders };
140
146
  export default API;
@@ -14,6 +14,7 @@ import { boardService } from './board';
14
14
  import { userService } from './user';
15
15
  import { brandService } from './brand';
16
16
  import { fileService } from './file';
17
+ import { documentService } from './document';
17
18
  var API = {
18
19
  locationService: locationService,
19
20
  operatorService: operatorService,
@@ -29,7 +30,8 @@ var API = {
29
30
  boardService: boardService,
30
31
  userService: userService,
31
32
  brandService: brandService,
32
- fileService: fileService
33
+ fileService: fileService,
34
+ documentService: documentService
33
35
  };
34
36
  export { setAxiosGlobalHeaders, removeAxiosGlobalHeaders, axiosInstance, getAxiosHeaders };
35
37
  export default API;
@@ -1,4 +1,4 @@
1
- import { DocumentInfo } from './entity';
1
+ import { DocumentInfo } from './document';
2
2
  export type BrandListBody = {
3
3
  individual_id: string;
4
4
  };
@@ -388,5 +388,7 @@
388
388
  "share_value_label": "قيمة السهم ({{currency}})",
389
389
  "share_value_hint": "0000",
390
390
  "brand": "الاسم التجاري",
391
- "try_again": "حاول مرة أخرى"
391
+ "try_again": "حاول مرة أخرى",
392
+ "file_delete_error": "حدث خطأ ما في حذف الملف. حاول مرة اخرى",
393
+ "file_download_error": "حدث خطأ ما في تحميل الملف. حاول مرة اخرى"
392
394
  }
@@ -418,5 +418,7 @@
418
418
  "share_value_label": "Share Value ({{currency}})",
419
419
  "share_value_hint": "0000",
420
420
  "brand": "Brand",
421
- "try_again": "Try again"
421
+ "try_again": "Try again",
422
+ "file_delete_error": "Something went wrong with deleting file. Please try again",
423
+ "file_download_error": "Something went wrong with downloading file. Please try again"
422
424
  }
@@ -1,6 +1,6 @@
1
+ import { CancelToken } from 'axios';
1
2
  import { RootState } from '../../../app/store';
2
3
  import { ActionState, BankFormValues, FlowsTypes, OTPFormValues, ResponseData, SharedState } from '../../../@types';
3
- import { CancelToken } from 'axios';
4
4
  interface VerifyLeadTokenProps {
5
5
  token: string;
6
6
  isInternally?: boolean;
@@ -180,10 +180,10 @@ export var retrieveBoardDetails = createAsyncThunk('retrieveBankEntityInfo', fun
180
180
  });
181
181
  }); });
182
182
  export var createBankAccount = createAsyncThunk('createBankAccount', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
183
- var _a, settings, bank, iban, beneficiaryName, bankName, bankStatementId, confirmPolicy, bank_account, isIBANEditable, isBeneficiaryNameEditable, isBankNameEditable, isBankStatementIdEditable, requestBody, data;
184
- var _b, _c, _d, _e, _f, _g, _h;
185
- return __generator(this, function (_j) {
186
- switch (_j.label) {
183
+ var _a, settings, bank, iban, beneficiaryName, bankName, bankStatementId, confirmPolicy, bank_account, isIBANEditable, isBeneficiaryNameEditable, isBankNameEditable, isBankStatementIdEditable, documentResponse, hasDocument, documentId, documentBody, requestBody, data;
184
+ var _b, _c, _d, _e, _f, _g, _h, _j;
185
+ return __generator(this, function (_k) {
186
+ switch (_k.label) {
187
187
  case 0:
188
188
  _a = thunkApi.getState(), settings = _a.settings, bank = _a.bank;
189
189
  iban = params.iban, beneficiaryName = params.beneficiaryName, bankName = params.bankName, bankStatementId = params.bankStatementId, confirmPolicy = params.confirmPolicy;
@@ -192,14 +192,27 @@ export var createBankAccount = createAsyncThunk('createBankAccount', function (p
192
192
  isBeneficiaryNameEditable = true;
193
193
  isBankNameEditable = true;
194
194
  isBankStatementIdEditable = true;
195
+ documentResponse = undefined;
196
+ hasDocument = isBankStatementIdEditable && (bankStatementId || []).length > 0;
197
+ documentId = (_b = bank_account === null || bank_account === void 0 ? void 0 : bank_account.document) === null || _b === void 0 ? void 0 : _b.id;
198
+ if (!(documentId && hasDocument)) return [3, 2];
199
+ documentBody = {
200
+ id: documentId,
201
+ files: bankStatementId || []
202
+ };
203
+ return [4, API.documentService.addFilesToExistingDocument(documentBody)];
204
+ case 1:
205
+ documentResponse = _k.sent();
206
+ _k.label = 2;
207
+ case 2:
195
208
  requestBody = {
196
- wallet_id: (_f = (_e = (_d = (_c = (_b = bank.data.verify.responseBody) === null || _b === void 0 ? void 0 : _b.business) === null || _c === void 0 ? void 0 : _c.entity) === null || _d === void 0 ? void 0 : _d.merchant) === null || _e === void 0 ? void 0 : _e.wallet) === null || _f === void 0 ? void 0 : _f.id,
209
+ wallet_id: (_g = (_f = (_e = (_d = (_c = bank.data.verify.responseBody) === null || _c === void 0 ? void 0 : _c.business) === null || _d === void 0 ? void 0 : _d.entity) === null || _e === void 0 ? void 0 : _e.merchant) === null || _f === void 0 ? void 0 : _f.wallet) === null || _g === void 0 ? void 0 : _g.id,
197
210
  bank_account: {
198
211
  iban: isIBANEditable ? iban : undefined,
199
212
  beneficiary_name: isBeneficiaryNameEditable ? beneficiaryName : undefined,
200
213
  bank_name: isBankNameEditable ? bankName : undefined,
201
214
  is_acknowledged: confirmPolicy,
202
- document: isBankStatementIdEditable && (bankStatementId || []).length > 0
215
+ document: !documentId && hasDocument
203
216
  ? {
204
217
  type: 'bank_statement',
205
218
  files: bankStatementId || []
@@ -210,11 +223,12 @@ export var createBankAccount = createAsyncThunk('createBankAccount', function (p
210
223
  encryption_contract: ['bank_account.iban', 'bank_account.beneficiary_name', 'bank_account.bank_name']
211
224
  };
212
225
  return [4, API.entityService.createBankAccount(requestBody)];
213
- case 1:
214
- data = (_j.sent()).data;
226
+ case 3:
227
+ data = (_k.sent()).data;
215
228
  if (!data.errors) {
229
+ data.documentData = documentResponse;
216
230
  thunkApi.dispatch(handleNextScreenStep());
217
- (_h = (_g = settings.data.appConfig).onStepCompleted) === null || _h === void 0 ? void 0 : _h.call(_g, settings.data.activeScreen.name, requestBody);
231
+ (_j = (_h = settings.data.appConfig).onStepCompleted) === null || _j === void 0 ? void 0 : _j.call(_h, settings.data.activeScreen.name, requestBody);
218
232
  }
219
233
  return [2, { data: data, formData: params }];
220
234
  }
@@ -45,13 +45,24 @@ 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
+ var __rest = (this && this.__rest) || function (s, e) {
49
+ var t = {};
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
+ t[p] = s[p];
52
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
54
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
55
+ t[p[i]] = s[p[i]];
56
+ }
57
+ return t;
58
+ };
48
59
  var _a;
49
60
  import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
50
61
  import API from '../../../api';
51
62
  import { FlowsTypes } from '../../../@types';
52
63
  import { handleNextScreenStep, handleSetCountryByIso2 } from '../../../app/settings';
53
64
  import { BRAND_STEP_NAMES } from '../../../constants';
54
- import { findInArrayOrSubArray, isKW, isTwitter, isWebsite, sleep } from '../../../utils';
65
+ import { isKW, isTwitter, isWebsite, sleep } from '../../../utils';
55
66
  export var verifyLeadToken = createAsyncThunk('brandVerifyLeadToken', function (_a, thunkApi) {
56
67
  var token = _a.token, isInternally = _a.isInternally;
57
68
  return __awaiter(void 0, void 0, void 0, function () {
@@ -340,7 +351,7 @@ export var updateBrandActivities = createAsyncThunk('brandUpdateBrandActivities'
340
351
  }); });
341
352
  customerBaseId = (expectedCustomer === null || expectedCustomer === void 0 ? void 0 : expectedCustomer.id) && { id: expectedCustomer.id, period: 'monthly' };
342
353
  salesId = (expectedSale === null || expectedSale === void 0 ? void 0 : expectedSale.id) && { id: expectedSale.id, period: 'monthly' };
343
- customerBase = (customerBaseId || customerLocation.length) && __assign(__assign({}, (customerBaseId && { id: expectedCustomer.id, period: 'monthly' })), (customerLocation.length && { location: customerLocation }));
354
+ customerBase = (customerBaseId || customerLocation.length) && __assign(__assign({}, (customerBaseId && { id: expectedCustomer.id, period: 'monthly' })), (customerLocation.length && { locations: customerLocation }));
344
355
  if (customerBase)
345
356
  requestBody = __assign(__assign({}, requestBody), { operations: __assign(__assign({}, requestBody.operations), { customer_base: customerBase }) });
346
357
  if (salesId && isSalesRangeEditable) {
@@ -400,12 +411,14 @@ export var updateBoardSuccess = createAsyncThunk('updateBoardBrandSuccess', func
400
411
  step_name: BRAND_STEP_NAMES.BRAND_SUCCESS,
401
412
  id: id
402
413
  };
403
- data = {};
404
- return [4, API.boardService.retrieveBoardInfoStatus(id)];
414
+ return [4, API.boardService.updateBoardInfo(__assign({ id: id, infoId: infoId }, payload))];
405
415
  case 1:
416
+ data = _g.sent();
417
+ return [4, API.boardService.retrieveBoardInfoStatus(id)];
418
+ case 2:
406
419
  boardInfoData = _g.sent();
407
420
  return [4, thunkApi.dispatch(retrieveBoardDetails(id)).unwrap()];
408
- case 2:
421
+ case 3:
409
422
  _g.sent();
410
423
  (_d = (_c = settings.data.appConfig).onStepCompleted) === null || _d === void 0 ? void 0 : _d.call(_c, settings.data.activeScreen.name, {});
411
424
  (_f = (_e = settings.data.appConfig).onFlowCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, { data: data });
@@ -580,13 +593,13 @@ export var brandSlice = createSlice({
580
593
  state.data.brandData = formData;
581
594
  state.data.brandActivities.activities = (selectedActivity === null || selectedActivity === void 0 ? void 0 : selectedActivity.length) > 0 ? selectedActivity : [];
582
595
  var _b = operations || {}, customer_base = _b.customer_base, sales = _b.sales;
583
- var _c = state.data.brandActivities.responseBody || {}, customerBases = _c.customerBases, expectedSales = _c.expectedSales, expectedCustomerSales = _c.expectedCustomerSales;
584
- var findCustomerBase = findInArrayOrSubArray(expectedCustomerSales, customer_base === null || customer_base === void 0 ? void 0 : customer_base.id);
585
- var findSale = findInArrayOrSubArray(expectedSales, sales === null || sales === void 0 ? void 0 : sales.id);
586
- if (!!findSale)
587
- state.data.brandActivities.expectedSale = findSale;
588
- if (!!findCustomerBase)
589
- state.data.brandActivities.expectedCustomer = findCustomerBase;
596
+ var _c = customer_base || {}, locations = _c.locations, customerBase = __rest(_c, ["locations"]);
597
+ if (locations && locations.length)
598
+ state.data.brandActivities.customerLocations = locations;
599
+ if (!!sales)
600
+ state.data.brandActivities.expectedSale = sales;
601
+ if (!!customerBase)
602
+ state.data.brandActivities.expectedCustomer = customerBase;
590
603
  state.data.verify.responseBody = __assign(__assign({}, state.data.verify.responseBody), { activities: data === null || data === void 0 ? void 0 : data.brand_activities });
591
604
  })
592
605
  .addCase(updateBrandActivities.rejected, function (state, action) {
@@ -494,7 +494,7 @@ export var updateLeadBusinessType = createAsyncThunk('updateLeadBusinessType', f
494
494
  }
495
495
  ]
496
496
  };
497
- return [4, API.entityService.updateDocumentInfo(documentBody)];
497
+ return [4, API.documentService.updateDocumentInfo(documentBody)];
498
498
  case 5:
499
499
  documentData = _h.sent();
500
500
  _h.label = 6;
@@ -63,7 +63,7 @@ import { BusinessType, DocumentPurpose, FlowsTypes } from '../../../@types';
63
63
  import { handleNextScreenStep, handleSetCountryByIso2 } from '../../../app/settings';
64
64
  import { ENTITY_STEP_NAMES } from '../../../constants';
65
65
  import moment from 'moment';
66
- import { convertNumbers2English } from '../../../utils';
66
+ import { convertNumbers2English, getRecentDocumentBasedOnPurpose } from '../../../utils';
67
67
  export var verifyLeadToken = createAsyncThunk('entityVerifyLeadToken', function (_a, thunkApi) {
68
68
  var token = _a.token, isInternally = _a.isInternally;
69
69
  return __awaiter(void 0, void 0, void 0, function () {
@@ -240,10 +240,10 @@ export var retrieveBoardDetails = createAsyncThunk('entityRetrieveEntityInfo', f
240
240
  });
241
241
  }); });
242
242
  export var updateEntityName = createAsyncThunk('entityUpdateEntityName', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
243
- var _a, settings, entity, entityData, _b, id, data_status, articleId, issuingDate, expiryDate, isFL, isLegalNameEditable, isLicenseTypeEditable, isEntityTypeEditable, isLicenseNumberEditable, isUnifiedNumberEditable, isIssuingDateEditable, isExpiryDateEditable, payload, data, documentBody, _c, list;
244
- var _d, _e;
245
- return __generator(this, function (_f) {
246
- switch (_f.label) {
243
+ var _a, settings, entity, entityData, _b, id, data_status, articleId, issuingDate, expiryDate, isFL, isLegalNameEditable, isLicenseTypeEditable, isEntityTypeEditable, isLicenseNumberEditable, isUnifiedNumberEditable, isIssuingDateEditable, isExpiryDateEditable, documentResponse, document, documentBody, documentBody, payload, data, list;
244
+ var _c, _d;
245
+ return __generator(this, function (_e) {
246
+ switch (_e.label) {
247
247
  case 0:
248
248
  _a = thunkApi.getState(), settings = _a.settings, entity = _a.entity;
249
249
  entityData = (entity.data.verify.responseBody || {}).entity;
@@ -259,6 +259,32 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
259
259
  isUnifiedNumberEditable = true;
260
260
  isIssuingDateEditable = true;
261
261
  isExpiryDateEditable = true;
262
+ documentResponse = undefined;
263
+ document = getRecentDocumentBasedOnPurpose(entityData === null || entityData === void 0 ? void 0 : entityData.documents, DocumentPurpose.CR);
264
+ if (!((params.certificateId || []).length > 0)) return [3, 4];
265
+ if (!(document === null || document === void 0 ? void 0 : document.id)) return [3, 2];
266
+ documentBody = {
267
+ id: document === null || document === void 0 ? void 0 : document.id,
268
+ images: params.certificateId
269
+ };
270
+ return [4, API.documentService.addFilesToExistingDocument(documentBody)];
271
+ case 1:
272
+ documentResponse = _e.sent();
273
+ return [3, 4];
274
+ case 2:
275
+ documentBody = {
276
+ entity_id: id || '',
277
+ documents: [
278
+ {
279
+ images: params.certificateId
280
+ }
281
+ ]
282
+ };
283
+ return [4, API.documentService.updateDocumentInfo(documentBody)];
284
+ case 3:
285
+ documentResponse = _e.sent();
286
+ _e.label = 4;
287
+ case 4:
262
288
  payload = {
263
289
  id: id,
264
290
  AOA_file_id: articleId,
@@ -292,28 +318,15 @@ export var updateEntityName = createAsyncThunk('entityUpdateEntityName', functio
292
318
  ]
293
319
  };
294
320
  return [4, API.entityService.updateEntity(payload)];
295
- case 1:
296
- data = _f.sent();
297
- if (!((params.certificateId || []).length > 0)) return [3, 3];
298
- documentBody = {
299
- entity_id: id || '',
300
- documents: [
301
- {
302
- images: params.certificateId
303
- }
304
- ]
305
- };
306
- _c = data;
307
- return [4, API.entityService.updateDocumentInfo(documentBody)];
308
- case 2:
309
- _c.documentData = _f.sent();
310
- _f.label = 3;
311
- case 3: return [4, API.dataService.getActivities()];
312
- case 4:
313
- list = (_f.sent()).list;
321
+ case 5:
322
+ data = _e.sent();
323
+ data.documentData = documentResponse;
324
+ return [4, API.dataService.getActivities()];
325
+ case 6:
326
+ list = (_e.sent()).list;
314
327
  data.activityList = list;
315
328
  thunkApi.dispatch(handleNextScreenStep());
316
- (_e = (_d = settings.data.appConfig).onStepCompleted) === null || _e === void 0 ? void 0 : _e.call(_d, settings.data.activeScreen.name, id);
329
+ (_d = (_c = settings.data.appConfig).onStepCompleted) === null || _d === void 0 ? void 0 : _d.call(_c, settings.data.activeScreen.name, id);
317
330
  return [2, { data: data, formData: params }];
318
331
  }
319
332
  });
@@ -624,7 +637,7 @@ export var entitySlice = createSlice({
624
637
  var _b = data || {}, activityList = _b.activityList, rest = __rest(_b, ["activityList"]);
625
638
  state.data.entityNameData = formData;
626
639
  state.data.entityNameData.responseBody = __assign(__assign({}, state.data.entityNameData.responseBody), { rest: rest });
627
- state.data.verify.responseBody = __assign(__assign({}, state.data.verify.responseBody), { activityList: activityList });
640
+ state.data.verify.responseBody = __assign(__assign({}, state.data.verify.responseBody), { entity: data === null || data === void 0 ? void 0 : data.entity, activityList: activityList });
628
641
  if (rest === null || rest === void 0 ? void 0 : rest.activities)
629
642
  state.data.entityCapitalData = __assign(__assign({}, state.data.entityCapitalData), { activities: rest === null || rest === void 0 ? void 0 : rest.activities });
630
643
  })
@@ -648,7 +648,7 @@ export var updateIndividualInfo = createAsyncThunk('updateIndividualInfo', funct
648
648
  documents: documentsList
649
649
  };
650
650
  if (!(documentsList.length > 0)) return [3, 2];
651
- return [4, API.entityService.updateDocumentInfo(documentBody)];
651
+ return [4, API.documentService.updateDocumentInfo(documentBody)];
652
652
  case 1:
653
653
  _f.sent();
654
654
  _f.label = 2;
@@ -48,9 +48,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  var _a;
49
49
  import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
50
50
  import API from '../../../api';
51
- import { FlowsTypes } from '../../../@types';
51
+ import { DocumentPurpose, FlowsTypes } from '../../../@types';
52
52
  import { handleNextScreenStep, handleCurrentActiveScreen, handleSetCountryByIso2 } from '../../../app/settings';
53
53
  import { TAX_STEP_NAMES } from '../../../constants';
54
+ import { getRecentDocumentBasedOnPurpose } from '../../../utils';
54
55
  export var verifyLeadToken = createAsyncThunk('taxVerifyLeadToken', function (_a, thunkApi) {
55
56
  var token = _a.token, isInternally = _a.isInternally;
56
57
  return __awaiter(void 0, void 0, void 0, function () {
@@ -168,15 +169,16 @@ export var verifyTaxLeadOTP = createAsyncThunk('verifyTaxLeadOTP', function (par
168
169
  });
169
170
  }); });
170
171
  export var updateTaxInfo = createAsyncThunk('updateTaxInfo', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
171
- var _a, settings, tax, entity, entityId, isTaxNumberEditable, requestBody, data, documentBody, _b;
172
- var _c, _d, _e;
173
- return __generator(this, function (_f) {
174
- switch (_f.label) {
172
+ var _a, settings, tax, entity, entityId, isTaxNumberEditable, document, requestBody, data, documentBody, _b, documentBody, _c;
173
+ var _d, _e, _f;
174
+ return __generator(this, function (_g) {
175
+ switch (_g.label) {
175
176
  case 0:
176
177
  _a = thunkApi.getState(), settings = _a.settings, tax = _a.tax;
177
178
  entity = (tax.data.verify.responseBody || {}).entity;
178
179
  entityId = entity === null || entity === void 0 ? void 0 : entity.id;
179
180
  isTaxNumberEditable = true;
181
+ document = getRecentDocumentBasedOnPurpose(entity === null || entity === void 0 ? void 0 : entity.documents, DocumentPurpose.TAX_DOCUMENT);
180
182
  requestBody = {
181
183
  id: entityId,
182
184
  vat_id: isTaxNumberEditable ? params.vatId : undefined,
@@ -185,10 +187,21 @@ export var updateTaxInfo = createAsyncThunk('updateTaxInfo', function (params, t
185
187
  };
186
188
  return [4, API.entityService.updateEntityInfo(requestBody)];
187
189
  case 1:
188
- data = (_f.sent()).data;
189
- if ((_c = data.errors) === null || _c === void 0 ? void 0 : _c.length)
190
+ data = (_g.sent()).data;
191
+ if ((_d = data.errors) === null || _d === void 0 ? void 0 : _d.length)
190
192
  throw new Error(data.errors[0].description);
191
- if (!((params.documentId || []).length > 0)) return [3, 3];
193
+ if (!((params.documentId || []).length > 0)) return [3, 5];
194
+ if (!(document === null || document === void 0 ? void 0 : document.id)) return [3, 3];
195
+ documentBody = {
196
+ id: document === null || document === void 0 ? void 0 : document.id,
197
+ images: params.documentId
198
+ };
199
+ _b = data;
200
+ return [4, API.documentService.addFilesToExistingDocument(documentBody)];
201
+ case 2:
202
+ _b.documentData = _g.sent();
203
+ return [3, 5];
204
+ case 3:
192
205
  documentBody = {
193
206
  entity_id: entityId || '',
194
207
  documents: [
@@ -197,14 +210,14 @@ export var updateTaxInfo = createAsyncThunk('updateTaxInfo', function (params, t
197
210
  }
198
211
  ]
199
212
  };
200
- _b = data;
201
- return [4, API.entityService.updateDocumentInfo(documentBody)];
202
- case 2:
203
- _b.documentData = _f.sent();
204
- _f.label = 3;
205
- case 3:
213
+ _c = data;
214
+ return [4, API.documentService.updateDocumentInfo(documentBody)];
215
+ case 4:
216
+ _c.documentData = _g.sent();
217
+ _g.label = 5;
218
+ case 5:
206
219
  thunkApi.dispatch(handleNextScreenStep());
207
- (_e = (_d = settings.data.appConfig).onStepCompleted) === null || _e === void 0 ? void 0 : _e.call(_d, settings.data.activeScreen.name, requestBody);
220
+ (_f = (_e = settings.data.appConfig).onStepCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, settings.data.activeScreen.name, requestBody);
208
221
  return [2, { data: data, formData: params }];
209
222
  }
210
223
  });
@@ -6,7 +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 { getRecentDocumentFiles } from '../../../../utils';
9
+ import { getFileDetailsFromDocument } from '../../../../utils';
10
10
  import { bankSelector, bankStatementUploadingStatus } from '../../../app/bank/bankStore';
11
11
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
12
12
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
@@ -30,7 +30,7 @@ var BankStatement = function (_a) {
30
30
  var handleReset = function (ids) {
31
31
  bankStatementIdControl.field.onChange(ids);
32
32
  };
33
- var defaultFiles = React.useMemo(function () { return getRecentDocumentFiles(document ? [document] : [], DocumentPurpose.BANK_STATEMENT); }, [document]);
33
+ var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(document ? [document] : [], DocumentPurpose.BANK_STATEMENT); }, [document]);
34
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
35
  };
36
36
  export default BankStatement;
@@ -17,7 +17,7 @@ import { styled } from '@mui/material/styles';
17
17
  import Collapse from '../../../../components/Collapse';
18
18
  import { DocumentPurpose } from '../../../../@types';
19
19
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
20
- import { getRecentDocumentFiles } from '../../../../utils';
20
+ import { getFileDetailsFromDocument } from '../../../../utils';
21
21
  import { ScreenContainer } from '../../../shared/Containers';
22
22
  import { entitySelector, uploadingStatus } from '../../../app/entity/entityStore';
23
23
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
@@ -42,7 +42,7 @@ var LicenseCertificate = function (_a) {
42
42
  var handleReset = function (ids) {
43
43
  certificateIdControl.field.onChange(ids);
44
44
  };
45
- var defaultFiles = React.useMemo(function () { return getRecentDocumentFiles(documents, DocumentPurpose.CR); }, [documents]);
45
+ var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.CR); }, [documents]);
46
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
47
  };
48
48
  export default LicenseCertificate;
@@ -6,7 +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 { getRecentDocumentFiles } from '../../../../utils';
9
+ import { getFileDetailsFromDocument } from '../../../../utils';
10
10
  import { civilIDUploadingStatus, individualSelector } from '../../../app/individual/individualStore';
11
11
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
12
12
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
@@ -29,7 +29,7 @@ var CivilIDFile = function () {
29
29
  var handleReset = function (ids) {
30
30
  civilIDFileIdControl.field.onChange(ids);
31
31
  };
32
- var defaultFiles = React.useMemo(function () { return getRecentDocumentFiles(documents, DocumentPurpose.IDENTITY_DOCUMENT); }, [documents]);
32
+ var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.IDENTITY_DOCUMENT); }, [documents]);
33
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
34
  };
35
35
  export default CivilIDFile;
@@ -16,7 +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 { getRecentDocumentFiles } from '../../../../utils';
19
+ import { getFileDetailsFromDocument } from '../../../../utils';
20
20
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
21
21
  import { ScreenContainer } from '../../../shared/Containers';
22
22
  import { individualSelector, signatureFileUploadingStatus } from '../../../app/individual/individualStore';
@@ -42,7 +42,7 @@ var SignatureFile = function (_a) {
42
42
  var handleReset = function (ids) {
43
43
  signatureFileIdControl.field.onChange(ids);
44
44
  };
45
- var defaultFiles = React.useMemo(function () { return getRecentDocumentFiles(documents, DocumentPurpose.CUSTOMER_SIGNATURE); }, [documents]);
45
+ var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.CUSTOMER_SIGNATURE); }, [documents]);
46
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
47
  };
48
48
  export default SignatureFile;
@@ -11,21 +11,31 @@ export declare const InputContainerStyled: import("@emotion/styled").StyledCompo
11
11
  export declare enum FileStatus {
12
12
  INIT = "init",
13
13
  UPLOADING = "uploading",
14
+ DOWNLOADING = "downloading",
14
15
  SUCCESS = "success",
15
16
  ERROR = "error",
16
17
  ALREADY_UPLOADED = "already_uploaded"
17
18
  }
19
+ export declare enum DeleteFileStatus {
20
+ NONE = "none",
21
+ DELETING = "deleting",
22
+ ERROR = "error",
23
+ SUCCESS = "success"
24
+ }
18
25
  export type FileInfo = {
19
26
  fileId: string;
27
+ docId: string;
20
28
  name: string;
21
29
  status: FileStatus;
22
30
  progress: number;
23
31
  error: string;
32
+ deleteStatus: DeleteFileStatus;
24
33
  };
25
34
  export type UploadFileProps = {
26
35
  index: number;
27
36
  purpose: string;
28
37
  file: File;
38
+ required?: boolean;
29
39
  title?: string;
30
40
  uploadedFiles: Array<FileInfo>;
31
41
  onSuccess: (index: number, file: FileInfo) => void;
@@ -34,5 +44,5 @@ export type UploadFileProps = {
34
44
  onProgress: (index: number, file: FileInfo) => void;
35
45
  sx?: SxProps<Theme> | undefined;
36
46
  };
37
- declare const UploadFile: ({ index, title, file, uploadedFiles, onSuccess, onFailure, onDelete, onProgress, sx, purpose }: UploadFileProps) => JSX.Element;
47
+ declare const UploadFile: ({ index, title, file, uploadedFiles, onSuccess, onFailure, onDelete, onProgress, sx, purpose, required }: UploadFileProps) => JSX.Element;
38
48
  export default UploadFile;
@@ -51,11 +51,13 @@ import { useTranslation } from 'react-i18next';
51
51
  import { alpha, styled, useTheme } from '@mui/material/styles';
52
52
  import Box from '@mui/material/Box';
53
53
  import ClearIcon from '@mui/icons-material/Clear';
54
+ import { CircularProgress as MUICircularProgress } from '@mui/material';
54
55
  import Collapse from '../../../components/Collapse';
55
56
  import { CircularProgress } from '../../../components/ProgressBar';
56
57
  import Text from '../../../components/Text';
57
58
  import Icon from '../../../components/Icon';
58
59
  import { maskFileName } from '../../../utils';
60
+ import { DocumentPurpose } from '../../../@types';
59
61
  import API from '../../../api';
60
62
  import { ICONS_NAMES, MAX_FILE_SIZE_FOUR_MB, VALID_FILE_FORMATS } from '../../../constants';
61
63
  import CheckIcon from '../../shared/CheckIcon';
@@ -81,7 +83,7 @@ export var InputContainerStyled = styled(Box)(function () { return ({
81
83
  width: '100%',
82
84
  justifyContent: 'center'
83
85
  }); });
84
- var CenterBoxStyled = styled(Box)(function () { return ({
86
+ var ProgressBoxStyled = styled(Box)(function () { return ({
85
87
  display: 'flex',
86
88
  justifyContent: 'center',
87
89
  alignItems: 'center'
@@ -110,17 +112,25 @@ export var FileStatus;
110
112
  (function (FileStatus) {
111
113
  FileStatus["INIT"] = "init";
112
114
  FileStatus["UPLOADING"] = "uploading";
115
+ FileStatus["DOWNLOADING"] = "downloading";
113
116
  FileStatus["SUCCESS"] = "success";
114
117
  FileStatus["ERROR"] = "error";
115
118
  FileStatus["ALREADY_UPLOADED"] = "already_uploaded";
116
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 = {}));
117
127
  var UploadFile = function (_a) {
118
- 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;
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;
119
129
  var theme = useTheme();
120
130
  var t = useTranslation().t;
121
131
  var _b = file || {}, name = _b.name, size = _b.size, type = _b.type;
122
132
  var uploadedFile = (uploadedFiles === null || uploadedFiles === void 0 ? void 0 : uploadedFiles[index]) || {};
123
- var status = uploadedFile.status, progress = uploadedFile.progress, error = uploadedFile.error;
133
+ var status = uploadedFile.status, progress = uploadedFile.progress, error = uploadedFile.error, deleteStatus = uploadedFile.deleteStatus;
124
134
  var uploadFile = function () { return __awaiter(void 0, void 0, void 0, function () {
125
135
  var uploadPayload, onUploadProgress, data, fileId;
126
136
  return __generator(this, function (_a) {
@@ -153,6 +163,68 @@ var UploadFile = function (_a) {
153
163
  }
154
164
  });
155
165
  }); };
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) {
170
+ 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);
175
+ return [4, API.documentService.removeFilesFromDocument(payload)];
176
+ case 1:
177
+ data = (_a.sent()).data;
178
+ docId = (data || {}).id;
179
+ if (docId) {
180
+ uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.SUCCESS, fileId: '' });
181
+ onSuccess(index, uploadedFile);
182
+ onDelete(index);
183
+ }
184
+ else {
185
+ uploadedFile = __assign(__assign({}, uploadedFile), { deleteStatus: DeleteFileStatus.ERROR, error: 'file_delete_error' });
186
+ onFailure(index, uploadedFile);
187
+ }
188
+ return [2];
189
+ }
190
+ });
191
+ }); };
192
+ var downloadFile = function () { return __awaiter(void 0, void 0, void 0, function () {
193
+ var onDownloadProgress, _a;
194
+ return __generator(this, function (_b) {
195
+ switch (_b.label) {
196
+ case 0:
197
+ onDownloadProgress = function (progressEvent) {
198
+ 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);
201
+ };
202
+ _b.label = 1;
203
+ case 1:
204
+ _b.trys.push([1, 3, , 4]);
205
+ return [4, API.fileService.downloadFile(uploadedFile.fileId, uploadedFile.name, { onDownloadProgress: onDownloadProgress })];
206
+ case 2:
207
+ _b.sent();
208
+ uploadedFile = __assign(__assign({}, uploadedFile), { status: FileStatus.SUCCESS });
209
+ onSuccess(index, uploadedFile);
210
+ return [3, 4];
211
+ case 3:
212
+ _a = _b.sent();
213
+ uploadedFile = __assign(__assign({}, uploadedFile), { error: 'file_download_error', status: FileStatus.SUCCESS });
214
+ onFailure(index, uploadedFile);
215
+ return [3, 4];
216
+ case 4: return [2];
217
+ }
218
+ });
219
+ }); };
220
+ var handleDeleteFile = function (index) {
221
+ var canDeleteFile = required ? uploadedFiles.length > 1 : true;
222
+ if (canDeleteFile && uploadedFile.docId) {
223
+ deleteFile();
224
+ return;
225
+ }
226
+ onDelete(index);
227
+ };
156
228
  React.useEffect(function () {
157
229
  if (!file)
158
230
  return;
@@ -174,11 +246,12 @@ var UploadFile = function (_a) {
174
246
  }
175
247
  }
176
248
  }, []);
249
+ var canDownloadFile = uploadedFile.fileId && status !== FileStatus.DOWNLOADING;
177
250
  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: {
178
251
  display: 'flex',
179
252
  flexDirection: 'column',
180
253
  padding: theme.spacing(1.5, 0, 1.5),
181
254
  width: '100%'
182
- } }, { children: [_jsxs(Box, __assign({ sx: { display: 'flex', flexDirection: 'row' } }, { 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(CenterBoxStyled, { children: 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 ? undefined : function () { return onDelete(index); } }, { children: _jsx(ClearIconStyled, {}) }))] })) }, index));
255
+ } }, { 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));
183
256
  };
184
257
  export default UploadFile;
@@ -28,7 +28,7 @@ import Collapse from '../../../components/Collapse';
28
28
  import { InputLabelStyled } from '../../shared/Input/Input';
29
29
  import { ScreenContainer } from '../../shared/Containers';
30
30
  import Mandatory from '../../shared/Mandatory';
31
- import UploadFile, { FileStatus } from './UploadFile';
31
+ import UploadFile, { DeleteFileStatus, FileStatus } from './UploadFile';
32
32
  import { useController } from 'react-hook-form';
33
33
  import { getFileType } from '../../../utils';
34
34
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
@@ -76,10 +76,12 @@ var UploadMultipleFile = function (_a) {
76
76
  fileArray.push({ name: file.title, size: file.size, type: getFileType(file.type) });
77
77
  fileInfoArray.push({
78
78
  fileId: file.id,
79
+ docId: file.docId,
79
80
  status: FileStatus.SUCCESS,
80
81
  progress: 100,
81
82
  error: '',
82
- name: file.title || ''
83
+ name: file.title || '',
84
+ deleteStatus: DeleteFileStatus.NONE
83
85
  });
84
86
  });
85
87
  fileControl.field.onChange(__spreadArray([], fileArray, true));
@@ -107,14 +109,24 @@ var UploadMultipleFile = function (_a) {
107
109
  if (isFileAlreadyUploaded) {
108
110
  fileInfoArray.push({
109
111
  fileId: '',
112
+ docId: '',
110
113
  status: FileStatus.ALREADY_UPLOADED,
111
114
  progress: 0,
112
115
  error: '',
113
- name: file.name
116
+ name: file.name,
117
+ deleteStatus: DeleteFileStatus.NONE
114
118
  });
115
119
  }
116
120
  else {
117
- fileInfoArray.push({ fileId: '', status: FileStatus.INIT, progress: 0, error: '', name: file.name });
121
+ fileInfoArray.push({
122
+ fileId: '',
123
+ docId: '',
124
+ status: FileStatus.INIT,
125
+ progress: 0,
126
+ error: '',
127
+ name: file.name,
128
+ deleteStatus: DeleteFileStatus.NONE
129
+ });
118
130
  }
119
131
  });
120
132
  fileControl.field.onChange(__spreadArray([], fileArray, true));
@@ -133,7 +145,8 @@ var UploadMultipleFile = function (_a) {
133
145
  fileInfoArray.splice(index, 1);
134
146
  fileInfoControl.field.onChange(__spreadArray([], fileInfoArray, true));
135
147
  var fileIds = fileInfoArray.filter(function (f) { return f.fileId; }).map(function (f) { return f.fileId; });
136
- onDeleteFile(fileIds);
148
+ var filteredFromDefaultFiles = fileIds.filter(function (id) { return !(defaultFiles || []).some(function (file) { return file.id === id; }); });
149
+ onDeleteFile(filteredFromDefaultFiles);
137
150
  }
138
151
  }
139
152
  };
@@ -163,7 +176,7 @@ var UploadMultipleFile = function (_a) {
163
176
  };
164
177
  var fileExists = fileInfoArray.length > 0;
165
178
  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) {
166
- return (_jsx(UploadFile, { purpose: purpose, title: fileTitle, uploadedFiles: fileInfoArray, index: index, file: file, sx: {
179
+ return (_jsx(UploadFile, { required: required, purpose: purpose, title: fileTitle, uploadedFiles: fileInfoArray, index: index, file: file, sx: {
167
180
  borderBottom: index === fileArray.length - 1 ? "1px solid ".concat(alpha(theme.palette.divider, 0.8)) : ''
168
181
  }, onSuccess: handleSuccess, onDelete: handleDelete, onFailure: handleFailure, onProgress: handleProgress }, index));
169
182
  }) }))] }));
@@ -17,7 +17,7 @@ import { useAppDispatch, useAppSelector } from '../../../../hooks';
17
17
  import { DocumentPurpose } from '../../../../@types';
18
18
  import { styled } from '@mui/material/styles';
19
19
  import Collapse from '../../../../components/Collapse';
20
- import { getRecentDocumentFiles } from '../../../../utils';
20
+ import { getFileDetailsFromDocument } from '../../../../utils';
21
21
  import { ScreenContainer } from '../../../shared/Containers';
22
22
  import { taxSelector, uploadingStatus } from '../../../app/tax/taxStore';
23
23
  import UploadMultipleFile from '../../../shared/UploadMultipleFile';
@@ -42,7 +42,7 @@ var TaxDocument = function (_a) {
42
42
  var handleReset = function (ids) {
43
43
  documentIdControl.field.onChange(ids);
44
44
  };
45
- var defaultFiles = React.useMemo(function () { return getRecentDocumentFiles(documents, DocumentPurpose.TAX_DOCUMENT); }, [documents]);
45
+ var defaultFiles = React.useMemo(function () { return getFileDetailsFromDocument(documents, DocumentPurpose.TAX_DOCUMENT); }, [documents]);
46
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
47
  };
48
48
  export default TaxDocument;
@@ -62,5 +62,6 @@ export declare const fixBrandList: (items: Array<{
62
62
  }[];
63
63
  export declare const findFirstId: (items: Array<SaleChannel>) => string;
64
64
  export declare const sortActivitiesByName: (items: Array<Activity>, path: string) => Activity[];
65
- export declare const getRecentDocumentFiles: (documents: Array<any>, purpose: string) => any;
65
+ export declare const getFileDetailsFromDocument: (documents: Array<any>, purpose: string) => any;
66
+ export declare const getRecentDocumentBasedOnPurpose: (documents: Array<any>, purpose: string) => any;
66
67
  export declare const findInArrayOrSubArray: (items: Array<any>, value: string | number) => null;
@@ -142,13 +142,21 @@ export var sortActivitiesByName = function (items, path) {
142
142
  return get(a, path).trim().toLowerCase().localeCompare(get(b, path).trim().toLowerCase().trim().toLowerCase());
143
143
  });
144
144
  };
145
- export var getRecentDocumentFiles = function (documents, purpose) {
146
- var _a;
147
- if ((documents === null || documents === void 0 ? void 0 : documents.length) === 0)
145
+ export var getFileDetailsFromDocument = function (documents, purpose) {
146
+ if ((documents || []).length === 0)
148
147
  return [];
149
- return (((_a = (documents || [])
150
- .filter(function (doc) { return (doc.file_details || []).find(function (file) { return file.purpose === purpose; }); })
151
- .sort(function (a, b) { return b.created - a.created; })[0]) === null || _a === void 0 ? void 0 : _a.file_details) || []);
148
+ return documents.reduce(function (acc, document) {
149
+ var fileDetails = (document.file_details || []).filter(function (file) { return file.purpose === purpose; });
150
+ return acc.concat(fileDetails.map(function (f) { return (__assign(__assign({}, f), { docId: document.id })); }));
151
+ }, []);
152
+ };
153
+ export var getRecentDocumentBasedOnPurpose = function (documents, purpose) {
154
+ if ((documents || []).length === 0)
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]);
152
160
  };
153
161
  export var findInArrayOrSubArray = function (items, value) {
154
162
  var found = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.3.2-test",
3
+ "version": "2.3.4-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",