@tap-payments/auth-jsconnect 2.1.40-test → 2.1.42-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 (40) hide show
  1. package/build/@types/form.d.ts +6 -3
  2. package/build/api/entity.d.ts +8 -0
  3. package/build/api/entity.js +15 -0
  4. package/build/api/index.d.ts +2 -6
  5. package/build/api/index.js +1 -3
  6. package/build/assets/locales/ar.json +1 -5
  7. package/build/assets/locales/en.json +1 -5
  8. package/build/components/FileInput/DragAndDrop.js +1 -1
  9. package/build/components/ProgressBar/CircularProgressBar.d.ts +1 -3
  10. package/build/components/ProgressBar/CircularProgressBar.js +2 -2
  11. package/build/constants/assets.d.ts +0 -1
  12. package/build/constants/assets.js +0 -1
  13. package/build/constants/validation.d.ts +0 -1
  14. package/build/constants/validation.js +0 -1
  15. package/build/features/app/bank/bankStore.js +1 -1
  16. package/build/features/app/business/businessStore.d.ts +9 -7
  17. package/build/features/app/business/businessStore.js +67 -29
  18. package/build/features/app/individual/individualStore.d.ts +16 -4
  19. package/build/features/app/individual/individualStore.js +89 -11
  20. package/build/features/business/screens/BusinessType/Article.js +13 -10
  21. package/build/features/business/screens/BusinessType/BusinessType.js +4 -2
  22. package/build/features/business/screens/BusinessType/LicenseCertificate.js +50 -12
  23. package/build/features/business/screens/BusinessType/validation.d.ts +6 -3
  24. package/build/features/business/screens/BusinessType/validation.js +11 -1
  25. package/build/features/individual/screens/AdditionalIndividualInfo/AdditionalIndividualInfo.js +4 -18
  26. package/build/features/individual/screens/AdditionalIndividualInfo/CivilIDFile.js +62 -11
  27. package/build/features/individual/screens/AdditionalIndividualInfo/SignatureFile.js +59 -11
  28. package/build/features/individual/screens/AdditionalIndividualInfo/validation.d.ts +12 -6
  29. package/build/features/individual/screens/AdditionalIndividualInfo/validation.js +23 -2
  30. package/build/features/shared/UploadFile/UploadFile.js +1 -1
  31. package/build/theme/typography.js +1 -1
  32. package/package.json +1 -1
  33. package/build/api/file.d.ts +0 -13
  34. package/build/api/file.js +0 -24
  35. package/build/features/shared/UploadMultipleFile/UploadFile.d.ts +0 -38
  36. package/build/features/shared/UploadMultipleFile/UploadFile.js +0 -184
  37. package/build/features/shared/UploadMultipleFile/UploadMultipleFile.d.ts +0 -27
  38. package/build/features/shared/UploadMultipleFile/UploadMultipleFile.js +0 -147
  39. package/build/features/shared/UploadMultipleFile/index.d.ts +0 -2
  40. package/build/features/shared/UploadMultipleFile/index.js +0 -2
@@ -285,10 +285,10 @@ export var updateIndividualInfo = createAsyncThunk('updateIndividualInfo', funct
285
285
  civilID = params.civilID, signatureFileId = params.signatureFileId;
286
286
  businessCountry = settings.data.businessCountry;
287
287
  documentsList = [];
288
- if ((civilID || []).length > 0)
289
- documentsList.push({ type: 'Civil ID File', images: civilID });
290
- if ((signatureFileId || []).length > 0)
291
- documentsList.push({ type: 'Signature File', images: signatureFileId });
288
+ if (!!civilID)
289
+ documentsList.push({ type: 'Civil ID File', images: [civilID] });
290
+ if (!!signatureFileId)
291
+ documentsList.push({ type: 'Signature File', images: [signatureFileId] });
292
292
  requestBody = {
293
293
  id: id,
294
294
  type: type,
@@ -321,6 +321,56 @@ export var updateIndividualInfo = createAsyncThunk('updateIndividualInfo', funct
321
321
  }
322
322
  });
323
323
  }); });
324
+ export var uploadCivilIdFile = createAsyncThunk('uploadCivilIdFile', function (_a) {
325
+ var file = _a.file, onProgress = _a.onProgress, title = _a.title;
326
+ return __awaiter(void 0, void 0, void 0, function () {
327
+ var uploadPayload, onUploadProgress, data;
328
+ return __generator(this, function (_b) {
329
+ switch (_b.label) {
330
+ case 0:
331
+ uploadPayload = {
332
+ file_link_create: false,
333
+ title: title,
334
+ purpose: 'identity_document',
335
+ file: file
336
+ };
337
+ onUploadProgress = function (progressEvent) {
338
+ var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
339
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(Math.floor(progress));
340
+ };
341
+ return [4, API.entityService.uploadFileInfo(uploadPayload, { onUploadProgress: onUploadProgress })];
342
+ case 1:
343
+ data = _b.sent();
344
+ return [2, { data: data, file: file }];
345
+ }
346
+ });
347
+ });
348
+ });
349
+ export var uploadSignatureFile = createAsyncThunk('uploadSignatureFile', function (_a) {
350
+ var file = _a.file, onProgress = _a.onProgress;
351
+ return __awaiter(void 0, void 0, void 0, function () {
352
+ var uploadPayload, onUploadProgress, data;
353
+ return __generator(this, function (_b) {
354
+ switch (_b.label) {
355
+ case 0:
356
+ uploadPayload = {
357
+ file_link_create: false,
358
+ title: 'Merchant Signature',
359
+ purpose: 'customer_signature',
360
+ file: file
361
+ };
362
+ onUploadProgress = function (progressEvent) {
363
+ var progress = ((progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.loaded) / (progressEvent === null || progressEvent === void 0 ? void 0 : progressEvent.total)) * 100;
364
+ onProgress === null || onProgress === void 0 ? void 0 : onProgress(Math.floor(progress));
365
+ };
366
+ return [4, API.entityService.uploadFileInfo(uploadPayload, { onUploadProgress: onUploadProgress })];
367
+ case 1:
368
+ data = _b.sent();
369
+ return [2, { data: data, file: file }];
370
+ }
371
+ });
372
+ });
373
+ });
324
374
  export var updateBoardSuccess = createAsyncThunk('individualUpdateBoardSuccess', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
325
375
  var _a, settings, individual, _b, id, infoId, payload, data, boardInfoStatus;
326
376
  var _c, _d, _e, _f;
@@ -371,6 +421,10 @@ var initialState = {
371
421
  employerLocation: undefined,
372
422
  isPEP: null,
373
423
  isInfluencer: null
424
+ },
425
+ attachmentsData: {
426
+ civilIDUploading: false,
427
+ signatureFileUploading: false
374
428
  }
375
429
  }
376
430
  };
@@ -386,12 +440,6 @@ export var individualSlice = createSlice({
386
440
  },
387
441
  resetOTPScreen: function (state) {
388
442
  state.data.otpData.otp = '';
389
- },
390
- civilIDUploadingStatus: function (state, action) {
391
- state.data.individualData.civilIDUploading = action.payload;
392
- },
393
- signatureFileUploadingStatus: function (state, action) {
394
- state.data.individualData.signatureFileUploading = action.payload;
395
443
  }
396
444
  },
397
445
  extraReducers: function (builder) {
@@ -542,6 +590,36 @@ export var individualSlice = createSlice({
542
590
  .addCase(retrieveBoardDetails.rejected, function (state, action) {
543
591
  state.error = action.error.message;
544
592
  state.loading = false;
593
+ })
594
+ .addCase(uploadCivilIdFile.pending, function (state) {
595
+ state.error = null;
596
+ state.data.attachmentsData.civilIDUploading = true;
597
+ })
598
+ .addCase(uploadCivilIdFile.fulfilled, function (state, action) {
599
+ state.error = null;
600
+ state.data.attachmentsData.civilIDUploading = false;
601
+ var _a = action.payload, data = _a.data, file = _a.file;
602
+ state.data.attachmentsData.civilID = data === null || data === void 0 ? void 0 : data.id;
603
+ state.data.attachmentsData.civilIDFile = file;
604
+ })
605
+ .addCase(uploadCivilIdFile.rejected, function (state) {
606
+ state.data.attachmentsData.civilIDUploading = false;
607
+ state.error = 'file_upload_error';
608
+ })
609
+ .addCase(uploadSignatureFile.pending, function (state) {
610
+ state.error = null;
611
+ state.data.attachmentsData.signatureFileUploading = true;
612
+ })
613
+ .addCase(uploadSignatureFile.fulfilled, function (state, action) {
614
+ state.error = null;
615
+ state.data.attachmentsData.signatureFileUploading = false;
616
+ var _a = action.payload, data = _a.data, file = _a.file;
617
+ state.data.attachmentsData.signatureFileId = data === null || data === void 0 ? void 0 : data.id;
618
+ state.data.attachmentsData.signatureFile = file;
619
+ })
620
+ .addCase(uploadSignatureFile.rejected, function (state) {
621
+ state.data.attachmentsData.signatureFileUploading = false;
622
+ state.error = 'file_upload_error';
545
623
  })
546
624
  .addCase(updateBoardSuccess.fulfilled, function (state, action) {
547
625
  var _a;
@@ -566,6 +644,6 @@ export var individualSlice = createSlice({
566
644
  });
567
645
  }
568
646
  });
569
- export var clearError = (_a = individualSlice.actions, _a.clearError), stopLoader = _a.stopLoader, resetOTPScreen = _a.resetOTPScreen, civilIDUploadingStatus = _a.civilIDUploadingStatus, signatureFileUploadingStatus = _a.signatureFileUploadingStatus;
647
+ export var clearError = (_a = individualSlice.actions, _a.clearError), stopLoader = _a.stopLoader, resetOTPScreen = _a.resetOTPScreen;
570
648
  export default individualSlice.reducer;
571
649
  export var individualSelector = function (state) { return state.individual; };
@@ -28,16 +28,17 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
28
28
  });
29
29
  });
30
30
  var Article = function (_a) {
31
+ var _b, _c;
31
32
  var show = _a.show;
32
- var _b = React.useState(), error = _b[0], setError = _b[1];
33
- var _c = React.useState(0), progress = _c[0], setProgress = _c[1];
33
+ var _d = React.useState(0), progress = _d[0], setProgress = _d[1];
34
34
  var t = useTranslation().t;
35
- var _d = useFormContext(), control = _d.control, setValue = _d.setValue;
35
+ var _e = useFormContext(), control = _e.control, setError = _e.setError, clearErrors = _e.clearErrors, setValue = _e.setValue;
36
36
  var articleFileControl = useController({ name: 'articleFile', control: control });
37
37
  var articleIdControl = useController({ name: 'articleId', control: control });
38
- var _e = useAppSelector(businessSelector), loading = _e.loading, uploadingArticle = _e.uploadingArticle, sysError = _e.uploadingArticleError, data = _e.data;
38
+ var _f = useAppSelector(businessSelector), loading = _f.loading, uploadingArticle = _f.uploadingArticle, sysError = _f.error, data = _f.data;
39
39
  var dispatch = useAppDispatch();
40
40
  var articleValue = articleFileControl.field.value;
41
+ var error = ((_b = articleFileControl.fieldState.error) === null || _b === void 0 ? void 0 : _b.message) || ((_c = articleIdControl.fieldState.error) === null || _c === void 0 ? void 0 : _c.message);
41
42
  var businessTypeData = data.businessTypeData;
42
43
  var articleFile = businessTypeData.articleFile, articleId = businessTypeData.articleId;
43
44
  React.useEffect(function () {
@@ -47,16 +48,15 @@ var Article = function (_a) {
47
48
  }
48
49
  }, [articleFile, articleId]);
49
50
  var handleArticleChange = function (files) {
50
- setError('');
51
51
  var file = files === null || files === void 0 ? void 0 : files[0];
52
52
  if (!file)
53
53
  return;
54
54
  if (!VALID_FILE_FORMATS.includes(file === null || file === void 0 ? void 0 : file.type)) {
55
- setError('file_not_supported_alert');
55
+ setError('articleFile', { message: 'file_not_supported_alert' });
56
56
  return;
57
57
  }
58
58
  if ((file === null || file === void 0 ? void 0 : file.size) > MAX_FILE_SIZE) {
59
- setError('file_size_alert');
59
+ setError('articleFile', { message: 'file_size_alert' });
60
60
  return;
61
61
  }
62
62
  articleFileControl.field.onChange(file);
@@ -75,13 +75,16 @@ var Article = function (_a) {
75
75
  };
76
76
  React.useEffect(function () {
77
77
  if (sysError === 'file_upload_error') {
78
- setError(sysError);
78
+ setError('articleId', { message: sysError });
79
79
  articleFileControl.field.onChange(undefined);
80
80
  setProgress(0);
81
81
  }
82
82
  }, [sysError]);
83
+ React.useEffect(function () {
84
+ if ((articleFileControl.formState.isValid || !!articleValue) && error != 'file_upload_error')
85
+ clearErrors();
86
+ }, [articleFileControl.formState.isValid, articleValue]);
83
87
  var fileName = articleValue ? maskFileName(articleValue === null || articleValue === void 0 ? void 0 : articleValue.name) : '';
84
- var errorValue = error || sysError || '';
85
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadFile, { label: t('title_article'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('article_of_association'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleArticleChange, isFileUploaded: !uploadingArticle && !!articleValue, isSubmitting: loading, isUploading: uploadingArticle, progress: progress, onReset: handleReset, error: errorValue && t(errorValue), initialFileName: fileName }) }) })));
88
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadFile, { label: t('title_article'), title: t('drag_and_drop'), subTitle: t('subtitle_drop'), dragDescription: t('article_of_association'), uploadingTitle: t('file_uploading_title'), successTitle: t('success_upload_bank_statement'), onFileUploaded: handleArticleChange, isFileUploaded: !uploadingArticle && !!articleValue, isSubmitting: loading, isUploading: uploadingArticle, progress: progress, onReset: handleReset, error: error && t(error), initialFileName: fileName }) }) })));
86
89
  };
87
90
  export default Article;
@@ -28,7 +28,7 @@ import LicenseList from './LicenseList';
28
28
  var BusinessType = function (_a) {
29
29
  var _b = useAppSelector(businessSelector), data = _b.data, loading = _b.loading, error = _b.error, uploading = _b.uploading, uploadingArticle = _b.uploadingArticle;
30
30
  var settingsData = useAppSelector(settingsSelector).data;
31
- var _c = data.businessTypeData, selectedLicense = _c.selectedLicense, licenseNumber = _c.licenseNumber, entityLegalName = _c.entityLegalName, certificateId = _c.certificateId, articleId = _c.articleId, articleFile = _c.articleFile;
31
+ var _c = data.businessTypeData, selectedLicense = _c.selectedLicense, licenseNumber = _c.licenseNumber, entityLegalName = _c.entityLegalName, certificateId = _c.certificateId, certificateFile = _c.certificateFile, articleId = _c.articleId, articleFile = _c.articleFile;
32
32
  var t = useTranslation().t;
33
33
  var isAr = useLanguage().isAr;
34
34
  var dispatch = useAppDispatch();
@@ -41,6 +41,7 @@ var BusinessType = function (_a) {
41
41
  licenseNumber: licenseNumber,
42
42
  entityLegalName: entityLegalName,
43
43
  certificateId: certificateId,
44
+ certificateFile: certificateFile,
44
45
  articleId: articleId,
45
46
  articleFile: articleFile
46
47
  },
@@ -56,7 +57,8 @@ var BusinessType = function (_a) {
56
57
  selectedLicense: data.selectedLicense,
57
58
  licenseNumber: data.licenseNumber,
58
59
  entityLegalName: data.entityLegalName,
59
- certificateId: data.certificateId
60
+ certificateId: data.certificateId,
61
+ certificateFile: data.certificateFile
60
62
  };
61
63
  dispatch(updateLeadBusinessType(dataValues));
62
64
  };
@@ -10,14 +10,16 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import React from 'react';
14
+ import { styled } from '@mui/material/styles';
15
+ import { ScreenContainer } from '../../../shared/Containers';
13
16
  import { useTranslation } from 'react-i18next';
14
17
  import { useController, useFormContext } from 'react-hook-form';
15
18
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
16
- import { styled } from '@mui/material/styles';
19
+ import { businessSelector, clearCertificateId, uploadLicenseCertificate } from '../../../app/business/businessStore';
20
+ import UploadFile from '../../../shared/UploadFile';
21
+ import { MAX_FILE_SIZE, VALID_FILE_FORMATS } from '../../../../constants';
17
22
  import Collapse from '../../../../components/Collapse';
18
- import { ScreenContainer } from '../../../shared/Containers';
19
- import { businessSelector, uploadingStatus } from '../../../app/business/businessStore';
20
- import UploadMultipleFile from '../../../shared/UploadMultipleFile';
21
23
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
22
24
  var theme = _a.theme;
23
25
  return ({
@@ -25,18 +27,54 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
25
27
  });
26
28
  });
27
29
  var LicenseCertificate = function (_a) {
30
+ var _b, _c;
28
31
  var show = _a.show;
32
+ var _d = React.useState(0), progress = _d[0], setProgress = _d[1];
29
33
  var t = useTranslation().t;
30
- var control = useFormContext().control;
31
- var dispatch = useAppDispatch();
34
+ var _e = useFormContext(), control = _e.control, setError = _e.setError, clearErrors = _e.clearErrors;
35
+ var certificateFileControl = useController({ name: 'certificateFile', control: control });
32
36
  var certificateIdControl = useController({ name: 'certificateId', control: control });
33
- var loading = useAppSelector(businessSelector).loading;
34
- var handleLicenseCertificateChange = function (ids) {
35
- certificateIdControl.field.onChange(ids);
37
+ var _f = useAppSelector(businessSelector), loading = _f.loading, uploading = _f.uploading, sysError = _f.error;
38
+ var dispatch = useAppDispatch();
39
+ var certificateValue = certificateFileControl.field.value;
40
+ var error = ((_b = certificateFileControl.fieldState.error) === null || _b === void 0 ? void 0 : _b.message) || ((_c = certificateIdControl.fieldState.error) === null || _c === void 0 ? void 0 : _c.message);
41
+ var handleLicenseCertificateChange = function (files) {
42
+ var file = (files || [])[0];
43
+ if (!file)
44
+ return;
45
+ if (!VALID_FILE_FORMATS.includes(file.type)) {
46
+ setError('certificateFile', { message: 'file_not_supported_alert' });
47
+ return;
48
+ }
49
+ if (file.size > MAX_FILE_SIZE) {
50
+ setError('certificateFile', { message: 'file_size_alert' });
51
+ return;
52
+ }
53
+ certificateFileControl.field.onChange(file);
54
+ dispatch(uploadLicenseCertificate({
55
+ file: file,
56
+ onProgress: function (value) {
57
+ setProgress(value);
58
+ }
59
+ }));
36
60
  };
37
- var handleReset = function (ids) {
38
- certificateIdControl.field.onChange(ids);
61
+ var handleReset = function () {
62
+ certificateFileControl.field.onChange(undefined);
63
+ certificateIdControl.field.onChange('');
64
+ dispatch(clearCertificateId());
65
+ setProgress(0);
39
66
  };
40
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { 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: 'commercial_registration', fileUploadingStatus: function (uploading) { return dispatch(uploadingStatus(uploading)); } }) }) })));
67
+ React.useEffect(function () {
68
+ if (sysError === 'file_upload_error') {
69
+ setError('certificateId', { message: sysError });
70
+ certificateFileControl.field.onChange(undefined);
71
+ setProgress(0);
72
+ }
73
+ }, [sysError]);
74
+ React.useEffect(function () {
75
+ if ((certificateFileControl.formState.isValid || !!certificateValue) && error != 'file_upload_error')
76
+ clearErrors();
77
+ }, [certificateFileControl.formState.isValid, certificateValue]);
78
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadFile, { 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, isFileUploaded: !uploading && !!certificateValue, isSubmitting: loading, isUploading: uploading, progress: progress, onReset: handleReset, error: error && t(error) }) }) })));
41
79
  };
42
80
  export default LicenseCertificate;
@@ -13,21 +13,24 @@ export declare const KWLicenseValidationSchema: yup.ObjectSchema<import("yup/lib
13
13
  selectedLicense: any;
14
14
  licenseNumber: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
15
15
  entityLegalName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
16
- certificateId: yup.ArraySchema<yup.AnySchema<any, any, any>, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
16
+ certificateId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
17
+ certificateFile: any;
17
18
  articleId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
18
19
  articleFile: any;
19
20
  }>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
20
21
  selectedLicense: any;
21
22
  licenseNumber: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
22
23
  entityLegalName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
23
- certificateId: yup.ArraySchema<yup.AnySchema<any, any, any>, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
24
+ certificateId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
25
+ certificateFile: any;
24
26
  articleId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
25
27
  articleFile: any;
26
28
  }>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
27
29
  selectedLicense: any;
28
30
  licenseNumber: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
29
31
  entityLegalName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
30
- certificateId: yup.ArraySchema<yup.AnySchema<any, any, any>, import("yup/lib/types").AnyObject, any[] | undefined, any[] | undefined>;
32
+ certificateId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
33
+ certificateFile: any;
31
34
  articleId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
32
35
  articleFile: any;
33
36
  }>>>;
@@ -74,7 +74,17 @@ export var KWLicenseValidationSchema = yup.object().shape({
74
74
  });
75
75
  })
76
76
  .required(''),
77
- certificateId: yup.array().optional(),
77
+ certificateId: yup.string().optional(),
78
+ certificateFile: yup
79
+ .mixed()
80
+ .test({
81
+ test: function (value) {
82
+ if (!!value)
83
+ return VALID_FILE_FORMATS.includes(value === null || value === void 0 ? void 0 : value.type) && (value === null || value === void 0 ? void 0 : value.size) < MAX_FILE_SIZE ? true : this.createError({ message: 'alert_file_upload' });
84
+ return true;
85
+ }
86
+ })
87
+ .optional(),
78
88
  articleId: yup.string().optional(),
79
89
  articleFile: yup
80
90
  .mixed()
@@ -48,27 +48,14 @@ var AdditionalIndividualInfo = function (_a) {
48
48
  var settingsData = useAppSelector(settingsSelector).data;
49
49
  var countries = settingsData.countries;
50
50
  var user = (data.verify.responseBody || {}).user;
51
- var _c = data.individualData, occupation = _c.occupation, sourceIncome = _c.sourceIncome, monthlyIncome = _c.monthlyIncome, employerName = _c.employerName, employerLocation = _c.employerLocation, isPEP = _c.isPEP, isInfluencer = _c.isInfluencer, civilID = _c.civilID, signatureFileId = _c.signatureFileId, civilIDUploading = _c.civilIDUploading, signatureFileUploading = _c.signatureFileUploading;
52
51
  var methods = useForm({
53
52
  resolver: yupResolver(IndividualInfoValidationSchema),
54
- defaultValues: {
55
- occupation: occupation,
56
- sourceIncome: sourceIncome,
57
- monthlyIncome: monthlyIncome,
58
- employerName: employerName,
59
- employerLocation: employerLocation,
60
- isPEP: isPEP,
61
- isInfluencer: isInfluencer,
62
- civilID: civilID,
63
- signatureFileId: signatureFileId,
64
- civilIDUploading: civilIDUploading,
65
- signatureFileUploading: signatureFileUploading
66
- },
53
+ defaultValues: data.individualData,
67
54
  mode: 'onChange'
68
55
  });
69
56
  useSetFromDefaultValues(methods, data.individualData, true);
70
- var _d = React.useState(), listActive = _d[0], setListActive = _d[1];
71
- var _e = React.useState(false), employerFieldsActive = _e[0], setEmployerFieldsActive = _e[1];
57
+ var _c = React.useState(), listActive = _c[0], setListActive = _c[1];
58
+ var _d = React.useState(false), employerFieldsActive = _d[0], setEmployerFieldsActive = _d[1];
72
59
  React.useEffect(function () {
73
60
  var _a, _b;
74
61
  if (((_b = (_a = methods.getValues('sourceIncome')) === null || _a === void 0 ? void 0 : _a.name.en) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'salary')
@@ -89,8 +76,7 @@ var AdditionalIndividualInfo = function (_a) {
89
76
  var isEmployerLocationListActive = listActive === ListType.EmployerLocationList;
90
77
  var isMonthlyIncomeListActive = listActive === ListType.MonthlyIncomeList;
91
78
  var isOccupationListActive = listActive === ListType.OccupationList;
92
- var disabled = !methods.formState.isValid || civilIDUploading || signatureFileUploading;
93
- return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(Form, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsxs(Box, { children: [_jsx(Occupation, { onListOpen: function () { return handleMenuClick(ListType.OccupationList); }, onListClose: function () { return handleMenuClick(); }, show: !isEmployerLocationListActive && !isMonthlyIncomeListActive && !isSourceOfIncomeListActive }), _jsx(SourceOfIncome, { onListOpen: function () { return handleMenuClick(ListType.SourceOfIncomeList); }, onListClose: function () { return handleMenuClick(); }, show: !isEmployerLocationListActive && !isMonthlyIncomeListActive && !isOccupationListActive }), _jsx(MonthlyIncome, { show: !isEmployerLocationListActive && !isSourceOfIncomeListActive && !isOccupationListActive, onListOpen: function () { return handleMenuClick(ListType.MonthlyIncomeList); }, onListClose: function () { return handleMenuClick(); } }), _jsx(EmployerName, { show: false }), _jsx(EmployerLocation, { show: !isSourceOfIncomeListActive && employerFieldsActive && !isMonthlyIncomeListActive && !isOccupationListActive, countries: countries, onListOpen: function () { return handleMenuClick(ListType.EmployerLocationList); }, onListClose: function () { return handleMenuClick(); } }), _jsxs(Collapse, __assign({ in: !listActive, timeout: 500 }, { children: [_jsx(CivilIDFile, {}), _jsx(SignatureFile, { show: user === null || user === void 0 ? void 0 : user.is_authorized })] })), _jsx(PEPSwitch, { show: !listActive }), _jsx(InfluencerSwitch, { show: !listActive })] }), _jsx(Collapse, __assign({ in: !listActive, timeout: 500 }, { children: _jsx(Button, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disableBack: true, disabled: disabled, loading: loading, error: t(error || '') }, { children: t('next') })) }))] })) })) }));
79
+ return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(Form, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsxs(Box, { children: [_jsx(Occupation, { onListOpen: function () { return handleMenuClick(ListType.OccupationList); }, onListClose: function () { return handleMenuClick(); }, show: !isEmployerLocationListActive && !isMonthlyIncomeListActive && !isSourceOfIncomeListActive }), _jsx(SourceOfIncome, { onListOpen: function () { return handleMenuClick(ListType.SourceOfIncomeList); }, onListClose: function () { return handleMenuClick(); }, show: !isEmployerLocationListActive && !isMonthlyIncomeListActive && !isOccupationListActive }), _jsx(MonthlyIncome, { show: !isEmployerLocationListActive && !isSourceOfIncomeListActive && !isOccupationListActive, onListOpen: function () { return handleMenuClick(ListType.MonthlyIncomeList); }, onListClose: function () { return handleMenuClick(); } }), _jsx(EmployerName, { show: false }), _jsx(EmployerLocation, { show: !isSourceOfIncomeListActive && employerFieldsActive && !isMonthlyIncomeListActive && !isOccupationListActive, countries: countries, onListOpen: function () { return handleMenuClick(ListType.EmployerLocationList); }, onListClose: function () { return handleMenuClick(); } }), _jsxs(Collapse, __assign({ in: !listActive, timeout: 500 }, { children: [_jsx(CivilIDFile, {}), _jsx(SignatureFile, { show: user === null || user === void 0 ? void 0 : user.is_authorized })] })), _jsx(PEPSwitch, { show: !listActive }), _jsx(InfluencerSwitch, { show: !listActive })] }), _jsx(Collapse, __assign({ in: !listActive, timeout: 500 }, { children: _jsx(Button, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disableBack: true, disabled: !methods.formState.isValid, loading: loading, error: t(error || '') }, { children: t('next') })) }))] })) })) }));
94
80
  };
95
81
  export default React.memo(AdditionalIndividualInfo);
96
82
  AdditionalIndividualInfo.defaultProps = {};
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React from 'react';
2
3
  import { ScreenContainer } from '../../../../features/shared/Containers';
3
4
  import { styled } from '@mui/material/styles';
4
5
  import { useTranslation } from 'react-i18next';
5
6
  import { useController, useFormContext } from 'react-hook-form';
6
7
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
7
- import { civilIDUploadingStatus, individualSelector } from '../../../app/individual/individualStore';
8
- import UploadMultipleFile from '../../../shared/UploadMultipleFile';
8
+ import { individualSelector, uploadCivilIdFile } from '../../../../features/app/individual/individualStore';
9
+ import { MAX_FILE_SIZE, VALID_FILE_FORMATS } from '../../../../constants';
10
+ import UploadFile from '../../../../features/shared/UploadFile';
11
+ import { maskFileName } from '../../../../utils';
9
12
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
10
13
  var theme = _a.theme;
11
14
  return ({
@@ -13,18 +16,66 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
13
16
  });
14
17
  });
15
18
  var CivilIDFile = function () {
16
- var _a;
19
+ var _a, _b;
20
+ var _c = React.useState(0), progress = _c[0], setProgress = _c[1];
17
21
  var t = useTranslation().t;
18
- var dispatch = useAppDispatch();
19
- var control = useFormContext().control;
22
+ var _d = useFormContext(), control = _d.control, setError = _d.setError, clearErrors = _d.clearErrors, setValue = _d.setValue;
23
+ var civilIDFileControl = useController({ name: 'civilIDFile', control: control });
20
24
  var civilIDFileIdControl = useController({ name: 'civilID', control: control });
21
- var _b = useAppSelector(individualSelector), loading = _b.loading, data = _b.data;
22
- var handleCivilIDChange = function (ids) {
23
- civilIDFileIdControl.field.onChange(ids);
25
+ var _e = useAppSelector(individualSelector), data = _e.data, loading = _e.loading, sysError = _e.error;
26
+ var _f = data.attachmentsData, civilIDUploading = _f.civilIDUploading, civilIDFile = _f.civilIDFile, civilID = _f.civilID;
27
+ var dispatch = useAppDispatch();
28
+ var civilIDValue = civilIDFileControl.field.value;
29
+ var error = ((_a = civilIDFileControl.fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || ((_b = civilIDFileIdControl.fieldState.error) === null || _b === void 0 ? void 0 : _b.message);
30
+ var handleCivilIDChange = function (files) {
31
+ var _a;
32
+ var file = files === null || files === void 0 ? void 0 : files[0];
33
+ if (!VALID_FILE_FORMATS.includes(file === null || file === void 0 ? void 0 : file.type)) {
34
+ setError('civilIDFile', { message: 'file_not_supported_alert' });
35
+ }
36
+ else if ((file === null || file === void 0 ? void 0 : file.size) > MAX_FILE_SIZE) {
37
+ setError('civilIDFile', { message: 'file_size_alert' });
38
+ }
39
+ else {
40
+ civilIDFileControl.field.onChange(file);
41
+ dispatch(uploadCivilIdFile({
42
+ file: file,
43
+ onProgress: function (value) {
44
+ setProgress(value);
45
+ },
46
+ title: (_a = data.verify.responseBody) === null || _a === void 0 ? void 0 : _a.merchant_id
47
+ }));
48
+ }
24
49
  };
25
- var handleReset = function (ids) {
26
- civilIDFileIdControl.field.onChange(ids);
50
+ var handleReset = function () {
51
+ civilIDFileControl.field.onChange(null);
52
+ civilIDFileIdControl.field.onChange('');
53
+ setProgress(0);
27
54
  };
28
- return (_jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { 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, fileTitle: (_a = data.verify.responseBody) === null || _a === void 0 ? void 0 : _a.merchant_id, purpose: 'identity_document', fileUploadingStatus: function (uploading) { return dispatch(civilIDUploadingStatus(uploading)); } }) }));
55
+ React.useEffect(function () {
56
+ if (!!civilIDFile) {
57
+ setValue('civilIDFile', civilIDFile);
58
+ setValue('civilID', civilID);
59
+ }
60
+ }, [civilIDFile, civilID]);
61
+ React.useEffect(function () {
62
+ if (sysError === 'file_upload_error') {
63
+ setError('civilIDFileId', { message: sysError });
64
+ civilIDFileControl.field.onChange(null);
65
+ setProgress(0);
66
+ }
67
+ }, [sysError]);
68
+ React.useEffect(function () {
69
+ if ((civilIDFileControl.formState.isValid || !!civilIDValue) && error != 'file_upload_error')
70
+ clearErrors();
71
+ }, [civilIDFileControl.formState.isValid, civilIDValue]);
72
+ React.useEffect(function () {
73
+ if (!!civilIDFile) {
74
+ civilIDFileControl.field.onChange(civilIDFile);
75
+ civilIDFileIdControl.field.onChange(civilID);
76
+ }
77
+ }, []);
78
+ var fileName = civilIDValue ? maskFileName(civilIDValue === null || civilIDValue === void 0 ? void 0 : civilIDValue.name) : '';
79
+ return (_jsx(FeatureStyled, { children: _jsx(UploadFile, { 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, isFileUploaded: !civilIDUploading && !!civilIDValue, isSubmitting: loading, isUploading: civilIDUploading, progress: progress, onReset: handleReset, initialFileName: fileName, error: error && t(error) }) }));
29
80
  };
30
81
  export default CivilIDFile;
@@ -10,14 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
+ import React from 'react';
14
+ import { ScreenContainer } from '../../../../features/shared/Containers';
15
+ import { styled } from '@mui/material/styles';
13
16
  import { useTranslation } from 'react-i18next';
14
17
  import { useController, useFormContext } from 'react-hook-form';
15
- import { styled } from '@mui/material/styles';
16
18
  import { useAppDispatch, useAppSelector } from '../../../../hooks';
17
- import UploadMultipleFile from '../../../shared/UploadMultipleFile';
18
- import { ScreenContainer } from '../../../shared/Containers';
19
- import { individualSelector, signatureFileUploadingStatus } from '../../../app/individual/individualStore';
19
+ import { individualSelector, uploadSignatureFile } from '../../../../features/app/individual/individualStore';
20
+ import { MAX_FILE_SIZE, VALID_FILE_FORMATS } from '../../../../constants';
21
+ import UploadFile from '../../../../features/shared/UploadFile';
20
22
  import Collapse from '../../../../components/Collapse';
23
+ import { maskFileName } from '../../../../utils';
21
24
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
22
25
  var theme = _a.theme;
23
26
  return ({
@@ -25,18 +28,63 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
25
28
  });
26
29
  });
27
30
  var SignatureFile = function (_a) {
31
+ var _b, _c;
28
32
  var show = _a.show;
33
+ var _d = React.useState(0), progress = _d[0], setProgress = _d[1];
29
34
  var t = useTranslation().t;
30
- var control = useFormContext().control;
35
+ var _e = useFormContext(), control = _e.control, setError = _e.setError, clearErrors = _e.clearErrors, setValue = _e.setValue;
36
+ var signatureFileControl = useController({ name: 'signatureFile', control: control });
31
37
  var signatureFileIdControl = useController({ name: 'signatureFileId', control: control });
32
- var loading = useAppSelector(individualSelector).loading;
38
+ var _f = useAppSelector(individualSelector), data = _f.data, loading = _f.loading, sysError = _f.error;
39
+ var _g = data.attachmentsData, signatureFileUploading = _g.signatureFileUploading, signatureFile = _g.signatureFile, signatureFileId = _g.signatureFileId;
33
40
  var dispatch = useAppDispatch();
34
- var handleSignatureChange = function (ids) {
35
- signatureFileIdControl.field.onChange(ids);
41
+ var signatureValue = signatureFileControl.field.value;
42
+ var error = ((_b = signatureFileControl.fieldState.error) === null || _b === void 0 ? void 0 : _b.message) || ((_c = signatureFileIdControl.fieldState.error) === null || _c === void 0 ? void 0 : _c.message);
43
+ var handleSignatureChange = function (files) {
44
+ var file = files === null || files === void 0 ? void 0 : files[0];
45
+ if (!VALID_FILE_FORMATS.includes(file === null || file === void 0 ? void 0 : file.type)) {
46
+ setError('signatureFile', { message: 'file_not_supported_alert' });
47
+ }
48
+ else if ((file === null || file === void 0 ? void 0 : file.size) > MAX_FILE_SIZE) {
49
+ setError('signatureFile', { message: 'file_size_alert' });
50
+ }
51
+ else {
52
+ signatureFileControl.field.onChange(file);
53
+ dispatch(uploadSignatureFile({
54
+ file: file,
55
+ onProgress: function (value) {
56
+ setProgress(value);
57
+ }
58
+ }));
59
+ }
36
60
  };
37
- var handleReset = function (ids) {
38
- signatureFileIdControl.field.onChange(ids);
61
+ var handleReset = function () {
62
+ signatureFileControl.field.onChange(null);
63
+ signatureFileIdControl.field.onChange('');
64
+ setProgress(0);
39
65
  };
40
- return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadMultipleFile, { 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, purpose: 'customer_signature', fileTitle: 'Merchant Signature', fileUploadingStatus: function (uploading) { return dispatch(signatureFileUploadingStatus(uploading)); } }) }) })));
66
+ React.useEffect(function () {
67
+ if (sysError === 'file_upload_error') {
68
+ setError('signatureFileId', { message: sysError });
69
+ signatureFileControl.field.onChange(null);
70
+ setProgress(0);
71
+ }
72
+ }, [sysError]);
73
+ React.useEffect(function () {
74
+ if ((signatureFileControl.formState.isValid || !!signatureValue) && error != 'file_upload_error')
75
+ clearErrors();
76
+ }, [signatureFileControl.formState.isValid, signatureValue]);
77
+ React.useEffect(function () {
78
+ if (!!signatureFile) {
79
+ setValue('signatureFile', signatureFile);
80
+ setValue('signatureFileId', signatureFileId);
81
+ }
82
+ }, [signatureFile, signatureFileId]);
83
+ React.useEffect(function () {
84
+ if (!!signatureValue)
85
+ signatureFileControl.field.onChange(signatureFile);
86
+ }, []);
87
+ var fileName = signatureValue ? maskFileName(signatureValue === null || signatureValue === void 0 ? void 0 : signatureValue.name) : '';
88
+ return (_jsx(Collapse, __assign({ in: show }, { children: _jsx(FeatureStyled, { children: _jsx(UploadFile, { 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, isFileUploaded: !signatureFileUploading && !!signatureValue, isSubmitting: loading, initialFileName: fileName, isUploading: signatureFileUploading, progress: progress, onReset: handleReset, error: error && t(error) }) }) })));
41
89
  };
42
90
  export default SignatureFile;