ordering-ui-react-native 0.21.17 → 0.21.19

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.21.17",
3
+ "version": "0.21.19",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -44,11 +44,11 @@ const LoginFormUI = (props: LoginParams) => {
44
44
  useLoginByCellphone,
45
45
  useLoginByEmail,
46
46
  loginTab,
47
- otpType,
48
- setOtpType,
49
- generateOtpCode,
50
- useLoginOtpEmail,
51
- useLoginOtpCellphone,
47
+ otpType,
48
+ setOtpType,
49
+ generateOtpCode,
50
+ useLoginOtpEmail,
51
+ useLoginOtpCellphone,
52
52
  } = props;
53
53
 
54
54
  const theme = useTheme()
@@ -82,31 +82,32 @@ const LoginFormUI = (props: LoginParams) => {
82
82
  });
83
83
 
84
84
  const isOtpEmail = loginTab === 'otp' && otpType === 'email'
85
- const isOtpCellphone = loginTab === 'otp' && otpType === 'cellphone'
85
+ const isOtpCellphone = loginTab === 'otp' && otpType === 'cellphone'
86
+ const isDeviceLoginEnabled = configs?.device_code_login_enabled?.value === '1'
86
87
 
87
88
  const mainLogin = (values) => {
88
89
  if (loginTab === 'otp') {
89
- if (phoneInputData.error && (loginTab !== 'otp' || (otpType === 'cellphone' && loginTab === 'otp'))) {
90
- showToast(ToastType.Error, t('INVALID_PHONE_NUMBER', 'Invalid phone number'));
91
- return
92
- }
93
- if (loginTab === 'otp') {
94
- generateOtpCode({
95
- ...values,
96
- ...phoneInputData.phone
97
- })
98
- }
99
- setWillVerifyOtpState(true)
100
- } else {
101
- if (phoneInputData.error) {
102
- showToast(ToastType.Error, phoneInputData.error);
103
- return;
104
- }
105
- handleButtonLoginClick({
106
- ...values,
107
- ...phoneInputData.phone,
108
- });
109
- }
90
+ if (phoneInputData.error && (loginTab !== 'otp' || (otpType === 'cellphone' && loginTab === 'otp'))) {
91
+ showToast(ToastType.Error, t('INVALID_PHONE_NUMBER', 'Invalid phone number'));
92
+ return
93
+ }
94
+ if (loginTab === 'otp') {
95
+ generateOtpCode({
96
+ ...values,
97
+ ...phoneInputData.phone
98
+ })
99
+ }
100
+ setWillVerifyOtpState(true)
101
+ } else {
102
+ if (phoneInputData.error) {
103
+ showToast(ToastType.Error, phoneInputData.error);
104
+ return;
105
+ }
106
+ handleButtonLoginClick({
107
+ ...values,
108
+ ...phoneInputData.phone,
109
+ });
110
+ }
110
111
  }
111
112
 
112
113
  const onSubmit = (values: any) => {
@@ -199,23 +200,23 @@ const LoginFormUI = (props: LoginParams) => {
199
200
  borderColor: theme.colors.inputSignup,
200
201
  },
201
202
  borderStyleBase: {
202
- width: 30,
203
- height: 45
204
- },
205
- borderStyleHighLighted: {
206
- borderColor: "#03DAC6",
207
- },
208
- underlineStyleBase: {
209
- width: 45,
210
- height: 60,
211
- borderWidth: 1,
212
- fontSize: 16
213
- },
214
- underlineStyleHighLighted: {
215
- borderColor: theme.colors.primary,
216
- color: theme.colors.primary,
217
- fontSize: 16
218
- },
203
+ width: 30,
204
+ height: 45
205
+ },
206
+ borderStyleHighLighted: {
207
+ borderColor: "#03DAC6",
208
+ },
209
+ underlineStyleBase: {
210
+ width: 45,
211
+ height: 60,
212
+ borderWidth: 1,
213
+ fontSize: 16
214
+ },
215
+ underlineStyleHighLighted: {
216
+ borderColor: theme.colors.primary,
217
+ color: theme.colors.primary,
218
+ fontSize: 16
219
+ },
219
220
  });
220
221
 
221
222
  useEffect(() => {
@@ -311,32 +312,32 @@ const LoginFormUI = (props: LoginParams) => {
311
312
  };
312
313
 
313
314
  const handleChangeOtpType = (type: string) => {
314
- handleChangeTab('otp', type)
315
- setOtpType(type)
316
- }
317
-
318
- const handleLoginOtp = (code: string) => {
319
- handleButtonLoginClick({ code })
320
- setWillVerifyOtpState(false)
321
- }
322
-
323
- const closeAlert = () => {
324
- setAlertState({
325
- open: false,
326
- title: '',
327
- content: []
328
- })
329
- }
315
+ handleChangeTab('otp', type)
316
+ setOtpType(type)
317
+ }
318
+
319
+ const handleLoginOtp = (code: string) => {
320
+ handleButtonLoginClick({ code })
321
+ setWillVerifyOtpState(false)
322
+ }
323
+
324
+ const closeAlert = () => {
325
+ setAlertState({
326
+ open: false,
327
+ title: '',
328
+ content: []
329
+ })
330
+ }
330
331
 
331
332
  useEffect(() => {
332
- if (checkPhoneCodeState?.result?.error) {
333
- setAlertState({
334
- open: true,
335
- content: t(checkPhoneCodeState?.result?.error, checkPhoneCodeState?.result?.error),
336
- title: ''
337
- })
338
- }
339
- }, [checkPhoneCodeState])
333
+ if (checkPhoneCodeState?.result?.error) {
334
+ setAlertState({
335
+ open: true,
336
+ content: t(checkPhoneCodeState?.result?.error, checkPhoneCodeState?.result?.error),
337
+ title: ''
338
+ })
339
+ }
340
+ }, [checkPhoneCodeState])
340
341
 
341
342
  useEffect(() => {
342
343
  const projectInputTimeout = setTimeout(() => {
@@ -346,9 +347,12 @@ const LoginFormUI = (props: LoginParams) => {
346
347
  project: projectName
347
348
  })
348
349
  }
350
+ if (isDeviceLoginEnabled) {
351
+ props.handleChangeTab('device_code')
352
+ }
349
353
  }, 1500)
350
354
  return () => clearTimeout(projectInputTimeout);
351
- }, [projectName])
355
+ }, [projectName, isDeviceLoginEnabled])
352
356
 
353
357
  const logo = (
354
358
  <LogoWrapper>
@@ -442,7 +446,7 @@ const LoginFormUI = (props: LoginParams) => {
442
446
  </View>
443
447
  )}
444
448
 
445
- {(Number(useLoginByEmail) + Number(useLoginOtpEmail) + Number(useLoginOtpCellphone) > 1) && (
449
+ {!isDeviceLoginEnabled && (Number(useLoginByEmail) + Number(useLoginOtpEmail) + Number(useLoginOtpCellphone) > 1) && (
446
450
  <LoginWith>
447
451
  <ScrollView
448
452
  ref={scrollRefTab}
@@ -553,7 +557,7 @@ const LoginFormUI = (props: LoginParams) => {
553
557
  style={{
554
558
  width: '100%',
555
559
  borderBottomColor:
556
- isOtpCellphone
560
+ isOtpCellphone
557
561
  ? theme.colors.black
558
562
  : theme.colors.border,
559
563
  borderBottomWidth: 2,
@@ -592,8 +596,29 @@ const LoginFormUI = (props: LoginParams) => {
592
596
  )}
593
597
  />
594
598
  )}
595
-
596
- {((useLoginByEmail && loginTab === 'email') || (loginTab === 'otp' && otpType === 'email')) && (
599
+ {isDeviceLoginEnabled && (
600
+ <Controller
601
+ control={control}
602
+ render={({ onChange, value }: any) => (
603
+ <OInput
604
+ placeholder={t('DEVICE_CODE', 'Device Code')}
605
+ style={styles.inputStyle}
606
+ value={value}
607
+ inputStyle={{ textAlign: 'center' }}
608
+ onChange={(val: any) => onChange(val)}
609
+ />
610
+ )}
611
+ name="device_code"
612
+ rules={{
613
+ required: t(
614
+ 'VALIDATION_ERROR_DEVICE_CODE_REQUIRED',
615
+ 'The field DEVICE_CODE is required',
616
+ ).replace('_attribute_', t('DEVICE_CODE', 'Device Code')),
617
+ }}
618
+ defaultValue=""
619
+ />
620
+ )}
621
+ {!isDeviceLoginEnabled && ((useLoginByEmail && loginTab === 'email') || (loginTab === 'otp' && otpType === 'email')) && (
597
622
  <Controller
598
623
  control={control}
599
624
  render={({ onChange, value }: any) => (
@@ -628,7 +653,7 @@ const LoginFormUI = (props: LoginParams) => {
628
653
  />
629
654
  )}
630
655
 
631
- {((useLoginByCellphone && loginTab === 'cellphone') || (loginTab === 'otp' && otpType === 'cellphone')) && (
656
+ {!isDeviceLoginEnabled && ((useLoginByCellphone && loginTab === 'cellphone') || (loginTab === 'otp' && otpType === 'cellphone')) && (
632
657
  <View style={{ marginBottom: 20 }}>
633
658
  <PhoneInputNumber
634
659
  data={phoneInputData}
@@ -642,7 +667,7 @@ const LoginFormUI = (props: LoginParams) => {
642
667
  </View>
643
668
  )}
644
669
 
645
- {loginTab !== 'otp' && (
670
+ {!isDeviceLoginEnabled && loginTab !== 'otp' && (
646
671
  <Controller
647
672
  control={control}
648
673
  render={({ onChange, value }: any) => (
@@ -732,26 +757,26 @@ const LoginFormUI = (props: LoginParams) => {
732
757
  )}
733
758
  </View>
734
759
  <OModal
735
- open={willVerifyOtpState}
736
- onClose={() => setWillVerifyOtpState(false)}
737
- entireModal
738
- title={t('ENTER_VERIFICATION_CODE', 'Enter verification code')}
739
- >
740
- <Otp
741
- willVerifyOtpState={willVerifyOtpState}
742
- setWillVerifyOtpState={setWillVerifyOtpState}
743
- handleLoginOtp={handleLoginOtp}
744
- onSubmit={onSubmit}
745
- setAlertState={setAlertState}
746
- />
747
- </OModal>
748
- <Alert
749
- open={alertState.open}
750
- content={alertState.content}
751
- title={alertState.title || ''}
752
- onAccept={closeAlert}
753
- onClose={closeAlert}
754
- />
760
+ open={willVerifyOtpState}
761
+ onClose={() => setWillVerifyOtpState(false)}
762
+ entireModal
763
+ title={t('ENTER_VERIFICATION_CODE', 'Enter verification code')}
764
+ >
765
+ <Otp
766
+ willVerifyOtpState={willVerifyOtpState}
767
+ setWillVerifyOtpState={setWillVerifyOtpState}
768
+ handleLoginOtp={handleLoginOtp}
769
+ onSubmit={onSubmit}
770
+ setAlertState={setAlertState}
771
+ />
772
+ </OModal>
773
+ <Alert
774
+ open={alertState.open}
775
+ content={alertState.content}
776
+ title={alertState.title || ''}
777
+ onAccept={closeAlert}
778
+ onClose={closeAlert}
779
+ />
755
780
  </View>
756
781
  );
757
782
  };
@@ -24,7 +24,8 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
24
24
  noDropIcon,
25
25
  isDisabled,
26
26
  isStartValidation,
27
- changeCountry
27
+ changeCountry,
28
+ updateStateWithSubmit
28
29
  } = props
29
30
 
30
31
  const theme = useTheme();
@@ -95,6 +96,19 @@ export const PhoneInputNumber = (props: PhoneInputParams) => {
95
96
  }
96
97
  }, [userphoneNumber])
97
98
 
99
+ useEffect(() => {
100
+ if (defaultValue && updateStateWithSubmit) {
101
+ phoneInput.current?.setState({
102
+ number: defaultValue,
103
+ countryCode: defaultCode ?
104
+ !isNaN(defaultCode)
105
+ ? transformCountryCode(defaultCode)
106
+ : findExitingCode(defaultCode)
107
+ : findExitingCode(configs?.default_country_code?.value?.toUpperCase())
108
+ })
109
+ }
110
+ }, [defaultValue])
111
+
98
112
  return (
99
113
  <Wrapper onPress={() => forwardRef?.current?.focus?.()}>
100
114
  {(isStartValidation && userphoneNumber === '') && (
@@ -293,7 +293,7 @@ const UserVerificationUI = (props: any) => {
293
293
 
294
294
  useEffect(() => {
295
295
  setupUserPhoneNumber()
296
- }, [user])
296
+ }, [user?.cellphone, user?.country_phone_code])
297
297
 
298
298
  return (
299
299
  <SafeAreaView style={{ flex: 1 }}>
@@ -402,6 +402,7 @@ const UserVerificationUI = (props: any) => {
402
402
  textStyle={{ color: theme.colors.textNormal, fontSize: 12, padding: 0 }}
403
403
  noDropIcon
404
404
  isDisabled
405
+ updateStateWithSubmit
405
406
  />
406
407
  </InputWrapper>
407
408
  </>
@@ -485,6 +486,7 @@ const UserVerificationUI = (props: any) => {
485
486
  user={user}
486
487
  isEdit
487
488
  isVerifiedPhone
489
+ dontToggleEditMode
488
490
  />
489
491
  </View>
490
492
  </ScrollView>
@@ -147,6 +147,7 @@ export interface PhoneInputParams {
147
147
  isDisabled?: any;
148
148
  isStartValidation?: any;
149
149
  changeCountry?: any;
150
+ updateStateWithSubmit?: boolean
150
151
  }
151
152
 
152
153
  export interface LanguageSelectorParams {