@tap-payments/auth-jsconnect 2.9.12-development → 2.9.14-development

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 (38) hide show
  1. package/build/@types/form.d.ts +4 -0
  2. package/build/assets/locales/ar.json +6 -1
  3. package/build/assets/locales/en.json +6 -1
  4. package/build/components/Input/Input.js +1 -1
  5. package/build/constants/app.d.ts +6 -0
  6. package/build/constants/app.js +36 -6
  7. package/build/features/app/business/businessStore.d.ts +10 -1
  8. package/build/features/app/business/businessStore.js +107 -8
  9. package/build/features/app/connect/connectStore.d.ts +8 -1
  10. package/build/features/app/connect/connectStore.js +87 -2
  11. package/build/features/app/connectExpress/connectExpressStore.d.ts +8 -1
  12. package/build/features/app/connectExpress/connectExpressStore.js +149 -16
  13. package/build/features/business/screens/MobileOwnership/CollectMobileOwnership.d.ts +3 -0
  14. package/build/features/business/screens/MobileOwnership/CollectMobileOwnership.js +104 -0
  15. package/build/features/business/screens/MobileOwnership/MobileNumber.d.ts +3 -0
  16. package/build/features/business/screens/MobileOwnership/MobileNumber.js +72 -0
  17. package/build/features/business/screens/MobileOwnership/index.d.ts +2 -0
  18. package/build/features/business/screens/MobileOwnership/index.js +2 -0
  19. package/build/features/business/screens/MobileOwnership/validation.d.ts +8 -0
  20. package/build/features/business/screens/MobileOwnership/validation.js +38 -0
  21. package/build/features/connect/screens/MobileOwnership/CollectMobileOwnership.d.ts +3 -0
  22. package/build/features/connect/screens/MobileOwnership/CollectMobileOwnership.js +105 -0
  23. package/build/features/connect/screens/MobileOwnership/MobileNumber.d.ts +3 -0
  24. package/build/features/connect/screens/MobileOwnership/MobileNumber.js +72 -0
  25. package/build/features/connect/screens/MobileOwnership/index.d.ts +2 -0
  26. package/build/features/connect/screens/MobileOwnership/index.js +2 -0
  27. package/build/features/connect/screens/MobileOwnership/validation.d.ts +8 -0
  28. package/build/features/connect/screens/MobileOwnership/validation.js +38 -0
  29. package/build/features/connectExpress/screens/MobileOwnership/CollectMobileOwnership.d.ts +3 -0
  30. package/build/features/connectExpress/screens/MobileOwnership/CollectMobileOwnership.js +107 -0
  31. package/build/features/connectExpress/screens/MobileOwnership/MobileNumber.d.ts +3 -0
  32. package/build/features/connectExpress/screens/MobileOwnership/MobileNumber.js +72 -0
  33. package/build/features/connectExpress/screens/MobileOwnership/index.d.ts +2 -0
  34. package/build/features/connectExpress/screens/MobileOwnership/index.js +2 -0
  35. package/build/features/connectExpress/screens/MobileOwnership/validation.d.ts +8 -0
  36. package/build/features/connectExpress/screens/MobileOwnership/validation.js +38 -0
  37. package/build/features/featuresScreens.js +15 -0
  38. package/package.json +1 -1
@@ -685,18 +685,18 @@ export var createNIDNafathAuthIdentityAsync = createAsyncThunk('connectExpress/c
685
685
  });
686
686
  }); });
687
687
  export var verifyNafathIdentityAsync = createAsyncThunk('connectExpress/verifyNafathIdentityAsync', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
688
- var connectExpress, authData, expiry, interval, maxCalls, count, data, isSuccess, isFailed, needToCollectMoreInfo, creatingAccount, askDobInfo;
689
- var _a, _b, _c, _d, _e, _f, _g;
690
- return __generator(this, function (_h) {
691
- switch (_h.label) {
688
+ var _a, connectExpress, settings, authData, expiry, interval, maxCalls, count, data, isSuccess, isFailed, needToCollectMoreInfo, creatingAccount, askDobInfo, collectPhoneOwnershipScreen;
689
+ var _b, _c, _d, _e, _f, _g, _h;
690
+ return __generator(this, function (_j) {
691
+ switch (_j.label) {
692
692
  case 0:
693
- connectExpress = thunkApi.getState().connectExpress;
693
+ _a = thunkApi.getState(), connectExpress = _a.connectExpress, settings = _a.settings;
694
694
  authData = (connectExpress.data.responseData || {}).authData;
695
695
  expiry = (authData === null || authData === void 0 ? void 0 : authData.expiry) || 120;
696
696
  interval = 3;
697
697
  maxCalls = Math.floor(expiry / interval);
698
698
  count = 1;
699
- _h.label = 1;
699
+ _j.label = 1;
700
700
  case 1:
701
701
  if (!(count <= maxCalls)) return [3, 7];
702
702
  if (thunkApi.signal.aborted) {
@@ -704,21 +704,25 @@ export var verifyNafathIdentityAsync = createAsyncThunk('connectExpress/verifyNa
704
704
  }
705
705
  return [4, API.authService.getExpressTokenVerify({ token: authData === null || authData === void 0 ? void 0 : authData.verify_token, leadId: authData === null || authData === void 0 ? void 0 : authData.lead_id })];
706
706
  case 2:
707
- data = _h.sent();
708
- isSuccess = ((_b = (_a = data.auth) === null || _a === void 0 ? void 0 : _a.status) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'success';
709
- isFailed = ((_d = (_c = data.auth) === null || _c === void 0 ? void 0 : _c.status) === null || _d === void 0 ? void 0 : _d.toLowerCase()) === 'failed';
707
+ data = _j.sent();
708
+ isSuccess = ((_c = (_b = data.auth) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.toLowerCase()) === 'success';
709
+ isFailed = ((_e = (_d = data.auth) === null || _d === void 0 ? void 0 : _d.status) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === 'failed';
710
710
  if (isFailed) {
711
- (_e = params.onFailure) === null || _e === void 0 ? void 0 : _e.call(params);
711
+ (_f = params.onFailure) === null || _f === void 0 ? void 0 : _f.call(params);
712
712
  return [2, { data: data }];
713
713
  }
714
714
  if (!isSuccess) return [3, 4];
715
- return [4, thunkApi.dispatch(getLeadByIdAsync((_f = data.auth) === null || _f === void 0 ? void 0 : _f.lead_id)).unwrap()];
715
+ return [4, thunkApi.dispatch(getLeadByIdAsync((_g = data.auth) === null || _g === void 0 ? void 0 : _g.lead_id)).unwrap()];
716
716
  case 3:
717
- _h.sent();
717
+ _j.sent();
718
718
  needToCollectMoreInfo = data.step_name === 'collect_info';
719
719
  creatingAccount = data.step_name === 'create_account';
720
720
  askDobInfo = data.step_name === COLLECT_DOB_INFO_NAFATH;
721
- (_g = params.onSuccess) === null || _g === void 0 ? void 0 : _g.call(params);
721
+ collectPhoneOwnershipScreen = data.step_name === CONNECT_EXPRESS_STEP_NAMES.COLLECT_MOBILE_OWNERSHIP;
722
+ (_h = params.onSuccess) === null || _h === void 0 ? void 0 : _h.call(params);
723
+ if (isSA(settings.data.businessCountry.iso2) && collectPhoneOwnershipScreen) {
724
+ sleep(100).then(function () { return thunkApi.dispatch(handleNextScreenStep('COLLECT_MOBILE_OWNERSHIP')); });
725
+ }
722
726
  if (askDobInfo) {
723
727
  sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_DOB_INFO_STEP')); });
724
728
  }
@@ -731,8 +735,8 @@ export var verifyNafathIdentityAsync = createAsyncThunk('connectExpress/verifyNa
731
735
  return [2, { data: data, isNextScreenIsDob: askDobInfo }];
732
736
  case 4: return [4, sleep(interval * 1000)];
733
737
  case 5:
734
- _h.sent();
735
- _h.label = 6;
738
+ _j.sent();
739
+ _j.label = 6;
736
740
  case 6:
737
741
  count++;
738
742
  return [3, 1];
@@ -1010,7 +1014,7 @@ export var updateLeadDOBAsync = createAsyncThunk('connectExpress/updateLeadDOBAs
1010
1014
  export var updateLeadIndividualAsync = createAsyncThunk('connectExpress/updateLeadIndividualAsync', function (_a, thunkApi) {
1011
1015
  var formData = _a.formData, originalFormData = _a.originalFormData;
1012
1016
  return __awaiter(void 0, void 0, void 0, function () {
1013
- var _b, settings, connectExpress, id, countryCode, name, email, mobile, phoneCountry, isContactAvailable, payload, data, needToCollectMoreInfo, creatingAccount, isSaudi;
1017
+ var _b, settings, connectExpress, id, countryCode, name, email, mobile, phoneCountry, isContactAvailable, payload, data, needToCollectMoreInfo, creatingAccount, collectPhoneOwnershipScreen, isSaudi;
1014
1018
  var _c, _d, _e, _f, _g;
1015
1019
  return __generator(this, function (_h) {
1016
1020
  switch (_h.label) {
@@ -1029,6 +1033,10 @@ export var updateLeadIndividualAsync = createAsyncThunk('connectExpress/updateLe
1029
1033
  (_g = (_f = settings.data.appConfig).onStepCompleted) === null || _g === void 0 ? void 0 : _g.call(_f, settings.data.activeScreen.name, formData);
1030
1034
  needToCollectMoreInfo = data.step_name === 'collect_info';
1031
1035
  creatingAccount = data.step_name === 'create_account';
1036
+ collectPhoneOwnershipScreen = data.step_name === CONNECT_EXPRESS_STEP_NAMES.COLLECT_MOBILE_OWNERSHIP;
1037
+ if (isSA(settings.data.businessCountry.iso2) && collectPhoneOwnershipScreen) {
1038
+ sleep(100).then(function () { return thunkApi.dispatch(handleNextScreenStep('COLLECT_MOBILE_OWNERSHIP')); });
1039
+ }
1032
1040
  if (creatingAccount) {
1033
1041
  sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_WAITING_FOR_CREATING_ACCOUNT_STEP')); });
1034
1042
  }
@@ -1088,6 +1096,104 @@ export var updateLeadBusinessDataAsync = createAsyncThunk('updateLeadBusinessDat
1088
1096
  });
1089
1097
  });
1090
1098
  });
1099
+ export var updateLeadMobile = createAsyncThunk('connect/updateLeadMobile', function (params, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
1100
+ var _a, settings, connectExpress, id, startWithNID, payload, leadResponse, needToCollectMoreInfo, creatingAccount, askDobInfo, collectPhoneOwnershipScreen;
1101
+ var _b, _c, _d;
1102
+ return __generator(this, function (_e) {
1103
+ switch (_e.label) {
1104
+ case 0:
1105
+ _a = thunkApi.getState(), settings = _a.settings, connectExpress = _a.connectExpress;
1106
+ id = (((_b = connectExpress.data.responseData) === null || _b === void 0 ? void 0 : _b.leadData) || {}).id;
1107
+ startWithNID = connectExpress.data.otpData.authFor === AuthForType.NATIONAL_ID;
1108
+ payload = {
1109
+ id: id || '',
1110
+ contact: {
1111
+ phone: {
1112
+ country_code: params.countryCode.idd_prefix.toString(),
1113
+ number: params.mobile
1114
+ }
1115
+ },
1116
+ step_name: CONNECT_EXPRESS_STEP_NAMES.COLLECT_MOBILE_OWNERSHIP,
1117
+ encryption_contract: ['contact.phone.country_code', 'contact.phone.number']
1118
+ };
1119
+ return [4, API.leadService.updateLeadExpress(payload)];
1120
+ case 1:
1121
+ leadResponse = _e.sent();
1122
+ (_d = (_c = settings.data.appConfig).onStepCompleted) === null || _d === void 0 ? void 0 : _d.call(_c, settings.data.activeScreen.name, params);
1123
+ needToCollectMoreInfo = leadResponse.step_name === 'collect_info';
1124
+ creatingAccount = leadResponse.step_name === 'create_account';
1125
+ askDobInfo = leadResponse.step_name === COLLECT_DOB_INFO_NAFATH;
1126
+ collectPhoneOwnershipScreen = leadResponse.step_name === CONNECT_EXPRESS_STEP_NAMES.COLLECT_MOBILE_OWNERSHIP;
1127
+ if (collectPhoneOwnershipScreen) {
1128
+ throw new Error("The new mobile number doesn't match the national ID, please update the mobile to the correct one");
1129
+ }
1130
+ if (askDobInfo) {
1131
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_DOB_INFO_STEP')); });
1132
+ }
1133
+ if (creatingAccount) {
1134
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_WAITING_FOR_CREATING_ACCOUNT_STEP')); });
1135
+ }
1136
+ if (!needToCollectMoreInfo) return [3, 5];
1137
+ if (!startWithNID) return [3, 4];
1138
+ if (!isSA(settings.data.businessCountry.iso2)) return [3, 3];
1139
+ return [4, thunkApi.dispatch(retrieveEntityListAsync(leadResponse.lead.id)).unwrap()];
1140
+ case 2:
1141
+ _e.sent();
1142
+ _e.label = 3;
1143
+ case 3:
1144
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_BUSINESS_INFO_STEP')); });
1145
+ return [3, 5];
1146
+ case 4:
1147
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_INDIVIDUAL_INFO_STEP')); });
1148
+ _e.label = 5;
1149
+ case 5: return [2, { leadResponse: leadResponse, formData: params }];
1150
+ }
1151
+ });
1152
+ }); });
1153
+ export var skipUpdateLeadMobile = createAsyncThunk('connect/skipUpdateLeadMobile', function (_, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
1154
+ var _a, settings, connectExpress, id, startWithNID, payload, leadResponse, needToCollectMoreInfo, creatingAccount, askDobInfo;
1155
+ var _b, _c, _d;
1156
+ return __generator(this, function (_e) {
1157
+ switch (_e.label) {
1158
+ case 0:
1159
+ _a = thunkApi.getState(), settings = _a.settings, connectExpress = _a.connectExpress;
1160
+ id = (((_b = connectExpress.data.responseData) === null || _b === void 0 ? void 0 : _b.leadData) || {}).id;
1161
+ startWithNID = connectExpress.data.otpData.authFor === AuthForType.NATIONAL_ID;
1162
+ payload = {
1163
+ id: id || '',
1164
+ step_name: CONNECT_EXPRESS_STEP_NAMES.COLLECT_MOBILE_OWNERSHIP_SKIPPED,
1165
+ encryption_contract: []
1166
+ };
1167
+ return [4, API.leadService.updateLeadExpress(payload)];
1168
+ case 1:
1169
+ leadResponse = _e.sent();
1170
+ (_d = (_c = settings.data.appConfig).onStepCompleted) === null || _d === void 0 ? void 0 : _d.call(_c, settings.data.activeScreen.name, {});
1171
+ needToCollectMoreInfo = leadResponse.step_name === 'collect_info';
1172
+ creatingAccount = leadResponse.step_name === 'create_account';
1173
+ askDobInfo = leadResponse.step_name === COLLECT_DOB_INFO_NAFATH;
1174
+ if (askDobInfo) {
1175
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_DOB_INFO_STEP')); });
1176
+ }
1177
+ if (creatingAccount) {
1178
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_WAITING_FOR_CREATING_ACCOUNT_STEP')); });
1179
+ }
1180
+ if (!needToCollectMoreInfo) return [3, 5];
1181
+ if (!startWithNID) return [3, 4];
1182
+ if (!isSA(settings.data.businessCountry.iso2)) return [3, 3];
1183
+ return [4, thunkApi.dispatch(retrieveEntityListAsync(leadResponse.lead.id)).unwrap()];
1184
+ case 2:
1185
+ _e.sent();
1186
+ _e.label = 3;
1187
+ case 3:
1188
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_BUSINESS_INFO_STEP')); });
1189
+ return [3, 5];
1190
+ case 4:
1191
+ sleep(100).then(function () { return thunkApi.dispatch(handleCurrentActiveScreen('CONNECT_EXPRESS_COLLECT_INDIVIDUAL_INFO_STEP')); });
1192
+ _e.label = 5;
1193
+ case 5: return [2, { leadResponse: leadResponse }];
1194
+ }
1195
+ });
1196
+ }); });
1091
1197
  export var confirmInfo = createAsyncThunk('connectExpress/confirmInfo', function (_a, thunkApi) {
1092
1198
  var brandInfo = _a.brandInfo, entityInfo = _a.entityInfo, merchantInfo = _a.merchantInfo;
1093
1199
  return __awaiter(void 0, void 0, void 0, function () {
@@ -1639,6 +1745,33 @@ export var connectSlice = createSlice({
1639
1745
  .addCase(updateLeadBusinessDataAsync.rejected, function (state, action) {
1640
1746
  state.loading = false;
1641
1747
  state.error = action.error.message;
1748
+ })
1749
+ .addCase(updateLeadMobile.fulfilled, function (state, action) {
1750
+ state.loading = false;
1751
+ state.error = null;
1752
+ state.data.individualData.mobile = action.payload.formData.mobile;
1753
+ state.data.responseData = __assign(__assign({}, state.data.responseData), { individualData: action.payload.leadResponse });
1754
+ })
1755
+ .addCase(updateLeadMobile.pending, function (state) {
1756
+ state.loading = true;
1757
+ state.error = null;
1758
+ })
1759
+ .addCase(updateLeadMobile.rejected, function (state, action) {
1760
+ state.loading = false;
1761
+ state.error = action.error.message;
1762
+ })
1763
+ .addCase(skipUpdateLeadMobile.fulfilled, function (state, action) {
1764
+ state.loading = false;
1765
+ state.error = null;
1766
+ state.data.responseData = __assign(__assign({}, state.data.responseData), { individualData: action.payload.leadResponse });
1767
+ })
1768
+ .addCase(skipUpdateLeadMobile.pending, function (state) {
1769
+ state.loading = true;
1770
+ state.error = null;
1771
+ })
1772
+ .addCase(skipUpdateLeadMobile.rejected, function (state, action) {
1773
+ state.loading = false;
1774
+ state.error = action.error.message;
1642
1775
  })
1643
1776
  .addCase(createAccountAsync.pending, function (state) {
1644
1777
  state.loading = true;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const CollectMobileOwnership: () => JSX.Element;
3
+ export default CollectMobileOwnership;
@@ -0,0 +1,104 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { FormProvider, useForm } from 'react-hook-form';
14
+ import { ScreenContainer } from '../../../../features/shared/Containers';
15
+ import { styled } from '@mui/material/styles';
16
+ import Form from '../../../../components/Form';
17
+ import { yupResolver } from '@hookform/resolvers/yup';
18
+ import { PhoneValidationSchema } from './validation';
19
+ import { Box, alpha } from '@mui/material';
20
+ import { useTranslation } from 'react-i18next';
21
+ import Text from '../../../../components/Text';
22
+ import { Button as SharedButton } from '../../../shared/Button';
23
+ import { useAppDispatch, useAppSelector, useLanguage } from '../../../../hooks';
24
+ import { handlePrevScreenStep } from '../../../../app/settings';
25
+ import { businessSelector, skipUpdateLeadMobile, updateLeadMobile } from '../../../../features/app/business/businessStore';
26
+ import Button from '../../../../components/Button';
27
+ import MobileNumber from './MobileNumber';
28
+ var FormStyled = styled(Form)(function () { return ({
29
+ display: 'flex',
30
+ flexDirection: 'column',
31
+ justifyContent: 'flex-start'
32
+ }); });
33
+ var TitleContainerStyled = styled(Box)(function (_a) {
34
+ var theme = _a.theme;
35
+ return ({
36
+ background: theme.palette.common.white,
37
+ borderTop: '1px solid rgba(227, 232, 238, 0.8)',
38
+ borderBottom: '1px solid rgba(227, 232, 238, 0.8)',
39
+ borderRadius: theme.spacing(0, 0, 1.25, 1.25)
40
+ });
41
+ });
42
+ var TitleStyled = styled(Text)(function (_a) {
43
+ var theme = _a.theme;
44
+ return (__assign(__assign({}, theme.typography.body1), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightLight, margin: theme.spacing(1.75, 2.5), lineHeight: 1.2 }));
45
+ });
46
+ var InputLabelStyled = styled(Text)(function (_a) {
47
+ var theme = _a.theme;
48
+ return (__assign(__assign({ color: alpha(theme.palette.text.primary, 0.6), fontWeight: theme.typography.fontWeightRegular }, theme.typography.caption), { lineHeight: 1.2 }));
49
+ });
50
+ var CurrentMobileContainerStyled = styled(Box)(function (_a) {
51
+ var theme = _a.theme;
52
+ return ({
53
+ display: 'flex',
54
+ flexDirection: 'column',
55
+ rowGap: theme.spacing(1.6),
56
+ height: theme.spacing(9.375),
57
+ marginTop: theme.spacing(2.85),
58
+ marginInlineStart: theme.spacing(2.375)
59
+ });
60
+ });
61
+ var MobileNumberContainer = styled(Box)(function (_a) {
62
+ var theme = _a.theme;
63
+ return ({
64
+ display: 'flex',
65
+ columnGap: theme.spacing(0.9)
66
+ });
67
+ });
68
+ var CountryCodeStyled = styled(Text)(function (_a) {
69
+ var theme = _a.theme;
70
+ return (__assign(__assign({}, theme.typography.body2), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightMedium, lineHeight: 1.2 }));
71
+ });
72
+ var MobileNumberStyled = styled(Text)(function (_a) {
73
+ var theme = _a.theme;
74
+ return (__assign(__assign({}, theme.typography.body2), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightRegular, lineHeight: 1.2 }));
75
+ });
76
+ var UpdateLaterContainerStyled = styled(Box)(function (_a) {
77
+ var theme = _a.theme;
78
+ return ({
79
+ marginLeft: theme.spacing(2.5),
80
+ marginRight: theme.spacing(2.5)
81
+ });
82
+ });
83
+ var CollectMobileOwnership = function () {
84
+ var dispatch = useAppDispatch();
85
+ var t = useTranslation().t;
86
+ var isAr = useLanguage().isAr;
87
+ var _a = useAppSelector(businessSelector), data = _a.data, loading = _a.loading, error = _a.error;
88
+ var methods = useForm({
89
+ resolver: yupResolver(PhoneValidationSchema()),
90
+ defaultValues: { mobile: '', countryCode: data.mobileData.countryCode },
91
+ mode: 'onChange'
92
+ });
93
+ var onSubmit = function (data) {
94
+ dispatch(updateLeadMobile(data));
95
+ };
96
+ var onBack = function () {
97
+ dispatch(handlePrevScreenStep());
98
+ };
99
+ var onUpdateLater = function () {
100
+ dispatch(skipUpdateLeadMobile());
101
+ };
102
+ return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsx(TitleContainerStyled, { children: _jsx(TitleStyled, { children: t('mobile_ownership_title') }) }), _jsxs(CurrentMobileContainerStyled, { children: [_jsx(InputLabelStyled, { children: t('current_mobile_number') }), _jsxs(MobileNumberContainer, { children: [_jsxs(CountryCodeStyled, { children: ["+", data.mobileData.countryCode.idd_prefix] }), _jsx(MobileNumberStyled, { children: data.mobileData.mobile })] })] }), _jsx(MobileNumber, {}), _jsx(SharedButton, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disabled: !methods.formState.isValid, loading: loading, error: t(error || '') }, { children: t('update_mobile_number') })), _jsx(UpdateLaterContainerStyled, { children: _jsx(Button, __assign({ variant: 'text', onClick: function () { return onUpdateLater(); } }, { children: t('update_later') })) })] })) })) }));
103
+ };
104
+ export default CollectMobileOwnership;
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ declare const _default: React.MemoExoticComponent<() => JSX.Element>;
3
+ export default _default;
@@ -0,0 +1,72 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
+ import * as React from 'react';
14
+ import { useTranslation } from 'react-i18next';
15
+ import { useController, useFormContext } from 'react-hook-form';
16
+ import Box from '@mui/material/Box';
17
+ import { styled, alpha } from '@mui/material/styles';
18
+ import { getMobileNumberLen, removeAllCharsFromNumber } from '../../../../utils';
19
+ import { useAppSelector } from '../../../../hooks';
20
+ import Text from '../../../../components/Text';
21
+ import ClearIcon from '../../../shared/ClearIcon';
22
+ import CheckIcon from '../../../shared/CheckIcon';
23
+ import ScreenContainer from '../../../shared/Containers/ScreenContainer';
24
+ import Input from '../../../shared/Input';
25
+ import { businessSelector } from '../../../../features/app/business/businessStore';
26
+ var LabelContainerStyled = styled(Box)(function (_a) {
27
+ var theme = _a.theme;
28
+ return ({
29
+ display: 'flex',
30
+ justifyContent: 'space-between',
31
+ padding: theme.spacing(0, 2.5, 1.25, 2.5)
32
+ });
33
+ });
34
+ var InputLabelStyled = styled(Text)(function (_a) {
35
+ var theme = _a.theme;
36
+ return (__assign(__assign({ color: alpha(theme.palette.text.primary, 0.6), fontWeight: theme.typography.fontWeightMedium }, theme.typography.caption), { lineHeight: theme.spacing(2.5) }));
37
+ });
38
+ var InputStyled = styled(Input)(function () { return ({
39
+ direction: 'ltr',
40
+ '& .MuiInputBase-input': {
41
+ cursor: 'auto'
42
+ }
43
+ }); });
44
+ var MobileNumber = function () {
45
+ var _a;
46
+ var t = useTranslation().t;
47
+ var _b = useFormContext(), control = _b.control, setValue = _b.setValue;
48
+ var data = useAppSelector(businessSelector).data;
49
+ var phoneControl = useController({ name: 'mobile', control: control });
50
+ var countryCodeValue = data.mobileData.countryCode;
51
+ var mobileValue = phoneControl.field.value || '';
52
+ var error = !!mobileValue ? (_a = phoneControl.fieldState.error) === null || _a === void 0 ? void 0 : _a.message : '';
53
+ var isSA = countryCodeValue.iso2 === 'SA';
54
+ var mobileMaxLen = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.max_digits;
55
+ var mobileMinLen = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.min_digits;
56
+ var requiredMaxLen = getMobileNumberLen(mobileMaxLen, mobileValue);
57
+ var requiredMinLen = getMobileNumberLen(mobileMinLen, mobileValue);
58
+ React.useEffect(function () {
59
+ if (mobileValue)
60
+ setValue('mobile', mobileValue, { shouldValidate: true });
61
+ }, []);
62
+ var onPhoneNumberChange = function (_a) {
63
+ var target = _a.target;
64
+ var value = removeAllCharsFromNumber(target.value);
65
+ phoneControl.field.onChange(value);
66
+ };
67
+ var clearMobileNumber = function () {
68
+ phoneControl.field.onChange('');
69
+ };
70
+ return (_jsx(_Fragment, { children: _jsxs(ScreenContainer, __assign({ sx: { mb: 3 } }, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: t('new_mobile_number') }) }), _jsx(InputStyled, { inputProps: { maxLength: requiredMaxLen }, type: 'tel', onChange: onPhoneNumberChange, value: mobileValue, startAdornment: "+".concat(countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix), endAdornment: !error && mobileValue ? _jsx(CheckIcon, {}) : mobileValue && _jsx(ClearIcon, { onClick: clearMobileNumber }), placeholder: "".concat(isSA ? '5' : '0', "00000000"), warningType: 'alert', warningMessage: error && t(error, { minLength: requiredMinLen, length: requiredMaxLen, number: '05|5' }) })] })) }));
71
+ };
72
+ export default React.memo(MobileNumber);
@@ -0,0 +1,2 @@
1
+ import CollectMobileOwnership from './CollectMobileOwnership';
2
+ export default CollectMobileOwnership;
@@ -0,0 +1,2 @@
1
+ import CollectMobileOwnership from './CollectMobileOwnership';
2
+ export default CollectMobileOwnership;
@@ -0,0 +1,8 @@
1
+ import * as yup from 'yup';
2
+ export declare const PhoneValidationSchema: () => yup.ObjectSchema<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
3
+ mobile: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
4
+ }>, import("yup/lib/object").AnyObject, import("yup/lib/object").TypeOfShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
5
+ mobile: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
6
+ }>>, import("yup/lib/object").AssertsShape<import("yup/lib/object").Assign<import("yup/lib/object").ObjectShape, {
7
+ mobile: import("yup/lib/string").RequiredStringSchema<string | undefined, import("yup/lib/types").AnyObject>;
8
+ }>>>;
@@ -0,0 +1,38 @@
1
+ import { getMobileNumberLen } from '../../../../utils';
2
+ import * as yup from 'yup';
3
+ export var PhoneValidationSchema = function () {
4
+ return yup.object().shape({
5
+ mobile: yup
6
+ .string()
7
+ .test({
8
+ test: function (value) {
9
+ var countryCode = this.parent.countryCode;
10
+ var isSA = countryCode.iso2 === 'SA';
11
+ var maxDigits = countryCode.max_digits;
12
+ var minDigits = countryCode.min_digits;
13
+ var mobileValue = value || '';
14
+ var valueLen = mobileValue.length;
15
+ var isNumber = mobileValue.match(/^[0-9]/g);
16
+ if (!isNumber)
17
+ return this.createError({ message: 'enter_valid_mobile_number' });
18
+ var isStartWithZero = mobileValue.startsWith('05');
19
+ var isStartWith5 = mobileValue.startsWith('5');
20
+ var isSaudiNumber = isStartWith5 || isStartWithZero;
21
+ if (isSA) {
22
+ if (!isSaudiNumber)
23
+ return this.createError({ message: 'start_with_number' });
24
+ var requiredLen = isStartWithZero ? maxDigits + 1 : maxDigits;
25
+ return valueLen === requiredLen ? true : this.createError({ message: 'enter_valid_mobile_number' });
26
+ }
27
+ var requiredMaxLen = getMobileNumberLen(maxDigits, mobileValue);
28
+ var requiredMinLen = getMobileNumberLen(minDigits, mobileValue);
29
+ if (valueLen >= requiredMinLen && valueLen <= requiredMaxLen)
30
+ return true;
31
+ if (minDigits === maxDigits)
32
+ return this.createError({ message: 'enter_valid_mobile_number' });
33
+ return this.createError({ message: 'enter_valid_mobile_number_min_max_length' });
34
+ }
35
+ })
36
+ .required('mobile_number_error')
37
+ });
38
+ };
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare const CollectMobileOwnership: () => JSX.Element;
3
+ export default CollectMobileOwnership;
@@ -0,0 +1,105 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { FormProvider, useForm } from 'react-hook-form';
14
+ import { ScreenContainer } from '../../../../features/shared/Containers';
15
+ import { styled } from '@mui/material/styles';
16
+ import Form from '../../../../components/Form';
17
+ import { yupResolver } from '@hookform/resolvers/yup';
18
+ import { PhoneValidationSchema } from './validation';
19
+ import { Box, alpha } from '@mui/material';
20
+ import { useTranslation } from 'react-i18next';
21
+ import Text from '../../../../components/Text';
22
+ import { Button as SharedButton } from '../../../shared/Button';
23
+ import { useAppDispatch, useAppSelector, useLanguage } from '../../../../hooks';
24
+ import { handlePrevScreenStep } from '../../../../app/settings';
25
+ import { connectSelector, skipUpdateLeadMobile, updateLeadMobile } from '../../../../features/app/connect/connectStore';
26
+ import Button from '../../../../components/Button';
27
+ import MobileNumber from './MobileNumber';
28
+ import { deepCopy } from '../../../../utils';
29
+ var FormStyled = styled(Form)(function () { return ({
30
+ display: 'flex',
31
+ flexDirection: 'column',
32
+ justifyContent: 'flex-start'
33
+ }); });
34
+ var TitleContainerStyled = styled(Box)(function (_a) {
35
+ var theme = _a.theme;
36
+ return ({
37
+ background: theme.palette.common.white,
38
+ borderTop: '1px solid rgba(227, 232, 238, 0.8)',
39
+ borderBottom: '1px solid rgba(227, 232, 238, 0.8)',
40
+ borderRadius: theme.spacing(0, 0, 1.25, 1.25)
41
+ });
42
+ });
43
+ var TitleStyled = styled(Text)(function (_a) {
44
+ var theme = _a.theme;
45
+ return (__assign(__assign({}, theme.typography.body1), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightLight, margin: theme.spacing(1.75, 2.5), lineHeight: 1.2 }));
46
+ });
47
+ var InputLabelStyled = styled(Text)(function (_a) {
48
+ var theme = _a.theme;
49
+ return (__assign(__assign({ color: alpha(theme.palette.text.primary, 0.6), fontWeight: theme.typography.fontWeightRegular }, theme.typography.caption), { lineHeight: 1.2 }));
50
+ });
51
+ var CurrentMobileContainerStyled = styled(Box)(function (_a) {
52
+ var theme = _a.theme;
53
+ return ({
54
+ display: 'flex',
55
+ flexDirection: 'column',
56
+ rowGap: theme.spacing(1.6),
57
+ height: theme.spacing(9.375),
58
+ marginTop: theme.spacing(2.85),
59
+ marginInlineStart: theme.spacing(2.375)
60
+ });
61
+ });
62
+ var MobileNumberContainer = styled(Box)(function (_a) {
63
+ var theme = _a.theme;
64
+ return ({
65
+ display: 'flex',
66
+ columnGap: theme.spacing(0.9)
67
+ });
68
+ });
69
+ var CountryCodeStyled = styled(Text)(function (_a) {
70
+ var theme = _a.theme;
71
+ return (__assign(__assign({}, theme.typography.body2), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightMedium, lineHeight: 1.2 }));
72
+ });
73
+ var MobileNumberStyled = styled(Text)(function (_a) {
74
+ var theme = _a.theme;
75
+ return (__assign(__assign({}, theme.typography.body2), { color: theme.palette.text.primary, fontWeight: theme.typography.fontWeightRegular, lineHeight: 1.2 }));
76
+ });
77
+ var UpdateLaterContainerStyled = styled(Box)(function (_a) {
78
+ var theme = _a.theme;
79
+ return ({
80
+ marginLeft: theme.spacing(2.5),
81
+ marginRight: theme.spacing(2.5)
82
+ });
83
+ });
84
+ var CollectMobileOwnership = function () {
85
+ var dispatch = useAppDispatch();
86
+ var t = useTranslation().t;
87
+ var isAr = useLanguage().isAr;
88
+ var _a = useAppSelector(connectSelector), data = _a.data, loading = _a.loading, error = _a.error;
89
+ var methods = useForm({
90
+ resolver: yupResolver(PhoneValidationSchema()),
91
+ defaultValues: { mobile: '', countryCode: data.mobileData.countryCode },
92
+ mode: 'onChange'
93
+ });
94
+ var onSubmit = function (data) {
95
+ dispatch(updateLeadMobile(deepCopy(data)));
96
+ };
97
+ var onBack = function () {
98
+ dispatch(handlePrevScreenStep());
99
+ };
100
+ var onUpdateLater = function () {
101
+ dispatch(skipUpdateLeadMobile());
102
+ };
103
+ return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsx(TitleContainerStyled, { children: _jsx(TitleStyled, { children: t('mobile_ownership_title') }) }), _jsxs(CurrentMobileContainerStyled, { children: [_jsx(InputLabelStyled, { children: t('current_mobile_number') }), _jsxs(MobileNumberContainer, { children: [_jsxs(CountryCodeStyled, { children: ["+", data.individualData.countryCode.idd_prefix] }), _jsx(MobileNumberStyled, { children: data.individualData.mobile })] })] }), _jsx(MobileNumber, {}), _jsx(SharedButton, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disabled: !methods.formState.isValid, loading: loading, error: t(error || '') }, { children: t('update_mobile_number') })), _jsx(UpdateLaterContainerStyled, { children: _jsx(Button, __assign({ variant: 'text', onClick: function () { return onUpdateLater(); } }, { children: t('update_later') })) })] })) })) }));
104
+ };
105
+ export default CollectMobileOwnership;
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ declare const _default: React.MemoExoticComponent<() => JSX.Element>;
3
+ export default _default;