ordering-ui-react-native 0.21.15 → 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
|
@@ -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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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}
|