@tap-payments/auth-jsconnect 1.0.30 → 1.0.31

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.
@@ -160,4 +160,16 @@ export interface DeviceInfo {
160
160
  connection: Connection;
161
161
  entry: Entry;
162
162
  }
163
+ export interface LocalProps {
164
+ en: {
165
+ translation: {
166
+ [key: string]: any;
167
+ };
168
+ };
169
+ ar: {
170
+ translation: {
171
+ [key: string]: any;
172
+ };
173
+ };
174
+ }
163
175
  export {};
@@ -0,0 +1,4 @@
1
+ declare const firebaseService: {
2
+ getLocale: () => Promise<import("axios").AxiosResponse<any, any>>;
3
+ };
4
+ export { firebaseService };
@@ -0,0 +1,9 @@
1
+ import axios from 'axios';
2
+ import { ENDPOINT_PATHS } from '../constants';
3
+ var getLocale = function () {
4
+ return axios.get(ENDPOINT_PATHS.FIREBASE_URL);
5
+ };
6
+ var firebaseService = {
7
+ getLocale: getLocale
8
+ };
9
+ export { firebaseService };
@@ -26,6 +26,9 @@ declare const API: {
26
26
  checkEmail: (data: CheckEmailBody, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("axios").AxiosResponse<any, any>>;
27
27
  checkBrand: (data: CheckBrandBody, config?: import("axios").AxiosRequestConfig<any> | undefined) => Promise<import("axios").AxiosResponse<any, any>>;
28
28
  };
29
+ firebaseService: {
30
+ getLocale: () => Promise<import("axios").AxiosResponse<any, any>>;
31
+ };
29
32
  };
30
33
  export type { ValidateOperatorBody, CreateAuthBody, VerifyAuthBody, UpdateLeadBody, LeadVerifyBody, CheckEmailBody, CheckBrandBody };
31
34
  export default API;
@@ -4,12 +4,14 @@ import { countryService } from './country';
4
4
  import { authService } from './auth';
5
5
  import { leadService } from './lead';
6
6
  import availabilityServices from './availabilityServices';
7
+ import { firebaseService } from './firebase';
7
8
  var API = {
8
9
  ipService: ipService,
9
10
  operatorService: operatorService,
10
11
  countryService: countryService,
11
12
  authService: authService,
12
13
  leadService: leadService,
13
- availabilityServices: availabilityServices
14
+ availabilityServices: availabilityServices,
15
+ firebaseService: firebaseService
14
16
  };
15
17
  export default API;
@@ -10,6 +10,7 @@ export declare const getBrowserFingerPrint: import("@reduxjs/toolkit").AsyncThun
10
10
  appInfo: AppInfo;
11
11
  }, AppInfo, {}>;
12
12
  export declare const getOperator: import("@reduxjs/toolkit").AsyncThunk<any, ValidateOperatorBody, {}>;
13
+ export declare const getLocale: import("@reduxjs/toolkit").AsyncThunk<any, void, {}>;
13
14
  export interface SettingsData {
14
15
  skin: ThemeMode;
15
16
  language: LanguageMode;
@@ -50,6 +50,7 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit';
50
50
  import { getStoredData, storeData, isArray, findItem, getBrowserInfo, getFingerPrint } from '../utils';
51
51
  import { DefaultDeviceInfo, LOCAL_STORAGE_KEYS } from '../constants';
52
52
  import i18n from '../i18n';
53
+ import { updateLocale } from '../utils/locale';
53
54
  import API from '../api';
54
55
  export var getClientIp = createAsyncThunk('getClientIp', function () { return __awaiter(void 0, void 0, void 0, function () {
55
56
  var data;
@@ -86,6 +87,17 @@ export var getOperator = createAsyncThunk('getOperator', function (params) { ret
86
87
  }
87
88
  });
88
89
  }); });
90
+ export var getLocale = createAsyncThunk('getLocale', function () { return __awaiter(void 0, void 0, void 0, function () {
91
+ var data;
92
+ return __generator(this, function (_a) {
93
+ switch (_a.label) {
94
+ case 0: return [4, API.firebaseService.getLocale()];
95
+ case 1:
96
+ data = (_a.sent()).data;
97
+ return [2, data];
98
+ }
99
+ });
100
+ }); });
89
101
  var initialState = {
90
102
  error: null,
91
103
  loading: false,
@@ -176,13 +188,16 @@ export var settingsSlice = createSlice({
176
188
  builder
177
189
  .addCase(getClientIp.pending, function (state) {
178
190
  state.error = null;
191
+ state.loading = true;
179
192
  })
180
193
  .addCase(getClientIp.fulfilled, function (state, action) {
181
194
  state.error = null;
195
+ state.loading = false;
182
196
  state.data.deviceInfo.connection.ip = action.payload;
183
197
  })
184
198
  .addCase(getClientIp.rejected, function (state, action) {
185
199
  state.error = action.error.message;
200
+ state.loading = false;
186
201
  })
187
202
  .addCase(getBrowserFingerPrint.pending, function (state) {
188
203
  state.loading = true;
@@ -206,18 +221,35 @@ export var settingsSlice = createSlice({
206
221
  })
207
222
  .addCase(getBrowserFingerPrint.rejected, function (state, action) {
208
223
  state.loading = false;
224
+ state.loading = false;
209
225
  state.error = action.error.message;
210
226
  })
211
227
  .addCase(getOperator.pending, function (state) {
212
228
  state.error = null;
229
+ state.loading = true;
213
230
  })
214
231
  .addCase(getOperator.fulfilled, function (state, action) {
232
+ state.loading = false;
215
233
  if (action.payload === 'valid') {
216
234
  state.error = null;
217
235
  }
218
236
  })
219
237
  .addCase(getOperator.rejected, function (state, action) {
220
238
  state.error = action.error.message;
239
+ state.loading = false;
240
+ })
241
+ .addCase(getLocale.pending, function (state) {
242
+ state.error = null;
243
+ state.loading = true;
244
+ })
245
+ .addCase(getLocale.fulfilled, function (state, action) {
246
+ state.loading = false;
247
+ state.error = null;
248
+ updateLocale(action.payload);
249
+ })
250
+ .addCase(getLocale.rejected, function (state, action) {
251
+ state.loading = false;
252
+ state.error = action.error.message;
221
253
  });
222
254
  }
223
255
  });
@@ -210,6 +210,6 @@
210
210
  "absher_button_label": "المتابعة عن طريق أبشر",
211
211
  "or": "أو",
212
212
  "next": "التالي",
213
- "open_mail_box": "Open Mailbox",
213
+ "open_mail_box": "افتح البريد الإلكتروني",
214
214
  "mobile_button_label": "المتابعة عن طريق رقم الجوال"
215
215
  }
@@ -9,4 +9,5 @@ export declare const ENDPOINT_PATHS: {
9
9
  LEAD_IDENTITY_VERIFY: string;
10
10
  CHECK_EMAIL: string;
11
11
  CHECK_BRAND: string;
12
+ FIREBASE_URL: string;
12
13
  };
@@ -8,6 +8,7 @@ var LEAD_PATH = '/lead';
8
8
  var LEAD_IDENTITY_VERIFY_PATH = 'lead/identity/verify';
9
9
  var CHECK_EMAIL = '/lead/identity/emailcheck';
10
10
  var CHECK_BRAND = 'lead/profile/profile_name';
11
+ var FIREBASE_URL = 'https://goconnect-195cd-default-rtdb.asia-southeast1.firebasedatabase.app/sandbox/local.json';
11
12
  export var ENDPOINT_PATHS = {
12
13
  BASE_URL: API_BASE_URL,
13
14
  BUSINESS_COUNTRIES: API_BUSINESS_COUNTRIES,
@@ -18,5 +19,6 @@ export var ENDPOINT_PATHS = {
18
19
  LEAD: LEAD_PATH,
19
20
  LEAD_IDENTITY_VERIFY: LEAD_IDENTITY_VERIFY_PATH,
20
21
  CHECK_EMAIL: CHECK_EMAIL,
21
- CHECK_BRAND: CHECK_BRAND
22
+ CHECK_BRAND: CHECK_BRAND,
23
+ FIREBASE_URL: FIREBASE_URL
22
24
  };
@@ -32,4 +32,5 @@ export declare const ICONS_NAMES: {
32
32
  WHITE_ARROW: string;
33
33
  SUCCESS: string;
34
34
  ABSHER_LOGO: string;
35
+ EMAIL_ICON: string;
35
36
  };
@@ -31,5 +31,6 @@ export var ICONS_NAMES = {
31
31
  MOBILE_IMAGE: 'https://image.shutterstock.com/image-vector/smartphone-icon-logo-260nw-767440327.jpg',
32
32
  WHITE_ARROW: 'https://tap-connecet.b-cdn.net/imgs/whiteArrow.svg',
33
33
  SUCCESS: 'https://tap-connecet.b-cdn.net/imgs/success.svg',
34
- ABSHER_LOGO: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Absher.svg/687px-Absher.svg.png'
34
+ ABSHER_LOGO: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/Absher.svg/687px-Absher.svg.png',
35
+ EMAIL_ICON: 'https://dash.b-cdn.net/icons/menu/email.png'
35
36
  };
@@ -54,7 +54,7 @@ export var defaultCountry = {
54
54
  geoNameId: '102358',
55
55
  idd_prefix: 966,
56
56
  logo: 'https://back-end.b-cdn.net/country/png/SA.png',
57
- digits: 9,
57
+ digits: 10,
58
58
  supported_by_tap: true
59
59
  };
60
60
  export var businessCountries = [
@@ -107,7 +107,7 @@ export var businessCountries = [
107
107
  geoNameId: '102358',
108
108
  idd_prefix: 966,
109
109
  logo: 'https://back-end.b-cdn.net/country/png/SA.png',
110
- digits: 9,
110
+ digits: 10,
111
111
  supported_by_tap: true
112
112
  },
113
113
  {
@@ -367,7 +367,7 @@ export var countriesCode = [
367
367
  geoNameId: '102358',
368
368
  idd_prefix: 966,
369
369
  logo: 'https://back-end.b-cdn.net/country/png/SA.png',
370
- digits: 9,
370
+ digits: 10,
371
371
  supported_by_tap: true
372
372
  },
373
373
  {
@@ -4,3 +4,4 @@ export declare const VAT_ID_LENGTH = 15;
4
4
  export declare const MAX_IBAN_VALUE = 34;
5
5
  export declare const FL_NUMBER_LENGTH = 8;
6
6
  export declare const CR_NUMBER_LENGTH = 10;
7
+ export declare const SAUDI_NUMBER_LENGTH = 9;
@@ -4,3 +4,4 @@ export var VAT_ID_LENGTH = 15;
4
4
  export var MAX_IBAN_VALUE = 34;
5
5
  export var FL_NUMBER_LENGTH = 8;
6
6
  export var CR_NUMBER_LENGTH = 10;
7
+ export var SAUDI_NUMBER_LENGTH = 9;
@@ -51,7 +51,7 @@ import { handleNextScreenStep } from '../../../app/settings';
51
51
  import API from '../../../api';
52
52
  import { CONNECT_STEP_NAMES, IDENTIFICATION_TYPE } from '../../../constants';
53
53
  import { defaultCountry } from '../../../constants';
54
- import { getIndividualName, getClientEmailUrl } from '../../../utils';
54
+ import { getIndividualName, getClientEmailUrl, capitalizeTheFirstLetterOfEachWord } from '../../../utils';
55
55
  export var getCountries = createAsyncThunk('getCountries', function (_, thunkApi) { return __awaiter(void 0, void 0, void 0, function () {
56
56
  var settings, countriesBody, list, businessCountry;
57
57
  return __generator(this, function (_a) {
@@ -486,8 +486,10 @@ export var connectSlice = createSlice({
486
486
  if (!!leadResponse && !leadError) {
487
487
  var name_1 = leadResponse.name, contact = leadResponse.contact;
488
488
  var email = (contact || {}).email;
489
- if (!!name_1)
490
- state.data.individualData.name = (name_1 === null || name_1 === void 0 ? void 0 : name_1.first) + ' ' + (name_1 === null || name_1 === void 0 ? void 0 : name_1.middle) + ' ' + (name_1 === null || name_1 === void 0 ? void 0 : name_1.last);
489
+ if (!!name_1) {
490
+ var capitalizedName = capitalizeTheFirstLetterOfEachWord((name_1 === null || name_1 === void 0 ? void 0 : name_1.first) + ' ' + (name_1 === null || name_1 === void 0 ? void 0 : name_1.middle) + ' ' + (name_1 === null || name_1 === void 0 ? void 0 : name_1.last));
491
+ state.data.individualData.name = capitalizedName;
492
+ }
491
493
  if (!!email)
492
494
  state.data.individualData.email = email;
493
495
  }
@@ -36,7 +36,7 @@ import Input from '../../../shared/Input';
36
36
  import SimpleList from '../../../../components/SimpleList';
37
37
  import { removeAllCharsFromNumber } from '../../../../utils';
38
38
  import { useLanguage } from '../../../../hooks';
39
- import { defaultCountry } from '../../../../constants';
39
+ import { SAUDI_NUMBER_LENGTH } from '../../../../constants';
40
40
  var LabelContainerStyled = styled(Box)(function (_a) {
41
41
  var theme = _a.theme;
42
42
  return ({
@@ -75,19 +75,35 @@ var ExpandIconStyled = styled(ExpandIcon)(function (_a) {
75
75
  var MobileNumber = React.forwardRef(function (_a, ref) {
76
76
  var _b, _c, _d;
77
77
  var countries = _a.countries, rest = __rest(_a, ["countries"]);
78
- var countriesCode = React.useState(countries)[0];
78
+ var countriesCode = React.useState(countries || [])[0];
79
79
  var _e = React.useState(null), anchorEl = _e[0], setAnchorEl = _e[1];
80
80
  var t = useTranslation().t;
81
81
  var isAr = useLanguage().isAr;
82
82
  var _f = useFormContext(), control = _f.control, setValue = _f.setValue;
83
83
  var phoneControl = useController({ name: 'mobile', control: control });
84
84
  var countryCodeControl = useController({ name: 'countryCode', control: control });
85
+ var countryCodeValue = countryCodeControl.field.value;
86
+ var mobileValue = phoneControl.field.value || '';
87
+ var countryName = (isAr ? (_b = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _b === void 0 ? void 0 : _b.arabic : (_c = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _c === void 0 ? void 0 : _c.english) || '';
88
+ var error = (_d = phoneControl.fieldState.error) === null || _d === void 0 ? void 0 : _d.message;
89
+ var isSA = countryCodeValue.iso2 === 'SA';
90
+ var isStartingWithZero = mobileValue.startsWith('0');
91
+ var mobileLen = isSA
92
+ ? isStartingWithZero
93
+ ? countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits
94
+ : SAUDI_NUMBER_LENGTH
95
+ : countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits;
85
96
  React.useEffect(function () {
86
- var _a;
87
- var country = countryCodeControl.field.value || defaultCountry;
88
- setValue('countryCode', country, { shouldValidate: true });
89
- (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, (country === null || country === void 0 ? void 0 : country.digits) || 9);
97
+ if (mobileValue) {
98
+ setValue('mobile', mobileValue, { shouldValidate: true });
99
+ }
90
100
  }, []);
101
+ React.useEffect(function () {
102
+ var _a;
103
+ if ((mobileValue === null || mobileValue === void 0 ? void 0 : mobileValue.length) === 1 && isSA) {
104
+ (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, mobileLen);
105
+ }
106
+ }, [mobileValue]);
91
107
  var onPhoneNumberChange = function (_a) {
92
108
  var target = _a.target;
93
109
  var value = removeAllCharsFromNumber(target.value);
@@ -113,11 +129,7 @@ var MobileNumber = React.forwardRef(function (_a, ref) {
113
129
  countryCodeControl.field.onChange(country);
114
130
  (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, country.digits);
115
131
  };
116
- var countryCodeValue = countryCodeControl.field.value;
117
- var mobileValue = phoneControl.field.value || '';
118
- var countryName = (isAr ? (_b = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _b === void 0 ? void 0 : _b.arabic : (_c = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _c === void 0 ? void 0 : _c.english) || '';
119
- var error = (_d = phoneControl.fieldState.error) === null || _d === void 0 ? void 0 : _d.message;
120
- return (_jsx(Collapse, __assign({ in: rest.show }, { children: _jsxs(ScreenContainer, __assign({ sx: { mb: 3 }, ref: ref }, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: t('signup_enter_mobile') }) }), _jsx(Input, { sx: { direction: 'ltr' }, inputProps: { maxLength: (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits) || 9 }, onChange: onPhoneNumberChange, value: !!anchorEl ? countryName : mobileValue, startAdornment: _jsxs(CountryCodeStyled, __assign({ onClick: function () { return toggleCountryList(); } }, { children: ["+".concat(countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix), !anchorEl && _jsx(ExpandIconStyled, { anchorEl: !!anchorEl })] })), endAdornment: !!anchorEl ? (_jsx(ExpandIconStyled, { onClick: function () { return toggleCountryList(); }, anchorEl: !!anchorEl })) : !error && mobileValue ? (_jsx(CheckIcon, {})) : (mobileValue && _jsx(ClearIcon, { onClick: clearMobileNumber })), placeholder: "".concat((countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.iso2) === 'SA' ? '5' : '0', "00000000"), warningType: 'alert', warningMessage: error && t(error, { length: countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits }) }), _jsx(Collapse, __assign({ in: !!anchorEl }, { children: _jsx(SimpleList, { searchKeyPath: 'name.english', list: countriesCode, onSelectItem: onSelectItem, renderItem: function (item) {
132
+ return (_jsx(Collapse, __assign({ in: rest.show }, { children: _jsxs(ScreenContainer, __assign({ sx: { mb: 3 }, ref: ref }, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: t('signup_enter_mobile') }) }), _jsx(Input, { sx: { direction: 'ltr' }, inputProps: { maxLength: mobileLen }, onChange: onPhoneNumberChange, value: !!anchorEl ? countryName : mobileValue, startAdornment: _jsxs(CountryCodeStyled, __assign({ onClick: function () { return toggleCountryList(); } }, { children: ["+".concat(countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix), !anchorEl && _jsx(ExpandIconStyled, { anchorEl: !!anchorEl })] })), endAdornment: !!anchorEl ? (_jsx(ExpandIconStyled, { onClick: function () { return toggleCountryList(); }, anchorEl: !!anchorEl })) : !error && mobileValue ? (_jsx(CheckIcon, {})) : (mobileValue && _jsx(ClearIcon, { onClick: clearMobileNumber })), placeholder: "".concat(isSA ? '5' : '0', "00000000"), warningType: 'alert', warningMessage: error && t(error, { length: mobileLen }) }), _jsx(Collapse, __assign({ in: !!anchorEl }, { children: _jsx(SimpleList, { searchKeyPath: 'name.english', list: countriesCode, onSelectItem: onSelectItem, renderItem: function (item) {
121
133
  return (_jsxs(_Fragment, { children: [_jsxs(CountryItemContainer, { children: [_jsxs(CountryCodeText, __assign({ isSelected: (item === null || item === void 0 ? void 0 : item.idd_prefix) === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) }, { children: ["+", item.idd_prefix] })), _jsx(CountryNameText, __assign({ isSelected: (item === null || item === void 0 ? void 0 : item.idd_prefix) === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) }, { children: isAr ? item.name.arabic : item.name.english }))] }), item.idd_prefix === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) && _jsx(CheckIcon, {})] }));
122
134
  } }) }))] })) })));
123
135
  });
@@ -74,6 +74,7 @@ var ListType;
74
74
  ListType["CountryCodeList"] = "CountryCodeList";
75
75
  })(ListType || (ListType = {}));
76
76
  var Mobile = function (_a) {
77
+ var settingsStore = useSelector(settingsSelector);
77
78
  var _b = useSelector(connectSelector), data = _b.data, loading = _b.loading, error = _b.error;
78
79
  var _c = React.useState(data.mobileData.countryCode.digits), mobileLength = _c[0], setMobileLength = _c[1];
79
80
  var _d = React.useState(), listType = _d[0], setListType = _d[1];
@@ -85,7 +86,6 @@ var Mobile = function (_a) {
85
86
  });
86
87
  var t = useTranslation().t;
87
88
  var isAr = useLanguage().isAr;
88
- var settingsStore = useSelector(settingsSelector);
89
89
  var handleMenuListClick = function (flag) {
90
90
  setListType(flag);
91
91
  };
@@ -110,8 +110,7 @@ var Mobile = function (_a) {
110
110
  var isBusinessListActive = listType === ListType.BusinessList;
111
111
  var isCountryListActive = listType === ListType.CountryCodeList;
112
112
  var listActive = isBusinessListActive || isCountryListActive;
113
- var isLoading = settingsStore.loading || loading;
114
113
  var disabled = !methods.formState.isValid || !!error;
115
- return (_jsxs(ScreenContainer, { children: [_jsx(MIDTitle, { show: !listActive, title: t('join_our_community'), description: t('ide_terms_and_conditions_description') }), _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsxs(InputsContainerStyled, { children: [_jsx(BusinessCountry, { country: data.businessCountry, show: !isCountryListActive }), _jsx(MobileNumber, { show: !isBusinessListActive, setMobileLength: setMobileLength, countries: data.countries, onListOpen: function () { return handleMenuListClick(ListType.CountryCodeList); }, onListClose: function () { return handleMenuListClick(); } })] }), _jsxs(Collapse, __assign({ in: !listActive }, { children: [_jsx(Button, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disableBack: true, disabled: disabled, loading: isLoading, error: t(error || '') }, { children: t('next') })), _jsxs(OrBoxStyled, { children: [_jsx(DividerStyled, {}), _jsx(TextStyled, { children: t('or') }), _jsx(DividerStyled, {})] }), _jsx(AbsherButton, __assign({ disabled: loading, onClick: function () { return onBack(); }, isAr: isAr }, { children: t('absher_button_label') }))] }))] })) }))] }));
114
+ return (_jsxs(ScreenContainer, { children: [_jsx(MIDTitle, { show: !listActive, title: t('join_our_community'), description: t('ide_terms_and_conditions_description') }), _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsxs(InputsContainerStyled, { children: [_jsx(BusinessCountry, { country: data.businessCountry, show: !isCountryListActive }), _jsx(MobileNumber, { show: !isBusinessListActive, setMobileLength: setMobileLength, countries: data.countries, onListOpen: function () { return handleMenuListClick(ListType.CountryCodeList); }, onListClose: function () { return handleMenuListClick(); } })] }), _jsxs(Collapse, __assign({ in: !listActive }, { children: [_jsx(Button, __assign({ onBackClicked: function () { return onBack(); }, isAr: isAr, disableBack: true, disabled: disabled || settingsStore.loading, loading: loading, error: t(error || '') }, { children: t('next') })), _jsxs(OrBoxStyled, { children: [_jsx(DividerStyled, {}), _jsx(TextStyled, { children: t('or') }), _jsx(DividerStyled, {})] }), _jsx(AbsherButton, __assign({ disabled: settingsStore.loading || loading, onClick: function () { return onBack(); }, isAr: isAr }, { children: t('absher_button_label') }))] }))] })) }))] }));
116
115
  };
117
116
  export default React.memo(Mobile);
@@ -36,6 +36,7 @@ import Input from '../../../shared/Input';
36
36
  import SimpleList from '../../../../components/SimpleList';
37
37
  import { removeAllCharsFromNumber } from '../../../../utils';
38
38
  import { useLanguage } from '../../../../hooks';
39
+ import { SAUDI_NUMBER_LENGTH } from '../../../../constants';
39
40
  var LabelContainerStyled = styled(Box)(function (_a) {
40
41
  var theme = _a.theme;
41
42
  return ({
@@ -74,38 +75,35 @@ var ExpandIconStyled = styled(ExpandIcon)(function (_a) {
74
75
  var MobileNumber = React.forwardRef(function (_a, ref) {
75
76
  var _b, _c, _d;
76
77
  var countries = _a.countries, rest = __rest(_a, ["countries"]);
77
- var _e = React.useState(countries), countriesCode = _e[0], setCountriesCode = _e[1];
78
- var _f = React.useState(null), anchorEl = _f[0], setAnchorEl = _f[1];
78
+ var countriesCode = React.useState(countries || [])[0];
79
+ var _e = React.useState(null), anchorEl = _e[0], setAnchorEl = _e[1];
79
80
  var t = useTranslation().t;
80
81
  var isAr = useLanguage().isAr;
81
- var _g = useFormContext(), control = _g.control, setValue = _g.setValue, getValues = _g.getValues;
82
+ var _f = useFormContext(), control = _f.control, setValue = _f.setValue;
82
83
  var phoneControl = useController({ name: 'mobile', control: control });
83
84
  var countryCodeControl = useController({ name: 'countryCode', control: control });
84
- var businessCountry = getValues('businessCountry');
85
+ var countryCodeValue = countryCodeControl.field.value;
86
+ var mobileValue = phoneControl.field.value || '';
87
+ var countryName = (isAr ? (_b = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _b === void 0 ? void 0 : _b.arabic : (_c = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _c === void 0 ? void 0 : _c.english) || '';
88
+ var error = (_d = phoneControl.fieldState.error) === null || _d === void 0 ? void 0 : _d.message;
89
+ var isSA = countryCodeValue.iso2 === 'SA';
90
+ var isStartingWithZero = mobileValue.startsWith('0');
91
+ var mobileLen = isSA
92
+ ? isStartingWithZero
93
+ ? countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits
94
+ : SAUDI_NUMBER_LENGTH
95
+ : countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits;
85
96
  React.useEffect(function () {
86
- var _a;
87
- if (phoneControl.field.value) {
88
- setValue('mobile', phoneControl.field.value, { shouldValidate: true });
89
- }
90
- if (countryCodeControl.field.value) {
91
- var country = countryCodeControl.field.value;
92
- setValue('countryCode', country, { shouldValidate: true });
93
- (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, (country === null || country === void 0 ? void 0 : country.digits) || 10);
97
+ if (mobileValue) {
98
+ setValue('mobile', mobileValue, { shouldValidate: true });
94
99
  }
95
100
  }, []);
96
101
  React.useEffect(function () {
97
102
  var _a;
98
- var mobile = phoneControl.field.value;
99
- if (mobile == null) {
100
- setValue('countryCode', businessCountry);
101
- (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, (businessCountry === null || businessCountry === void 0 ? void 0 : businessCountry.digits) || 10);
103
+ if (mobileValue.length === 1 && isSA) {
104
+ (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, mobileLen);
102
105
  }
103
- }, [businessCountry]);
104
- React.useEffect(function () {
105
- if (countriesCode.length === 0) {
106
- setCountriesCode(countries);
107
- }
108
- }, [countries]);
106
+ }, [mobileValue]);
109
107
  var onPhoneNumberChange = function (_a) {
110
108
  var target = _a.target;
111
109
  var value = removeAllCharsFromNumber(target.value);
@@ -128,14 +126,10 @@ var MobileNumber = React.forwardRef(function (_a, ref) {
128
126
  var _a;
129
127
  onCloseCountryList();
130
128
  setValue('mobile', '');
131
- (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, (country === null || country === void 0 ? void 0 : country.digits) || 10);
132
129
  countryCodeControl.field.onChange(country);
130
+ (_a = rest.setMobileLength) === null || _a === void 0 ? void 0 : _a.call(rest, country.digits);
133
131
  };
134
- var countryCodeValue = countryCodeControl.field.value;
135
- var mobileValue = phoneControl.field.value || '';
136
- var countryName = (isAr ? (_b = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _b === void 0 ? void 0 : _b.arabic : (_c = countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.name) === null || _c === void 0 ? void 0 : _c.english) || '';
137
- var error = (_d = phoneControl.fieldState.error) === null || _d === void 0 ? void 0 : _d.message;
138
- return (_jsx(Collapse, __assign({ in: rest.show }, { children: _jsxs(ScreenContainer, __assign({ ref: ref }, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: t('signup_enter_mobile') }) }), _jsx(Input, { sx: { direction: 'ltr' }, inputProps: { maxLength: (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits) || 10 }, onChange: onPhoneNumberChange, value: !!anchorEl ? countryName : mobileValue, startAdornment: _jsxs(CountryCodeStyled, __assign({ onClick: function () { return toggleCountryList(); } }, { children: ["+".concat(countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix), !anchorEl && _jsx(ExpandIconStyled, { anchorEl: !!anchorEl })] })), endAdornment: !!anchorEl ? (_jsx(ExpandIconStyled, { onClick: function () { return toggleCountryList(); }, anchorEl: !!anchorEl })) : !error && mobileValue ? (_jsx(CheckIcon, {})) : (mobileValue && _jsx(ClearIcon, { onClick: clearMobileNumber })), placeholder: "".concat((countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.iso2) === 'SA' ? '5' : '0', "00000000"), warningType: 'alert', warningMessage: error && t(error, { length: countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.digits }) }), _jsx(Collapse, __assign({ in: !!anchorEl }, { children: _jsx(SimpleList, { searchKeyPath: 'name.english', list: countriesCode, onSelectItem: onSelectItem, renderItem: function (item) {
132
+ return (_jsx(Collapse, __assign({ in: rest.show }, { children: _jsxs(ScreenContainer, __assign({ ref: ref }, { children: [_jsx(LabelContainerStyled, { children: _jsx(InputLabelStyled, { children: t('signup_enter_mobile') }) }), _jsx(Input, { sx: { direction: 'ltr' }, inputProps: { maxLength: mobileLen }, onChange: onPhoneNumberChange, value: !!anchorEl ? countryName : mobileValue, startAdornment: _jsxs(CountryCodeStyled, __assign({ onClick: function () { return toggleCountryList(); } }, { children: ["+".concat(countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix), !anchorEl && _jsx(ExpandIconStyled, { anchorEl: !!anchorEl })] })), endAdornment: !!anchorEl ? (_jsx(ExpandIconStyled, { onClick: function () { return toggleCountryList(); }, anchorEl: !!anchorEl })) : !error && mobileValue ? (_jsx(CheckIcon, {})) : (mobileValue && _jsx(ClearIcon, { onClick: clearMobileNumber })), placeholder: "".concat(isSA ? '5' : '0', "00000000"), warningType: 'alert', warningMessage: error && t(error, { length: mobileLen }) }), _jsx(Collapse, __assign({ in: !!anchorEl }, { children: _jsx(SimpleList, { searchKeyPath: 'name.english', list: countriesCode, onSelectItem: onSelectItem, renderItem: function (item) {
139
133
  return (_jsxs(_Fragment, { children: [_jsxs(CountryItemContainer, { children: [_jsxs(CountryCodeText, __assign({ isSelected: (item === null || item === void 0 ? void 0 : item.idd_prefix) === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) }, { children: ["+", item.idd_prefix] })), _jsx(CountryNameText, __assign({ isSelected: (item === null || item === void 0 ? void 0 : item.idd_prefix) === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) }, { children: isAr ? item.name.arabic : item.name.english }))] }), item.idd_prefix === (countryCodeValue === null || countryCodeValue === void 0 ? void 0 : countryCodeValue.idd_prefix) && _jsx(CheckIcon, {})] }));
140
134
  } }) }))] })) })));
141
135
  });
@@ -87,7 +87,6 @@ var NID = function (_a) {
87
87
  dispatch(handlePrevScreenStep('CONNECT_MOBILE_STEP'));
88
88
  };
89
89
  var disabled = !methods.formState.isValid || !!error;
90
- var isLoading = settingsStore.loading || loading;
91
- return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsx(BusinessCountry, { show: !collapse, country: data.businessCountry }), _jsx(Collapse, __assign({ in: !collapse }, { children: _jsx(IDNumber, { show: !collapse }) })), _jsx(DOB, { onDateClicked: handleCollapseOpenClose }), _jsxs(Collapse, __assign({ in: !collapse }, { children: [_jsx(Button, __assign({ loading: isLoading, isAr: isAr, disableBack: true, disabled: disabled, error: t(error || '') }, { children: t('next') })), _jsxs(OrBoxStyled, { children: [_jsx(DividerStyled, {}), _jsx(TextStyled, { children: t('or') }), _jsx(DividerStyled, {})] }), _jsx(AbsherButton, __assign({ onClick: function () { return onBack(); }, disabled: loading, hideIcon: true, isAr: isAr }, { children: t('mobile_button_label') }))] }))] })) })) }));
90
+ return (_jsx(ScreenContainer, { children: _jsx(FormProvider, __assign({}, methods, { children: _jsxs(FormStyled, __assign({ onSubmit: methods.handleSubmit(onSubmit) }, { children: [_jsx(BusinessCountry, { show: !collapse, country: data.businessCountry }), _jsx(Collapse, __assign({ in: !collapse }, { children: _jsx(IDNumber, { show: !collapse }) })), _jsx(DOB, { onDateClicked: handleCollapseOpenClose }), _jsxs(Collapse, __assign({ in: !collapse }, { children: [_jsx(Button, __assign({ loading: loading, isAr: isAr, disableBack: true, disabled: disabled || settingsStore.loading, error: t(error || '') }, { children: t('next') })), _jsxs(OrBoxStyled, { children: [_jsx(DividerStyled, {}), _jsx(TextStyled, { children: t('or') }), _jsx(DividerStyled, {})] }), _jsx(AbsherButton, __assign({ onClick: function () { return onBack(); }, disabled: loading || settingsStore.loading, hideIcon: true, isAr: isAr }, { children: t('mobile_button_label') }))] }))] })) })) }));
92
91
  };
93
92
  export default React.memo(NID);
@@ -18,6 +18,8 @@ import { useLanguage } from '../../../hooks';
18
18
  import Text from '../../../components/Text';
19
19
  import Container from '../Containers/ScreenContainer';
20
20
  import { AbsherButton } from '../../shared/Button';
21
+ import Icon from '../../../components/Icon';
22
+ import { ICONS_NAMES } from '../../../constants';
21
23
  var MailBoxStyled = styled(Box)(function () { return ({
22
24
  width: '100%'
23
25
  }); });
@@ -32,7 +34,7 @@ var TextContainerStyled = styled(Box)(function (_a) {
32
34
  borderRadius: theme.spacing(0, 0, 1.25, 1.25)
33
35
  },
34
36
  _b[theme.breakpoints.up('sm')] = {
35
- marginBottom: theme.spacing(6)
37
+ marginBottom: theme.spacing(7.5)
36
38
  },
37
39
  _b);
38
40
  });
@@ -48,10 +50,18 @@ var ContainerStyled = styled(Container)(function (_a) {
48
50
  alignItems: 'center'
49
51
  });
50
52
  });
53
+ var IconStyled = styled(Icon)(function (_a) {
54
+ var theme = _a.theme;
55
+ return ({
56
+ width: theme.spacing(10),
57
+ height: theme.spacing(10),
58
+ marginBlockEnd: theme.spacing(7.5)
59
+ });
60
+ });
51
61
  var ThankYou = function (_a) {
52
62
  var onSuccess = _a.onSuccess, title = _a.title;
53
63
  var t = useTranslation().t;
54
64
  var isAr = useLanguage().isAr;
55
- return (_jsxs(ContainerStyled, { children: [title && (_jsx(TextContainerStyled, { children: _jsxs(TitleStyled, { children: [title, " "] }) })), _jsx(MailBoxStyled, { children: _jsx(AbsherButton, __assign({ hideIcon: true, isAr: isAr, onClick: onSuccess }, { children: t('open_mail_box') })) })] }));
65
+ return (_jsxs(ContainerStyled, { children: [title && (_jsx(TextContainerStyled, { children: _jsxs(TitleStyled, { children: [title, " "] }) })), _jsx(IconStyled, { src: ICONS_NAMES.EMAIL_ICON, alt: 'loading...' }), _jsx(MailBoxStyled, { children: _jsx(AbsherButton, __assign({ hideIcon: true, isAr: isAr, onClick: onSuccess }, { children: t('open_mail_box') })) })] }));
56
66
  };
57
67
  export default React.memo(ThankYou);
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { useEffect } from 'react';
24
- import { handleActiveFlowScreens, settingsSelector, getClientIp, getBrowserFingerPrint, getOperator, handleSetAppConfig, handleLanguage } from '../app/settings';
24
+ import { handleActiveFlowScreens, settingsSelector, getClientIp, getLocale, getBrowserFingerPrint, getOperator, handleSetAppConfig, handleLanguage } from '../app/settings';
25
25
  import { useAppDispatch } from './useAppDispatch';
26
26
  import { useAppSelector } from './useAppSelector';
27
27
  export var useAppConfig = function (_a) {
@@ -31,6 +31,7 @@ export var useAppConfig = function (_a) {
31
31
  var deviceInfo = data.deviceInfo, language = data.language;
32
32
  var device = deviceInfo.device, browser = deviceInfo.browser;
33
33
  useEffect(function () {
34
+ dispatch(getLocale());
34
35
  dispatch(handleActiveFlowScreens(navigation));
35
36
  dispatch(getClientIp());
36
37
  dispatch(getBrowserFingerPrint(appInfo));
@@ -0,0 +1,2 @@
1
+ import { LocalProps } from '../@types';
2
+ export declare const updateLocale: (locale: LocalProps) => void;
@@ -0,0 +1,21 @@
1
+ import { initReactI18next } from 'react-i18next';
2
+ import i18n from '../i18n';
3
+ export var updateLocale = function (locale) {
4
+ if (i18n.isInitialized) {
5
+ i18n.removeResourceBundle('*', 'translation');
6
+ i18n.addResourceBundle('en', 'translation', locale.en.translation);
7
+ i18n.addResourceBundle('ar', 'translation', locale.ar.translation);
8
+ }
9
+ else {
10
+ i18n.use(initReactI18next).init({
11
+ resources: locale,
12
+ fallbackLng: 'en',
13
+ initImmediate: false,
14
+ preload: ['ar', 'en'],
15
+ debug: false,
16
+ interpolation: {
17
+ escapeValue: false
18
+ }
19
+ });
20
+ }
21
+ };
@@ -1,4 +1,3 @@
1
- export declare const string = "";
2
1
  export declare const maskPhone: (str?: string) => string;
3
2
  export declare const maskID: (str: string) => string;
4
3
  export declare const getIndividualName: (name: string) => {
@@ -9,3 +8,4 @@ export declare const getIndividualName: (name: string) => {
9
8
  export declare const convertNumbers2English: (str: string) => string;
10
9
  export declare const getParameterByName: (name: string) => string | null;
11
10
  export declare const getClientEmailUrl: () => string;
11
+ export declare const capitalizeTheFirstLetterOfEachWord: (words: string) => string;
@@ -1,4 +1,3 @@
1
- export var string = '';
2
1
  export var maskPhone = function (str) {
3
2
  if (str === void 0) { str = ''; }
4
3
  var lastTwo = str.substring(str.length - 2, str.length);
@@ -51,3 +50,10 @@ export var getClientEmailUrl = function () {
51
50
  }
52
51
  return origin + '/auth/business?token=';
53
52
  };
53
+ export var capitalizeTheFirstLetterOfEachWord = function (words) {
54
+ var separateWord = words.toLowerCase().split(' ');
55
+ for (var i = 0; i < separateWord.length; i++) {
56
+ separateWord[i] = separateWord[i].charAt(0).toUpperCase() + separateWord[i].substring(1);
57
+ }
58
+ return separateWord.join(' ');
59
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "1.0.30",
3
+ "version": "1.0.31",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",