ordering-ui-react-native 0.21.14 → 0.21.16

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.14",
3
+ "version": "0.21.16",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -19,6 +19,8 @@ import { BusinessBasicInformation } from '../BusinessBasicInformation'
19
19
  import { BusinessInformationParams } from '../../types'
20
20
  import { GoogleMap } from '../GoogleMap'
21
21
  import { useTheme } from 'styled-components/native';
22
+ import moment from 'moment';
23
+
22
24
  const BusinessInformationUI = (props: BusinessInformationParams) => {
23
25
  const {
24
26
  businessState,
@@ -38,14 +40,13 @@ const BusinessInformationUI = (props: BusinessInformationParams) => {
38
40
  t('FRIDAY_ABBREVIATION', 'Fri'),
39
41
  t('SATURDAY_ABBREVIATION', 'Sat')
40
42
  ]
41
- const is12hours = configs?.format_time?.value?.includes('12')
42
43
 
43
- const scheduleFormatted = ({ hour, minute } : { hour : number | string, minute : number | string}) => {
44
- const checkTime = (val: number | string) => (val < 10 ? `0${val}` : val);
45
- const zz = hour === 0 ? t('AM', 'AM') : hour >= 12 ? t('PM', 'PM') : t('AM', 'AM');
46
- const h = parseInt(`${hour}`);
47
- return is12hours ? `${h === 0 ? 12 : h > 12 ? h - 12 : h}:${checkTime(minute)} ${zz}` : `${checkTime(hour)}:${checkTime(minute)}`;
48
- }
44
+ const formatTime = configs?.general_hour_format?.value
45
+
46
+ const checkTime = (val: number) => (val < 10 ? `0${val}` : val);
47
+ const timeFormated = (time: any) => {
48
+ return moment(`1900-01-01 ${checkTime(time.hour)}:${checkTime(time.minute)}`).format(formatTime)
49
+ }
49
50
 
50
51
  return (
51
52
  <BusinessInformationContainer>
@@ -105,13 +106,13 @@ const BusinessInformationUI = (props: BusinessInformationParams) => {
105
106
  {schedule.enabled ? (
106
107
  schedule.lapses.map( (time: any, k: number) => (
107
108
  <React.Fragment key={k}>
108
- <OText>{scheduleFormatted(time.open)}</OText>
109
+ <OText>{timeFormated(time.open)}</OText>
109
110
  <OText mBottom={10} style={{
110
111
  padding: 3,
111
112
  borderBottomColor: theme.colors.primary,
112
113
  borderBottomWidth: 1
113
114
  }}
114
- >{scheduleFormatted(time.close)}</OText>
115
+ >{timeFormated(time.close)}</OText>
115
116
  </React.Fragment>
116
117
  ))) : ( <OText>{t('CLOSED', 'Closed')}</OText>)}
117
118
  </ScheduleBlock>
@@ -5,20 +5,23 @@ import { useCountdownTimer } from '../../../../../../src/hooks/useCountdownTimer
5
5
  import { useLanguage } from 'ordering-components/native';
6
6
  import { OTPContainer } from './styles';
7
7
  import { OText, OButton, OIcon } from '../../shared';
8
- import OtpInputs from 'react-native-otp-inputs';
8
+ import OtpInputs, { OtpInputsRef } from 'react-native-otp-inputs';
9
9
  import { useTheme } from 'styled-components/native';
10
10
  import { otpParams } from '../../../types'
11
+ import { ActivityIndicator } from 'react-native';
11
12
 
12
13
  export const Otp = (props: otpParams) => {
13
14
  const {
15
+ pinCount,
16
+ otpError,
17
+ setOtpError,
18
+ setAlertState,
14
19
  willVerifyOtpState,
20
+ isCheckingCode,
21
+ setCheckingCode,
15
22
  setWillVerifyOtpState,
16
- onSubmit,
17
23
  handleLoginOtp,
18
- setAlertState,
19
- pinCount,
20
- otpError,
21
- setOtpError
24
+ onSubmit,
22
25
  } = props
23
26
 
24
27
  const theme = useTheme();
@@ -26,8 +29,7 @@ export const Otp = (props: otpParams) => {
26
29
  const [otpLeftTime, _, resetOtpLeftTime]: any = useCountdownTimer(
27
30
  600, willVerifyOtpState)
28
31
 
29
- const [code, setCode] = useState('')
30
- const inputRef = useRef<any>()
32
+ const inputRef = useRef<OtpInputsRef | any>(null)
31
33
 
32
34
  const handleOnSubmit = () => {
33
35
  setAlertState({
@@ -39,7 +41,12 @@ export const Otp = (props: otpParams) => {
39
41
  }
40
42
 
41
43
  const handleChangeCode = (code : string) => {
42
- setCode(code)
44
+ if (code?.length === pinCount) {
45
+ setCheckingCode(true)
46
+ handleLoginOtp(code)
47
+ inputRef.current?.reset && inputRef.current.reset()
48
+ setTimeout(() => inputRef.current?.focus && inputRef.current.focus(), 100)
49
+ }
43
50
  setOtpError(null)
44
51
  }
45
52
 
@@ -58,13 +65,6 @@ export const Otp = (props: otpParams) => {
58
65
  }
59
66
  }, [otpLeftTime])
60
67
 
61
- useEffect(() => {
62
- if (code?.length === (pinCount || 6)) {
63
- handleLoginOtp(code)
64
- inputRef?.current?.reset()
65
- }
66
- }, [code])
67
-
68
68
  const loginStyle = StyleSheet.create({
69
69
  container: {
70
70
  width: '100%',
@@ -95,6 +95,13 @@ export const Otp = (props: otpParams) => {
95
95
  width: '100%',
96
96
  flexDirection: 'row',
97
97
  alignItems: 'center'
98
+ },
99
+ checkingCode: {
100
+ height: 50,
101
+ width: '100%',
102
+ marginVertical: 30,
103
+ justifyContent: 'center',
104
+ alignItems: 'center'
98
105
  }
99
106
  });
100
107
 
@@ -116,14 +123,24 @@ export const Otp = (props: otpParams) => {
116
123
  <OText size={24}>
117
124
  {formatSeconds(otpLeftTime)}
118
125
  </OText>
119
- <OtpInputs
120
- ref={inputRef}
121
- autofillFromClipboard={false}
122
- numberOfInputs={pinCount || 6}
123
- style={loginStyle.container}
124
- inputStyles={loginStyle.underlineStyleBase}
125
- handleChange={handleChangeCode}
126
- />
126
+ {isCheckingCode && (
127
+ <View style={loginStyle.checkingCode}>
128
+ <OText size={18}>
129
+ <ActivityIndicator size="large" color={theme.colors.primary} />
130
+ </OText>
131
+ </View>
132
+ )}
133
+ {!isCheckingCode && (
134
+ <OtpInputs
135
+ ref={inputRef}
136
+ autofillFromClipboard={false}
137
+ numberOfInputs={pinCount}
138
+ style={loginStyle.container}
139
+ returnKeyType={'done'}
140
+ inputStyles={loginStyle.underlineStyleBase}
141
+ handleChange={handleChangeCode}
142
+ />
143
+ )}
127
144
  {!!otpError && (
128
145
  <OText
129
146
  color={theme?.colors?.error}
@@ -150,3 +167,7 @@ export const Otp = (props: otpParams) => {
150
167
  </SafeAreaView>
151
168
  )
152
169
  }
170
+
171
+ Otp.defaultProps = {
172
+ pinCount: 6
173
+ }
@@ -104,6 +104,8 @@ const LoginFormUI = (props: LoginParams) => {
104
104
  const isOtpEmail = loginTab === 'otp' && otpType === 'email'
105
105
  const isOtpCellphone = loginTab === 'otp' && otpType === 'cellphone'
106
106
 
107
+ const [isCheckingCode, setCheckingCode] = useState(false)
108
+
107
109
  const googleLoginEnabled = configs?.google_login_enabled?.value === '1' || !configs?.google_login_enabled?.enabled
108
110
  const facebookLoginEnabled = configs?.facebook_login_enabled?.value === '1' || !configs?.facebook_login_enabled?.enabled
109
111
  const appleLoginEnabled = configs?.apple_login_enabled?.value === '1' || !configs?.apple_login_enabled?.enabled
@@ -268,6 +270,7 @@ const LoginFormUI = (props: LoginParams) => {
268
270
  const handleLoginOtp = async (code: string) => {
269
271
  if (!code) return
270
272
  const logged = await handleButtonLoginClick({ code })
273
+ setCheckingCode(false)
271
274
  if (logged) {
272
275
  setWillVerifyOtpState(false)
273
276
  } else {
@@ -854,6 +857,8 @@ const LoginFormUI = (props: LoginParams) => {
854
857
  animationType='slide'
855
858
  >
856
859
  <Otp
860
+ isCheckingCode={isCheckingCode}
861
+ setCheckingCode={setCheckingCode}
857
862
  willVerifyOtpState={willVerifyOtpState}
858
863
  otpError={otpError}
859
864
  setOtpError={setOtpError}
@@ -732,6 +732,8 @@ export interface otpParams {
732
732
  pinCount: number;
733
733
  otpError: any,
734
734
  setOtpError: any
735
+ isCheckingCode: boolean
736
+ setCheckingCode: (value: boolean) => void
735
737
  }
736
738
 
737
739
  export interface FavoriteParams {