ordering-ui-react-native 0.23.58 → 0.23.59

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.23.58",
3
+ "version": "0.23.59",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -264,14 +264,11 @@ const CheckoutUI = (props: any) => {
264
264
  ReactNativeHapticFeedback.trigger(impact || "impactLight", options);
265
265
  }
266
266
 
267
- const handleSuccessSignup = (user: any) => {
268
- login({
267
+ const handleSuccessSignup = async (user: any) => {
268
+ await login({
269
269
  user,
270
270
  token: user?.session?.access_token
271
271
  })
272
- if (openModal?.isGuest && requiredFields?.length === 0) {
273
- openModal?.isGuest && handlePlaceOrderAsGuest()
274
- }
275
272
  setOpenModal({ ...openModal, signup: false, isGuest: false })
276
273
  }
277
274
 
@@ -73,7 +73,8 @@ const LoginFormUI = (props: LoginParams) => {
73
73
  generateOtpCode,
74
74
  useLoginOtpEmail,
75
75
  useLoginOtpCellphone,
76
- isGuest
76
+ isGuest,
77
+ setCellphoneStartZero
77
78
  } = props;
78
79
 
79
80
  const [, { showToast }] = useToast();
@@ -300,6 +301,11 @@ const LoginFormUI = (props: LoginParams) => {
300
301
  setTabLayouts(_tabLayouts)
301
302
  }
302
303
 
304
+ const handleChangePhoneNumber = (number : any, rawNumber: any) => {
305
+ setPhoneInputData(number)
306
+ setCellphoneStartZero && setCellphoneStartZero(rawNumber?.number && rawNumber?.countryCallingCode ? rawNumber?.number : null)
307
+ }
308
+
303
309
  useEffect(() => {
304
310
  if (configs && Object.keys(configs).length > 0 && enableReCaptcha) {
305
311
  if (configs?.security_recaptcha_type?.value === 'v3' &&
@@ -586,7 +592,7 @@ const LoginFormUI = (props: LoginParams) => {
586
592
  <View style={{ marginBottom: 28 }}>
587
593
  <PhoneInputNumber
588
594
  data={phoneInputData}
589
- handleData={(val: any) => setPhoneInputData(val)}
595
+ handleData={handleChangePhoneNumber}
590
596
  textInputProps={{
591
597
  returnKeyType: 'next',
592
598
  onSubmitEditing: () => passwordRef?.current?.focus?.(),
@@ -42,6 +42,8 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
42
42
  })
43
43
  const isDisableNumberValidation = parseInt(configs?.validation_phone_number_lib?.value ?? 1, 10)
44
44
  const countriesWithSubOptions = ['PR']
45
+ const codesStartsWithZero: any = ['44']
46
+
45
47
  const style = StyleSheet.create({
46
48
  input: {
47
49
  backgroundColor: theme.colors.white,
@@ -69,13 +71,22 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
69
71
  useEffect(() => {
70
72
  if ((defaultValue && userphoneNumber) || !defaultValue) {
71
73
  if (userphoneNumber) {
72
- const checkValid = phoneInput.current?.isValidNumber(userphoneNumber);
74
+ const validationsForUK = ['01', '02', '07', '0800', '0808', '0845', '0870', '0871']
75
+
76
+ let isPossibly = false
77
+ let numberWithoutCountryCode = ''
73
78
  const callingCode = phoneInput.current?.getCallingCode();
79
+ const cellphone = userphoneNumber.slice(0, 0) + userphoneNumber.slice(1, userphoneNumber.length)
80
+ if (codesStartsWithZero.includes(callingCode)) {
81
+ numberWithoutCountryCode = cellphone.replace(callingCode || '', '')
82
+ const result = validationsForUK.some(areaCode => numberWithoutCountryCode?.startsWith(areaCode))
83
+ isPossibly = result && numberWithoutCountryCode?.length >= 10 && numberWithoutCountryCode?.length < 12
84
+ }
85
+ const checkValid = phoneInput.current?.isValidNumber(userphoneNumber);
74
86
  const formattedNumber = phoneInput.current?.getNumberAfterPossiblyEliminatingZero();
75
87
  const regex = /^[0-9]*$/
76
- const cellphone = userphoneNumber.slice(0, 0) + userphoneNumber.slice(1, userphoneNumber.length)
77
88
  const validNumber = regex.test(cellphone)
78
- if (((!checkValid && formattedNumber?.number) || !validNumber) && !!isDisableNumberValidation) {
89
+ if (((!checkValid && formattedNumber?.number && !isPossibly) || !validNumber) && !!isDisableNumberValidation) {
79
90
  handleData && handleData({
80
91
  ...data,
81
92
  error: t('INVALID_ERROR_PHONE_NUMBER', 'The Phone Number field is invalid')
@@ -89,6 +100,9 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
89
100
  country_phone_code: callingCode,
90
101
  cellphone: !isDisableNumberValidation ? cellphone.slice(callingCode?.length) : formattedNumber?.number
91
102
  }
103
+ }, {
104
+ countryCallingCode: callingCode,
105
+ number: numberWithoutCountryCode,
92
106
  })
93
107
  } else {
94
108
  handleData && handleData({
@@ -83,7 +83,8 @@ const SignupFormUI = (props: SignupParams) => {
83
83
  useSignUpFullDetails,
84
84
  useSignUpOtpEmail,
85
85
  useSignUpOtpCellphone,
86
- isGuest
86
+ isGuest,
87
+ setCellphoneStartZero
87
88
  } = props;
88
89
 
89
90
  const theme = useTheme();
@@ -366,6 +367,19 @@ const SignupFormUI = (props: SignupParams) => {
366
367
  handleReCaptcha && handleReCaptcha({ code: token, version: recaptchaConfig?.version })
367
368
  }
368
369
 
370
+ const handleChangePhoneNumber = (number : any, rawNumber: any) => {
371
+ setPhoneInputData({
372
+ ...phoneInputData,
373
+ ...number,
374
+ phone: {
375
+ ...phoneInputData.phone,
376
+ ...number.phone,
377
+ country_code: phoneInputData.phone.country_code
378
+ }
379
+ })
380
+ setCellphoneStartZero && setCellphoneStartZero(rawNumber?.number && rawNumber?.countryCallingCode ? rawNumber?.number : null)
381
+ }
382
+
369
383
  useEffect(() => {
370
384
  if (configs && Object.keys(configs).length > 0 && enableReCaptcha) {
371
385
  if (configs?.security_recaptcha_type?.value === 'v3' &&
@@ -657,15 +671,7 @@ const SignupFormUI = (props: SignupParams) => {
657
671
  <View style={{ marginBottom: 25 }}>
658
672
  <PhoneInputNumber
659
673
  data={phoneInputData}
660
- handleData={(val: any) => setPhoneInputData({
661
- ...phoneInputData,
662
- ...val,
663
- phone: {
664
- ...phoneInputData.phone,
665
- ...val.phone,
666
- country_code: phoneInputData.phone.country_code
667
- }
668
- })}
674
+ handleData={handleChangePhoneNumber}
669
675
  forwardRef={phoneRef}
670
676
  changeCountry={(val: any) => setPhoneInputData({
671
677
  ...phoneInputData,
@@ -66,7 +66,7 @@ export const StripeCardsListUI = (props: any) => {
66
66
  useEffect(() => {
67
67
  const hasCardSelected = cardsList?.cards?.some?.((card : any) => card?.id === paySelected?.data?.id)
68
68
  setUserHasCards && setUserHasCards(cardsList?.cards?.length > 0 && hasCardSelected)
69
- }, [cardsList?.cards?.length])
69
+ }, [cardsList?.cards?.length, paySelected])
70
70
 
71
71
  return (
72
72
  <>
@@ -42,7 +42,8 @@ export const UserFormDetailsUI = (props: any) => {
42
42
  isGuest,
43
43
  isOrderTypeValidationField,
44
44
  checkoutFields,
45
- isCheckoutPlace
45
+ isCheckoutPlace,
46
+ setCellphoneStartZero
46
47
  } = props;
47
48
 
48
49
  const theme = useTheme();
@@ -185,7 +186,7 @@ export const UserFormDetailsUI = (props: any) => {
185
186
  formState.changes?.cellphone === null &&
186
187
  ((validationFields?.fields?.checkout?.cellphone?.enabled &&
187
188
  validationFields?.fields?.checkout?.cellphone?.required) ||
188
- (configs?.verification_phone_required?.value === '1' && !user?.guest_id))
189
+ (configs?.verification_phone_required?.value === '1' && !user?.guest_id))
189
190
  ) {
190
191
  content = content + `${t('VALIDATION_ERROR_MOBILE_PHONE_REQUIRED', 'The field Phone Number is required.',)}\n`
191
192
  showToast(ToastType.Error, content);
@@ -207,7 +208,7 @@ export const UserFormDetailsUI = (props: any) => {
207
208
  }
208
209
  };
209
210
 
210
- const handleChangePhoneNumber = (number: any) => {
211
+ const handleChangePhoneNumber = (number: any, rawNumber : any) => {
211
212
  setPhoneInputData(number);
212
213
  setIsChanged(true)
213
214
  let phoneNumber = {
@@ -220,6 +221,7 @@ export const UserFormDetailsUI = (props: any) => {
220
221
  value: number.phone.cellphone,
221
222
  },
222
223
  };
224
+ setCellphoneStartZero && setCellphoneStartZero(rawNumber?.number && rawNumber?.countryCallingCode ? rawNumber?.number : null)
223
225
  handleChangeInput(phoneNumber, true);
224
226
  };
225
227
 
@@ -428,7 +430,7 @@ export const UserFormDetailsUI = (props: any) => {
428
430
  <OText size={14} lineHeight={21} weight={'500'} color={theme.colors.textNormal}>{t('PHONE', 'Phone')}</OText>
429
431
  <PhoneInputNumber
430
432
  data={phoneInputData}
431
- handleData={(val: any) => handleChangePhoneNumber(val)}
433
+ handleData={handleChangePhoneNumber}
432
434
  changeCountry={(val: any) => changeCountry(val)}
433
435
  defaultValue={phoneUpdate ? '' : cellphoneValue()}
434
436
  defaultCode={user?.country_code ?? user?.country_phone_code ?? null}
@@ -25,7 +25,8 @@ export interface LoginParams {
25
25
  generateOtpCode: (values?: any) => void,
26
26
  useLoginOtpEmail?: boolean,
27
27
  useLoginOtpCellphone?: boolean,
28
- useLoginOtp?: boolean
28
+ useLoginOtp?: boolean,
29
+ setCellphoneStartZero?: any
29
30
  }
30
31
  export interface ProfileParams {
31
32
  navigation?: any;
@@ -131,6 +132,7 @@ export interface SignupParams {
131
132
  setSignUpTab?: (in1: string) => void;
132
133
  setWillVerifyOtpState?: (in1: boolean) => void;
133
134
  setOtpState?: (in1: string) => void;
135
+ setCellphoneStartZero?: any
134
136
  }
135
137
 
136
138
  export interface PhoneInputParams {