@tap-payments/auth-jsconnect 1.1.4-test → 1.1.5-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.
@@ -50,6 +50,7 @@ export declare type BankFormValues = {
50
50
  beneficiaryName: string;
51
51
  bankName: string;
52
52
  bankStatementId?: string;
53
+ bankStatementFile?: File;
53
54
  uploading?: boolean;
54
55
  confirmPolicy: boolean;
55
56
  };
@@ -39,7 +39,7 @@ export declare type EntityBankUpdateBody = {
39
39
  };
40
40
  export declare type UploadFileBody = {
41
41
  file_link_create: boolean;
42
- file: File | null;
42
+ file?: File;
43
43
  title: string | undefined;
44
44
  purpose: string;
45
45
  };
@@ -29,7 +29,6 @@ var DragAndDrop = function (_a) {
29
29
  noKeyboard: true,
30
30
  noClick: true,
31
31
  multiple: false,
32
- accept: { 'image/jpeg': ['.jpeg'], 'image/png': ['.png'], 'image/jpg': ['.jpg'], 'application/pdf': ['.pdf'] },
33
32
  onDrop: function (files) {
34
33
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(files === null || files === void 0 ? void 0 : files[0]);
35
34
  }
@@ -6,6 +6,7 @@ export declare const FL_NUMBER_LENGTH = 8;
6
6
  export declare const CR_NUMBER_LENGTH = 10;
7
7
  export declare const SAUDI_NUMBER_LENGTH = 9;
8
8
  export declare const MAX_FILE_SIZE = 1000000;
9
+ export declare const VALID_FILE_FORMATS: string[];
9
10
  export declare const REGEX_FULL_NAME: RegExp;
10
11
  export declare const REGEX_WEBSITE: RegExp;
11
12
  export declare const REGEX_BENEFICIARY_NAME: RegExp;
@@ -6,6 +6,7 @@ export var FL_NUMBER_LENGTH = 8;
6
6
  export var CR_NUMBER_LENGTH = 10;
7
7
  export var SAUDI_NUMBER_LENGTH = 9;
8
8
  export var MAX_FILE_SIZE = 1000000;
9
+ export var VALID_FILE_FORMATS = ['image/jpeg', 'image/png', 'image/jpg', 'application/pdf'];
9
10
  export var REGEX_FULL_NAME = /^([a-zA-Z]{2,}\s{1}[a-zA-Z]{1,}|[a-zA-Z]+\s{1}[a-zA-Z.-]{1,}\s{1}[a-zA-Z.-]{1,}\s{1}[a-zA-Z]{1,}|[a-zA-Z]+\s{1}[a-zA-Z.-]{1,}\s{1}[a-zA-Z]{1,})$/g;
10
11
  export var REGEX_WEBSITE = /^[a-zA-Z0-9]+([\-\.]{1}[a-zA-Z0-9]+)*\.[a-zA-Z]{2,63}(:[0-9]{1,5})?(\/.*)?$/;
11
12
  export var REGEX_BENEFICIARY_NAME = /^([\u0600-\u065F\u066A-\u06EF\u06FA-\u06FFa-zA-Z\s])*$/g;
@@ -20,7 +20,6 @@ export declare const createBankAccount: import("@reduxjs/toolkit").AsyncThunk<{
20
20
  data: any;
21
21
  formData: BankFormValues;
22
22
  }, BankFormValues, {}>;
23
- export declare const uploadBankStatement: import("@reduxjs/toolkit").AsyncThunk<any, File, {}>;
24
23
  export declare const checkIbanBank: import("@reduxjs/toolkit").AsyncThunk<{
25
24
  data: any;
26
25
  }, {
@@ -154,56 +154,51 @@ export var retrieveEntityInfo = createAsyncThunk('retrieveBankEntityInfo', funct
154
154
  });
155
155
  }); });
156
156
  export var createBankAccount = createAsyncThunk('createBankAccount', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
157
- var _a, settings, bank, iban, beneficiaryName, bank_name, requestBody, data;
158
- var _b, _c, _d, _e;
159
- return __generator(this, function (_f) {
160
- switch (_f.label) {
157
+ var _a, settings, bank, iban, beneficiaryName, bank_name, fileResponse, uploadPayload, requestBody, data;
158
+ var _b, _c, _d, _e, _f;
159
+ return __generator(this, function (_g) {
160
+ switch (_g.label) {
161
161
  case 0:
162
162
  _a = thunkApi.getState(), settings = _a.settings, bank = _a.bank;
163
163
  iban = params.iban;
164
164
  beneficiaryName = params.beneficiaryName;
165
165
  bank_name = params.bankName;
166
+ fileResponse = undefined;
167
+ uploadPayload = {
168
+ file_link_create: true,
169
+ title: (_b = params.bankStatementFile) === null || _b === void 0 ? void 0 : _b.name,
170
+ purpose: 'identity_document',
171
+ file: params.bankStatementFile
172
+ };
173
+ if (!params.bankStatementFile) return [3, 2];
174
+ return [4, API.entityService.uploadFileInfo(uploadPayload)];
175
+ case 1:
176
+ fileResponse = _g.sent();
177
+ _g.label = 2;
178
+ case 2:
166
179
  requestBody = {
167
- wallet_id: (_c = (_b = bank.data.verify.responseBody) === null || _b === void 0 ? void 0 : _b.merchant) === null || _c === void 0 ? void 0 : _c.wallet_id,
180
+ wallet_id: (_d = (_c = bank.data.verify.responseBody) === null || _c === void 0 ? void 0 : _c.merchant) === null || _d === void 0 ? void 0 : _d.wallet_id,
168
181
  bank_account: {
169
182
  iban: iban,
170
183
  beneficiary_name: beneficiaryName,
171
184
  bank_name: bank_name,
172
- bank_statement_file_id: params.bankStatementId,
185
+ bank_statement_file_id: fileResponse === null || fileResponse === void 0 ? void 0 : fileResponse.id,
173
186
  is_acknowledged: params.confirmPolicy
174
187
  },
175
188
  step_name: BANK_STEP_NAMES.BANK_INFO,
176
189
  encryption_contract: ['bank_account.iban', 'bank_account.beneficiary_name', 'bank_account.bank_name']
177
190
  };
178
191
  return [4, API.entityService.createBankAccount(requestBody)];
179
- case 1:
180
- data = (_f.sent()).data;
192
+ case 3:
193
+ data = (_g.sent()).data;
181
194
  if (!data.errors) {
182
195
  thunkApi.dispatch(handleNextScreenStep());
183
- (_e = (_d = settings.data.appConfig).onStepCompleted) === null || _e === void 0 ? void 0 : _e.call(_d, settings.data.activeScreen.name, requestBody);
196
+ (_f = (_e = settings.data.appConfig).onStepCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, settings.data.activeScreen.name, requestBody);
184
197
  }
185
198
  return [2, { data: data, formData: params }];
186
199
  }
187
200
  });
188
201
  }); });
189
- export var uploadBankStatement = createAsyncThunk('uploadBankStatement', function (file, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
190
- var requestBody, data;
191
- return __generator(this, function (_a) {
192
- switch (_a.label) {
193
- case 0:
194
- requestBody = {
195
- file_link_create: true,
196
- title: file === null || file === void 0 ? void 0 : file.name,
197
- purpose: 'identity_document',
198
- file: file
199
- };
200
- return [4, API.entityService.uploadFileInfo(requestBody)];
201
- case 1:
202
- data = _a.sent();
203
- return [2, data];
204
- }
205
- });
206
- }); });
207
202
  export var checkIbanBank = createAsyncThunk('checkIbanBank', function (_a) {
208
203
  var iban = _a.iban, cancelToken = _a.cancelToken, onSuccess = _a.onSuccess;
209
204
  return __awaiter(void 0, void 0, void 0, function () {
@@ -424,20 +419,6 @@ export var bankSlice = createSlice({
424
419
  if (action.error.message === 'Aborted')
425
420
  return;
426
421
  state.error = action.error.message;
427
- })
428
- .addCase(uploadBankStatement.pending, function (state) {
429
- state.data.bankData.uploading = true;
430
- state.error = null;
431
- })
432
- .addCase(uploadBankStatement.fulfilled, function (state, action) {
433
- state.data.bankData.uploading = false;
434
- state.error = null;
435
- var id = action.payload.id;
436
- state.data.bankData.responseBody = { fileId: id };
437
- })
438
- .addCase(uploadBankStatement.rejected, function (state, action) {
439
- state.data.bankData.uploading = false;
440
- state.error = action.error.message;
441
422
  });
442
423
  }
443
424
  });
@@ -1,12 +1,9 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
2
  import { styled } from '@mui/material/styles';
4
3
  import { ScreenContainer } from '../../../../features/shared/Containers';
5
4
  import { useTranslation } from 'react-i18next';
6
5
  import { useController, useFormContext } from 'react-hook-form';
7
6
  import UploadFile from '../../../../features/shared/UploadFile';
8
- import { useAppDispatch, useAppSelector } from '../../../../hooks';
9
- import { bankSelector, uploadBankStatement } from '../../../../features/app/bank/bankStore';
10
7
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
11
8
  var theme = _a.theme;
12
9
  return ({
@@ -14,25 +11,17 @@ var FeatureStyled = styled(ScreenContainer)(function (_a) {
14
11
  });
15
12
  });
16
13
  var BankStatement = function () {
17
- var _a, _b;
18
- var dispatch = useAppDispatch();
19
- var data = useAppSelector(bankSelector).data;
14
+ var _a;
20
15
  var t = useTranslation().t;
21
16
  var control = useFormContext().control;
22
- var bankStatementControl = useController({ name: 'bankStatementId', control: control });
23
- var error = (_a = bankStatementControl.fieldState.error) === null || _a === void 0 ? void 0 : _a.message;
24
- var uploading = data.bankData.uploading;
17
+ var bankStatementFileControl = useController({ name: 'bankStatementFile', control: control });
18
+ var error = (_a = bankStatementFileControl.fieldState.error) === null || _a === void 0 ? void 0 : _a.message;
25
19
  var handleBankStatementChange = function (file) {
26
- dispatch(uploadBankStatement(file));
20
+ bankStatementFileControl.field.onChange(file);
27
21
  };
28
22
  var handleReset = function () {
29
- bankStatementControl.field.onChange('');
23
+ bankStatementFileControl.field.onChange(null);
30
24
  };
31
- React.useEffect(function () {
32
- var _a, _b;
33
- if ((_a = data.bankData.responseBody) === null || _a === void 0 ? void 0 : _a.fileId)
34
- bankStatementControl.field.onChange((_b = data.bankData.responseBody) === null || _b === void 0 ? void 0 : _b.fileId);
35
- }, [(_b = data.bankData.responseBody) === null || _b === void 0 ? void 0 : _b.fileId]);
36
- return (_jsx(FeatureStyled, { children: _jsx(UploadFile, { label: t('title_bank_statement'), dragTitle: t('drag_and_drop'), uploadTitle: t('title_upload_file'), onFileUploaded: handleBankStatementChange, loading: uploading, onReset: handleReset, error: error && t(error) }) }));
25
+ return (_jsx(FeatureStyled, { children: _jsx(UploadFile, { label: t('title_bank_statement'), dragTitle: t('drag_and_drop'), uploadTitle: t('title_upload_file'), onFileUploaded: handleBankStatementChange, isSubmitting: bankStatementFileControl.formState.isSubmitted, onReset: handleReset, error: error && t(error) }) }));
37
26
  };
38
27
  export default BankStatement;
@@ -4,17 +4,20 @@ export declare const BankValidation: yup.ObjectSchema<import("yup/lib/object").A
4
4
  bankName: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
5
5
  beneficiaryName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
6
6
  bankStatementId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
7
+ bankStatementFile: any;
7
8
  confirmPolicy: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, true>;
8
9
  }>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
9
10
  iban: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
10
11
  bankName: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
11
12
  beneficiaryName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
12
13
  bankStatementId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
14
+ bankStatementFile: any;
13
15
  confirmPolicy: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, true>;
14
16
  }>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
15
17
  iban: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
16
18
  bankName: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
17
19
  beneficiaryName: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
18
20
  bankStatementId: yup.StringSchema<string | undefined, import("yup/lib/types").AnyObject, string | undefined>;
21
+ bankStatementFile: any;
19
22
  confirmPolicy: yup.BooleanSchema<boolean | undefined, import("yup/lib/types").AnyObject, true>;
20
23
  }>>>;
@@ -1,4 +1,4 @@
1
- import { REGEX_BENEFICIARY_NAME } from '../../../../constants';
1
+ import { REGEX_BENEFICIARY_NAME, VALID_FILE_FORMATS } from '../../../../constants';
2
2
  import * as yup from 'yup';
3
3
  export var BankValidation = yup.object().shape({
4
4
  iban: yup
@@ -13,5 +13,15 @@ export var BankValidation = yup.object().shape({
13
13
  .matches(REGEX_BENEFICIARY_NAME, 'beneficiary_name_invalid')
14
14
  .required('beneficiary_name_required'),
15
15
  bankStatementId: yup.string().optional(),
16
+ bankStatementFile: yup
17
+ .mixed()
18
+ .test({
19
+ test: function (value) {
20
+ if (!!value)
21
+ return VALID_FILE_FORMATS.includes(value === null || value === void 0 ? void 0 : value.type) ? true : this.createError({ message: 'alert_file_upload' });
22
+ return true;
23
+ }
24
+ })
25
+ .optional(),
16
26
  confirmPolicy: yup.boolean().required('alert_bank_confirm').isTrue('alert_bank_confirm')
17
27
  });
@@ -13,9 +13,9 @@ interface UploadFileProps {
13
13
  dragTitle: string;
14
14
  uploadTitle: string;
15
15
  error?: string;
16
- loading?: boolean;
16
+ isSubmitting?: boolean;
17
17
  onFileUploaded: (file: File) => void;
18
18
  onReset: () => void;
19
19
  }
20
- declare const UploadFile: ({ label, required, dragTitle, uploadTitle, loading, error, onFileUploaded, onReset }: UploadFileProps) => JSX.Element;
20
+ declare const UploadFile: ({ label, required, dragTitle, uploadTitle, isSubmitting, error, onFileUploaded, onReset }: UploadFileProps) => JSX.Element;
21
21
  export default UploadFile;
@@ -21,8 +21,6 @@ import Collapse from '../../../components/Collapse';
21
21
  import Warning from '../../../components/Warning';
22
22
  import Icon from '../../../components/Icon';
23
23
  import { ICONS_NAMES } from '../../../constants';
24
- import { useTranslation } from 'react-i18next';
25
- import Loader from '../../../components/Loader';
26
24
  var FeatureStyled = styled(ScreenContainer)(function (_a) {
27
25
  var theme = _a.theme;
28
26
  return ({
@@ -61,17 +59,18 @@ export var InputContainerStyled = styled(Box)(function (_a) {
61
59
  });
62
60
  });
63
61
  var UploadFile = function (_a) {
64
- var label = _a.label, required = _a.required, dragTitle = _a.dragTitle, uploadTitle = _a.uploadTitle, loading = _a.loading, error = _a.error, onFileUploaded = _a.onFileUploaded, onReset = _a.onReset;
62
+ var label = _a.label, required = _a.required, dragTitle = _a.dragTitle, uploadTitle = _a.uploadTitle, isSubmitting = _a.isSubmitting, error = _a.error, onFileUploaded = _a.onFileUploaded, onReset = _a.onReset;
65
63
  var _b = React.useState(''), fileName = _b[0], setFileName = _b[1];
66
- var t = useTranslation().t;
67
64
  var handleFileChange = function (file) {
68
65
  setFileName(file === null || file === void 0 ? void 0 : file.name);
69
66
  onFileUploaded === null || onFileUploaded === void 0 ? void 0 : onFileUploaded(file);
70
67
  };
71
68
  var handleReset = function () {
72
- setFileName('');
73
- onReset === null || onReset === void 0 ? void 0 : onReset();
69
+ if (!isSubmitting) {
70
+ setFileName('');
71
+ onReset === null || onReset === void 0 ? void 0 : onReset();
72
+ }
74
73
  };
75
- return (_jsxs(FeatureStyled, { children: [_jsxs(LabelContainerStyled, { children: [_jsx(InputLabelStyled, { children: label }), required && _jsx(Mandatory, {})] }), _jsx(Collapse, __assign({ in: !fileName }, { children: _jsxs(InputContainerStyled, { children: [_jsx(DragAndDrop, { title: dragTitle, onSuccess: handleFileChange }), _jsx(UploadInput, { title: uploadTitle, onChange: handleFileChange })] }) })), _jsx(Collapse, __assign({ in: !!fileName }, { children: _jsxs(InputContainerStyled, { children: [_jsx(BoxStyled, { children: loading ? t('loading_bank_statement') : fileName }), _jsxs(UploadBoxStyled, __assign({ onClick: handleReset }, { children: [_jsx(Collapse, __assign({ in: !loading }, { children: _jsx(IconStyled, { src: ICONS_NAMES.DELETE_ICON }) })), _jsx(Collapse, __assign({ in: loading }, { children: _jsx(Loader, { innerColor: 'white', outerColor: 'white', toggleAnimation: true, style: { width: 30, height: 30 }, svgStyle: { width: 30, height: 30 } }) }))] }))] }) })), _jsx(Collapse, __assign({ in: !!error, timeout: 400 }, { children: _jsx(Warning, __assign({ warningType: 'alert' }, { children: error })) }))] }));
74
+ return (_jsxs(FeatureStyled, { children: [_jsxs(LabelContainerStyled, { children: [_jsx(InputLabelStyled, { children: label }), required && _jsx(Mandatory, {})] }), _jsx(Collapse, __assign({ in: !fileName }, { children: _jsxs(InputContainerStyled, { children: [_jsx(DragAndDrop, { title: dragTitle, onSuccess: handleFileChange }), _jsx(UploadInput, { title: uploadTitle, onChange: handleFileChange })] }) })), _jsx(Collapse, __assign({ in: !!fileName }, { children: _jsxs(InputContainerStyled, { children: [_jsx(BoxStyled, { children: fileName }), _jsx(UploadBoxStyled, __assign({ onClick: handleReset }, { children: _jsx(IconStyled, { src: ICONS_NAMES.DELETE_ICON }) }))] }) })), _jsx(Collapse, __assign({ in: !!error, timeout: 400 }, { children: _jsx(Warning, __assign({ warningType: 'alert' }, { children: error })) }))] }));
76
75
  };
77
76
  export default UploadFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "1.1.4-test",
3
+ "version": "1.1.5-test",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",