@tap-payments/auth-jsconnect 2.8.45-test → 2.8.48-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.
@@ -17,8 +17,8 @@ import { useTranslation } from 'react-i18next';
17
17
  import { handleCurrentActiveScreen, handlePrevScreenStep, settingsSelector } from '../../../../app/settings';
18
18
  import Box from '@mui/material/Box';
19
19
  import { alpha, styled } from '@mui/material/styles';
20
- import { useAppDispatch, useAppSelector, useSetFromDefaultValues, useLanguage, useFormReadOnly, useDataNoneEditable, useFormErrorAndUpdateReadOnly, useExcludeReadOnlyFelids, useDataVerified } from '../../../../hooks';
21
- import { convertToEnglishDateFormat, deepCopy, getUserName, isKWOrSA, isOtherThanKWOrSA } from '../../../../utils';
20
+ import { useAppDispatch, useAppSelector, useSetFromDefaultValues, useLanguage, useFormReadOnly, useDataNoneEditable, useFormErrorAndUpdateReadOnly, useExcludeReadOnlyFelids, useDataVerified, useFormDirtyCheck } from '../../../../hooks';
21
+ import { convertToEnglishDateFormat, deepCopy, findCountryByIddPrefix, findCountryByIso2, getUserName, isKWOrSA, isOtherThanKWOrSA } from '../../../../utils';
22
22
  import Form from '../../../../components/Form';
23
23
  import Collapse from '../../../../components/Collapse';
24
24
  import Text from '../../../../components/Text';
@@ -50,17 +50,17 @@ var ListType;
50
50
  ListType["NationalityList"] = "NationalityList";
51
51
  })(ListType || (ListType = {}));
52
52
  var IndividualPersonalInfo = function (_a) {
53
- var _b, _c, _d, _e, _f, _g, _h, _j, _k;
53
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
54
54
  var t = useTranslation().t;
55
55
  var isAr = useLanguage().isAr;
56
56
  var dispatch = useAppDispatch();
57
- var _l = useAppSelector(individualSelector), data = _l.data, loading = _l.loading, error = _l.error, cityLoading = _l.cityLoading;
57
+ var _p = useAppSelector(individualSelector), data = _p.data, loading = _p.loading, error = _p.error, cityLoading = _p.cityLoading;
58
58
  var settingsData = useAppSelector(settingsSelector).data;
59
59
  var countries = settingsData.countries;
60
60
  var verify = data.verify, individualPersonalData = data.individualPersonalData;
61
- var _m = verify.responseBody || {}, user = _m.user, flows = _m.flows;
61
+ var _q = verify.responseBody || {}, user = _q.user, flows = _q.flows;
62
62
  var name = individualPersonalData.name, email = individualPersonalData.email, mobile = individualPersonalData.mobile, countryCode = individualPersonalData.countryCode, gender = individualPersonalData.gender, nid = individualPersonalData.nid, issuedCountry = individualPersonalData.issuedCountry, expiryDate = individualPersonalData.expiryDate, dob = individualPersonalData.dob, placeOfBirthCountry = individualPersonalData.placeOfBirthCountry, placeOfBirthCity = individualPersonalData.placeOfBirthCity, nationality = individualPersonalData.nationality;
63
- var _o = user || {}, data_status = _o.data_status, is_authorized = _o.is_authorized, data_verification = _o.data_verification, contact = _o.contact, genderRes = _o.gender, identification = _o.identification, birth = _o.birth, nationalityRes = _o.nationality;
63
+ var _r = user || {}, data_status = _r.data_status, is_authorized = _r.is_authorized, data_verification = _r.data_verification, contact = _r.contact, genderRes = _r.gender, identification = _r.identification, birth = _r.birth, nationalityRes = _r.nationality;
64
64
  var isOtherCountry = React.useMemo(function () { return isOtherThanKWOrSA(settingsData.businessCountry.iso2); }, [settingsData.businessCountry.iso2]);
65
65
  var methods = useForm({
66
66
  resolver: yupResolver(IndividualInfoValidationSchema(isOtherCountry)),
@@ -82,9 +82,51 @@ var IndividualPersonalInfo = function (_a) {
82
82
  });
83
83
  var watch = methods.watch;
84
84
  useSetFromDefaultValues(methods, data.individualPersonalData);
85
- var _p = React.useState(), listActive = _p[0], setListActive = _p[1];
86
- var _q = React.useState(false), dobActive = _q[0], setDobActive = _q[1];
87
- var _r = React.useState(false), expiryDateActive = _r[0], setExpiryDateActive = _r[1];
85
+ var _s = React.useState(), listActive = _s[0], setListActive = _s[1];
86
+ var _t = React.useState(false), dobActive = _t[0], setDobActive = _t[1];
87
+ var _u = React.useState(false), expiryDateActive = _u[0], setExpiryDateActive = _u[1];
88
+ var expDateRes = (identification === null || identification === void 0 ? void 0 : identification.expiry) && convertToEnglishDateFormat(new Date(identification === null || identification === void 0 ? void 0 : identification.expiry));
89
+ var dobDateRes = (birth === null || birth === void 0 ? void 0 : birth.date) && convertToEnglishDateFormat(new Date(birth === null || birth === void 0 ? void 0 : birth.date));
90
+ var resCountryCode = React.useMemo(function () {
91
+ var _a;
92
+ if (!((_a = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _a === void 0 ? void 0 : _a.country_code))
93
+ return {};
94
+ return findCountryByIddPrefix(countries, contact.phone.country_code) || {};
95
+ }, [(_b = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _b === void 0 ? void 0 : _b.country_code]);
96
+ var resIssuedCountry = React.useMemo(function () {
97
+ if (!(identification === null || identification === void 0 ? void 0 : identification.issued_country_code))
98
+ return;
99
+ return findCountryByIso2(countries, identification.issued_country_code);
100
+ }, [identification === null || identification === void 0 ? void 0 : identification.issued_country_code]);
101
+ var resPlaceOfBirthCountry = React.useMemo(function () {
102
+ if (!(birth === null || birth === void 0 ? void 0 : birth.country))
103
+ return;
104
+ return findCountryByIso2(countries, birth.country);
105
+ }, [birth === null || birth === void 0 ? void 0 : birth.country]);
106
+ var resNationality = React.useMemo(function () {
107
+ if (!nationalityRes)
108
+ return;
109
+ return findCountryByIso2(countries, nationalityRes);
110
+ }, [nationalityRes]);
111
+ var isDirty = useFormDirtyCheck(methods, {
112
+ name: getUserName(user, false),
113
+ email: contact === null || contact === void 0 ? void 0 : contact.email,
114
+ mobile: (_c = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _c === void 0 ? void 0 : _c.number,
115
+ countryCode: resCountryCode,
116
+ gender: genderRes === null || genderRes === void 0 ? void 0 : genderRes.toLowerCase(),
117
+ nid: identification === null || identification === void 0 ? void 0 : identification.id,
118
+ issuedCountry: resIssuedCountry,
119
+ expiryDate: expDateRes,
120
+ dob: dobDateRes,
121
+ placeOfBirthCountry: resPlaceOfBirthCountry,
122
+ placeOfBirthCity: ((_d = birth === null || birth === void 0 ? void 0 : birth.city) === null || _d === void 0 ? void 0 : _d.cityId) && { id: birth.city.cityId },
123
+ nationality: resNationality
124
+ }, [
125
+ {
126
+ name: 'placeOfBirthCity',
127
+ keys: ['id']
128
+ }
129
+ ]).isDirty;
88
130
  var originalReadOnly = useFormReadOnly(methods);
89
131
  var noneEditable = useDataNoneEditable(data_status, [
90
132
  'name.en',
@@ -120,25 +162,24 @@ var IndividualPersonalInfo = function (_a) {
120
162
  'nationality',
121
163
  'gender'
122
164
  ]);
123
- var expDateRes = (identification === null || identification === void 0 ? void 0 : identification.expiry) && convertToEnglishDateFormat(new Date(identification === null || identification === void 0 ? void 0 : identification.expiry));
124
- var dobDateRes = (birth === null || birth === void 0 ? void 0 : birth.date) && convertToEnglishDateFormat(new Date(birth === null || birth === void 0 ? void 0 : birth.date));
125
165
  var isNameVerified = dataVerified['name.en'] && dataVerified['name.ar'] && getUserName(user, isAr) === watch('name');
126
166
  var isPhoneNumberVerified = dataVerified['contact.phone.number'] &&
127
167
  dataVerified['contact.phone.country_code'] &&
128
- ((_b = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _b === void 0 ? void 0 : _b.number) === watch('mobile') &&
129
- ((_c = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _c === void 0 ? void 0 : _c.country_code) === ((_e = (_d = watch('countryCode')) === null || _d === void 0 ? void 0 : _d.idd_prefix) === null || _e === void 0 ? void 0 : _e.toString());
168
+ ((_e = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _e === void 0 ? void 0 : _e.number) === watch('mobile') &&
169
+ ((_f = contact === null || contact === void 0 ? void 0 : contact.phone) === null || _f === void 0 ? void 0 : _f.country_code) === ((_h = (_g = watch('countryCode')) === null || _g === void 0 ? void 0 : _g.idd_prefix) === null || _h === void 0 ? void 0 : _h.toString());
130
170
  var isEmailVerified = dataVerified['contact.email'] && (contact === null || contact === void 0 ? void 0 : contact.email) === watch('email');
131
171
  var isGenderVerified = dataVerified['gender'] && genderRes === watch('gender');
132
172
  var isIDVerified = dataVerified['identification.id'] && (identification === null || identification === void 0 ? void 0 : identification.id) === watch('nid');
133
- var isIssuedCountryVerified = dataVerified['identification.issuer_country'] && (identification === null || identification === void 0 ? void 0 : identification.issued_country_code) === ((_f = watch('issuedCountry')) === null || _f === void 0 ? void 0 : _f.iso2);
173
+ var isIssuedCountryVerified = dataVerified['identification.issuer_country'] && (identification === null || identification === void 0 ? void 0 : identification.issued_country_code) === ((_j = watch('issuedCountry')) === null || _j === void 0 ? void 0 : _j.iso2);
134
174
  var isExpiryDateVerified = dataVerified['identification.expiry'] && expDateRes === watch('expiryDate');
135
175
  var isDOBVerified = dataVerified['birth.date'] && dobDateRes === watch('dob');
136
- var isBirthCountryVerified = dataVerified['birth.country'] && (birth === null || birth === void 0 ? void 0 : birth.country) === ((_g = watch('placeOfBirthCountry')) === null || _g === void 0 ? void 0 : _g.iso2);
137
- var isBirthCityVerified = dataVerified['birth.city'] && ((_h = birth === null || birth === void 0 ? void 0 : birth.city) === null || _h === void 0 ? void 0 : _h.cityId) === ((_j = watch('placeOfBirthCity')) === null || _j === void 0 ? void 0 : _j.id);
138
- var isNationalityVerified = dataVerified['nationality'] && nationalityRes === ((_k = watch('nationality')) === null || _k === void 0 ? void 0 : _k.iso2);
176
+ var isBirthCountryVerified = dataVerified['birth.country'] && (birth === null || birth === void 0 ? void 0 : birth.country) === ((_k = watch('placeOfBirthCountry')) === null || _k === void 0 ? void 0 : _k.iso2);
177
+ var isBirthCityVerified = dataVerified['birth.city'] && ((_l = birth === null || birth === void 0 ? void 0 : birth.city) === null || _l === void 0 ? void 0 : _l.cityId) === ((_m = watch('placeOfBirthCity')) === null || _m === void 0 ? void 0 : _m.id);
178
+ var isNationalityVerified = dataVerified['nationality'] && nationalityRes === ((_o = watch('nationality')) === null || _o === void 0 ? void 0 : _o.iso2);
139
179
  var isKWOrSaCountry = React.useMemo(function () { return isKWOrSA(settingsData.businessCountry.iso2); }, [settingsData.businessCountry.iso2]);
140
180
  var onSubmit = function (data) {
141
- dispatch(updateIndividualPersonalInfo(deepCopy(getFelids(data))));
181
+ var formData = __assign(__assign({}, deepCopy(getFelids(data))), { isDirty: isDirty });
182
+ dispatch(updateIndividualPersonalInfo(formData));
142
183
  };
143
184
  React.useEffect(function () {
144
185
  if (error)
@@ -2,5 +2,9 @@ import { FieldValues, UseFormReturn } from 'react-hook-form';
2
2
  type UseFormWithDirtyCheck = {
3
3
  isDirty: boolean;
4
4
  };
5
- export declare const useFormDirtyCheck: <TFieldValues extends FieldValues>(method: UseFormReturn<TFieldValues, any, undefined>, backendData: TFieldValues) => UseFormWithDirtyCheck;
5
+ type CustomAttrProps = {
6
+ name: string;
7
+ keys: string[];
8
+ };
9
+ export declare const useFormDirtyCheck: <TFieldValues extends FieldValues>(method: UseFormReturn<TFieldValues, any, undefined>, backendData: TFieldValues, customAttrs?: CustomAttrProps[]) => UseFormWithDirtyCheck;
6
10
  export {};
@@ -1,28 +1,65 @@
1
1
  import React from 'react';
2
2
  import _ from 'lodash';
3
- export var useFormDirtyCheck = function (method, backendData) {
3
+ export var useFormDirtyCheck = function (method, backendData, customAttrs) {
4
4
  var _a = React.useState(false), isDirty = _a[0], setIsDirty = _a[1];
5
5
  var data = method.watch();
6
- var isValidData = function (data, backendData) {
7
- if (data === undefined)
6
+ var isValidData = function (formValue, backendValue) {
7
+ if (_.isUndefined(formValue))
8
8
  return false;
9
- if (Array.isArray(data) && !data.length)
9
+ if (_.isArray(formValue) && formValue.length === 0)
10
10
  return false;
11
- if (data === '' && !backendData)
11
+ if (_.isObject(formValue) && _.isEmpty(formValue))
12
+ return false;
13
+ if (formValue === '' && !backendValue)
12
14
  return false;
13
15
  return true;
14
16
  };
15
- var deepComparison = function (data, backendData) {
16
- for (var key in backendData) {
17
+ var isArray = function (data, backendData) {
18
+ return backendData && data && _.isArray(backendData) && _.isArray(data);
19
+ };
20
+ var isObject = function (data, backendData) {
21
+ return backendData && data && _.isObject(data) && _.isObject(backendData);
22
+ };
23
+ var mapArrayOfObjectWithKeys = function (items, keys) {
24
+ return _.map(items, function (item) { return _.pick(item, keys); });
25
+ };
26
+ var mapObjectWithKeys = function (item, keys) {
27
+ return _.pick(item, keys);
28
+ };
29
+ var deepComparison = function (data, backendData, customAttrs) {
30
+ var _loop_1 = function (key) {
17
31
  var formValue = data === null || data === void 0 ? void 0 : data[key];
18
32
  var backEndValue = backendData === null || backendData === void 0 ? void 0 : backendData[key];
19
- if (isValidData(formValue, backEndValue) && !_.isEqual(formValue, backEndValue))
20
- return true;
33
+ if (!isValidData(formValue, backEndValue))
34
+ return "continue";
35
+ var customAttr = customAttrs === null || customAttrs === void 0 ? void 0 : customAttrs.find(function (el) { return el.name === key; });
36
+ if (customAttr) {
37
+ var keys = customAttr.keys;
38
+ if (isArray(formValue, backEndValue)) {
39
+ formValue = mapArrayOfObjectWithKeys(formValue, keys);
40
+ backEndValue = mapArrayOfObjectWithKeys(backEndValue, keys);
41
+ if (formValue.length !== backEndValue.length)
42
+ return { value: true };
43
+ if (_.differenceWith(formValue, backEndValue, _.isEqual).length > 0)
44
+ return { value: true };
45
+ }
46
+ if (isObject(formValue, backEndValue)) {
47
+ formValue = mapObjectWithKeys(formValue, keys);
48
+ backEndValue = mapObjectWithKeys(backEndValue, keys);
49
+ }
50
+ }
51
+ if (!_.isEqual(formValue, backEndValue))
52
+ return { value: true };
53
+ };
54
+ for (var key in backendData) {
55
+ var state_1 = _loop_1(key);
56
+ if (typeof state_1 === "object")
57
+ return state_1.value;
21
58
  }
22
59
  return false;
23
60
  };
24
61
  React.useEffect(function () {
25
- var isDirty = deepComparison(data, backendData);
62
+ var isDirty = deepComparison(data, backendData, customAttrs);
26
63
  setIsDirty(isDirty);
27
64
  }, [data, backendData]);
28
65
  return { isDirty: isDirty };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tap-payments/auth-jsconnect",
3
- "version": "2.8.45-test",
3
+ "version": "2.8.48-development",
4
4
  "description": "connect library, auth",
5
5
  "private": false,
6
6
  "main": "build/index.js",
@@ -21,7 +21,7 @@
21
21
  "copy:files": "copyfiles -u 1 src/**/*.css build/",
22
22
  "tsc:alias": "tsc-alias -p tsconfig.json",
23
23
  "ts:build": "rm -rf build && tsc -p tsconfig.json && tsc-alias -p tsconfig.json && yarn copy:files",
24
- "push": "npm publish --access public --tag test"
24
+ "push": "npm publish --access public --tag development"
25
25
  },
26
26
  "keywords": [],
27
27
  "author": {