ordering-ui-react-native 0.12.95 → 0.12.96
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
|
@@ -418,6 +418,7 @@ const LoginFormUI = (props: LoginParams) => {
|
|
|
418
418
|
open={isModalVisible}
|
|
419
419
|
onClose={() => setIsModalVisible(false)}
|
|
420
420
|
entireModal
|
|
421
|
+
title={t('VERIFY_PHONE', 'Verify Phone')}
|
|
421
422
|
>
|
|
422
423
|
<VerifyPhone
|
|
423
424
|
phone={phoneInputData.phone}
|
|
@@ -426,6 +427,7 @@ const LoginFormUI = (props: LoginParams) => {
|
|
|
426
427
|
handleCheckPhoneCode={handleCheckPhoneCode}
|
|
427
428
|
setCheckPhoneCodeState={setCheckPhoneCodeState}
|
|
428
429
|
handleVerifyCodeClick={handleVerifyCodeClick}
|
|
430
|
+
onClose={() => setIsModalVisible(false)}
|
|
429
431
|
/>
|
|
430
432
|
</OModal>
|
|
431
433
|
<Spinner visible={isLoadingSocialButton} />
|
|
@@ -440,4 +442,4 @@ export const LoginForm = (props: any) => {
|
|
|
440
442
|
handleSuccessLogin: () => _removeStoreData('isGuestUser')
|
|
441
443
|
};
|
|
442
444
|
return <LoginFormController {...loginProps} />;
|
|
443
|
-
};
|
|
445
|
+
};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
import React, { useEffect, useState } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { useEffect, useState, useRef } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
SafeAreaView,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
Text,
|
|
6
|
+
View,
|
|
7
|
+
TextInput,
|
|
8
|
+
Pressable,
|
|
9
|
+
} from 'react-native';
|
|
3
10
|
import { useLanguage } from 'ordering-components/native';
|
|
4
11
|
import Spinner from 'react-native-loading-spinner-overlay';
|
|
5
12
|
import { getTraduction } from '../../utils'
|
|
@@ -17,6 +24,7 @@ import {
|
|
|
17
24
|
import { useTheme } from 'styled-components/native';
|
|
18
25
|
|
|
19
26
|
const TIME_COUNTDOWN = 60 * 10 // 10 minutes
|
|
27
|
+
const CODE_LENGTH = 4;
|
|
20
28
|
|
|
21
29
|
export const VerifyPhone = (props: any) => {
|
|
22
30
|
const {
|
|
@@ -26,36 +34,91 @@ export const VerifyPhone = (props: any) => {
|
|
|
26
34
|
checkPhoneCodeState,
|
|
27
35
|
setCheckPhoneCodeState,
|
|
28
36
|
handleCheckPhoneCode,
|
|
29
|
-
handleVerifyCodeClick
|
|
37
|
+
handleVerifyCodeClick,
|
|
38
|
+
onClose
|
|
30
39
|
} = props
|
|
31
40
|
|
|
32
41
|
const theme = useTheme();
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
const [, t] = useLanguage()
|
|
43
|
+
const ref = useRef<TextInput>(null);
|
|
44
|
+
|
|
45
|
+
const style = StyleSheet.create({
|
|
46
|
+
container: {
|
|
47
|
+
flex: 1,
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'center',
|
|
50
|
+
},
|
|
51
|
+
inputsContainer: {
|
|
52
|
+
width: '80%',
|
|
53
|
+
flexDirection: 'row',
|
|
54
|
+
justifyContent: 'space-between',
|
|
55
|
+
},
|
|
56
|
+
inputContainer: {
|
|
57
|
+
borderWidth: 2,
|
|
41
58
|
borderRadius: 20,
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
59
|
+
padding: 20,
|
|
60
|
+
borderColor: theme.colors.disabled,
|
|
61
|
+
},
|
|
62
|
+
inputContainerFocused: {
|
|
63
|
+
borderColor: theme.colors.primary,
|
|
64
|
+
},
|
|
65
|
+
inputText: {
|
|
66
|
+
fontSize: 24,
|
|
67
|
+
},
|
|
68
|
+
hiddenCodeInput: {
|
|
69
|
+
position: 'absolute',
|
|
70
|
+
height: 0,
|
|
71
|
+
width: 0,
|
|
72
|
+
opacity: 0,
|
|
73
|
+
},
|
|
45
74
|
});
|
|
46
75
|
|
|
47
|
-
const [, t] = useLanguage()
|
|
48
|
-
|
|
49
76
|
const [timer, setTimer] = useState(`${TIME_COUNTDOWN / 60}:00`)
|
|
50
|
-
const [verifyCode, setVerifyCode] = useState({ 0: '', 1: '', 2: '', 3: '' })
|
|
51
77
|
const [isSendCodeAgain, setIsSendCodeAgain] = useState(false)
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
const [code, setCode] = useState('');
|
|
79
|
+
const [containerIsFocused, setContainerIsFocused] = useState(false);
|
|
80
|
+
|
|
81
|
+
const codeDigitsArray = new Array(CODE_LENGTH).fill(0);
|
|
82
|
+
const phoneLength = phone?.cellphone.split('').length
|
|
83
|
+
const lastNumbers = phone?.cellphone && phone?.cellphone.split('').fill('*', 0, phoneLength - 2).join('')
|
|
84
|
+
|
|
85
|
+
const handleOnPress = () => {
|
|
86
|
+
setContainerIsFocused(true);
|
|
87
|
+
ref?.current?.focus();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleOnBlur = () => {
|
|
91
|
+
setContainerIsFocused(false);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const toDigitInput = (_value: number, idx: number) => {
|
|
95
|
+
const emptyInputChar = '0';
|
|
96
|
+
const digit = code[idx] || emptyInputChar;
|
|
97
|
+
|
|
98
|
+
const isCurrentDigit = idx === code.length;
|
|
99
|
+
const isLastDigit = idx === CODE_LENGTH - 1;
|
|
100
|
+
const isCodeFull = code.length === CODE_LENGTH;
|
|
101
|
+
|
|
102
|
+
const isFocused = isCurrentDigit || (isLastDigit && isCodeFull);
|
|
103
|
+
|
|
104
|
+
const containerStyle =
|
|
105
|
+
containerIsFocused && isFocused
|
|
106
|
+
? {...style.inputContainer, ...style.inputContainerFocused}
|
|
107
|
+
: style.inputContainer;
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<View key={idx} style={containerStyle}>
|
|
111
|
+
<Text
|
|
112
|
+
style={{
|
|
113
|
+
...style.inputText,
|
|
114
|
+
color: code[idx] ? theme.colors.black : theme.colors.disabled
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
{digit}
|
|
118
|
+
</Text>
|
|
119
|
+
</View>
|
|
120
|
+
);
|
|
121
|
+
};
|
|
59
122
|
|
|
60
123
|
const checkResult = (result: any) => {
|
|
61
124
|
if (!result) return
|
|
@@ -106,27 +169,28 @@ export const VerifyPhone = (props: any) => {
|
|
|
106
169
|
}, [isSendCodeAgain])
|
|
107
170
|
|
|
108
171
|
useEffect(() => {
|
|
109
|
-
|
|
110
|
-
const isFullInputs = codes && Object.values(verifyCode).every(val => val)
|
|
111
|
-
if (codes === 4 && isFullInputs) {
|
|
172
|
+
if (code.length === CODE_LENGTH) {
|
|
112
173
|
const values = {
|
|
113
174
|
...formValues,
|
|
114
175
|
cellphone: phone.cellphone,
|
|
115
176
|
country_phone_code: `+${phone.country_phone_code}`,
|
|
116
|
-
code
|
|
177
|
+
code
|
|
117
178
|
}
|
|
118
179
|
handleCheckPhoneCode && handleCheckPhoneCode(values)
|
|
119
180
|
}
|
|
120
|
-
}, [
|
|
181
|
+
}, [code]);
|
|
182
|
+
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (verifyPhoneState?.result?.error) {
|
|
185
|
+
onClose && onClose()
|
|
186
|
+
}
|
|
187
|
+
}, [verifyPhoneState]);
|
|
121
188
|
|
|
122
189
|
return (
|
|
123
190
|
<Container>
|
|
124
|
-
<OText size={30} style={{ textAlign: 'left' }}>
|
|
125
|
-
{t('VERIFY_PHONE', 'Verify Phone')}
|
|
126
|
-
</OText>
|
|
127
191
|
{lastNumbers && (
|
|
128
|
-
<OText size={
|
|
129
|
-
{`${t('MESSAGE_ENTER_VERIFY_CODE', 'Please, enter the verification code we sent to your mobile ending with')}
|
|
192
|
+
<OText size={18} color={theme.colors.disabled}>
|
|
193
|
+
{`${t('MESSAGE_ENTER_VERIFY_CODE', 'Please, enter the verification code we sent to your mobile ending with')} ${lastNumbers}`}
|
|
130
194
|
</OText>
|
|
131
195
|
)}
|
|
132
196
|
<WrappCountdown>
|
|
@@ -140,30 +204,34 @@ export const VerifyPhone = (props: any) => {
|
|
|
140
204
|
</CountDownContainer>
|
|
141
205
|
</WrappCountdown>
|
|
142
206
|
<InputsSection>
|
|
143
|
-
{
|
|
207
|
+
<SafeAreaView style={style.container}>
|
|
208
|
+
<Pressable style={style.inputsContainer} onPress={handleOnPress} disabled={code.length === CODE_LENGTH}>
|
|
209
|
+
{codeDigitsArray.map(toDigitInput)}
|
|
210
|
+
</Pressable>
|
|
144
211
|
<TextInput
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
placeholder=
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
212
|
+
ref={ref}
|
|
213
|
+
value={code}
|
|
214
|
+
placeholder='0'
|
|
215
|
+
onChangeText={setCode}
|
|
216
|
+
onSubmitEditing={handleOnBlur}
|
|
217
|
+
keyboardType="number-pad"
|
|
218
|
+
returnKeyType="done"
|
|
219
|
+
textContentType="oneTimeCode"
|
|
220
|
+
maxLength={CODE_LENGTH}
|
|
221
|
+
style={style.hiddenCodeInput}
|
|
152
222
|
/>
|
|
153
|
-
|
|
223
|
+
</SafeAreaView>
|
|
154
224
|
</InputsSection>
|
|
155
|
-
{
|
|
156
|
-
!
|
|
157
|
-
|
|
158
|
-
|
|
225
|
+
{checkPhoneCodeState &&
|
|
226
|
+
!checkPhoneCodeState?.loading &&
|
|
227
|
+
checkPhoneCodeState?.result?.error &&
|
|
228
|
+
checkPhoneCodeState?.result?.result &&
|
|
159
229
|
(
|
|
160
230
|
<ErrorSection>
|
|
161
|
-
{checkResult((
|
|
162
|
-
verifyPhoneState?.result?.error ? verifyPhoneState : checkPhoneCodeState
|
|
163
|
-
).result?.result)?.map((e: any, i: number) => (
|
|
231
|
+
{checkResult((checkPhoneCodeState).result?.result)?.map((e: any, i: number) => (
|
|
164
232
|
<OText
|
|
165
233
|
key={i}
|
|
166
|
-
size={
|
|
234
|
+
size={16}
|
|
167
235
|
color={theme.colors.error}
|
|
168
236
|
>
|
|
169
237
|
{`* ${getTraduction(e, t)}`}
|
|
@@ -2,9 +2,7 @@ import styled from 'styled-components/native';
|
|
|
2
2
|
|
|
3
3
|
export const Container = styled.View`
|
|
4
4
|
width: 100%;
|
|
5
|
-
padding
|
|
6
|
-
padding-left: 20px;
|
|
7
|
-
padding-right: 20px;
|
|
5
|
+
padding: 0 30px;
|
|
8
6
|
`
|
|
9
7
|
|
|
10
8
|
export const CountDownContainer = styled.View`
|
|
@@ -14,24 +12,26 @@ export const CountDownContainer = styled.View`
|
|
|
14
12
|
margin: 0 auto;
|
|
15
13
|
display: flex;
|
|
16
14
|
justify-content: center;
|
|
15
|
+
align-items: center;
|
|
16
|
+
width: 80%;
|
|
17
17
|
`
|
|
18
18
|
|
|
19
19
|
export const ResendSection = styled.View`
|
|
20
20
|
display: flex;
|
|
21
21
|
flex-direction: row;
|
|
22
22
|
justify-content: center;
|
|
23
|
-
margin-bottom: 30px;
|
|
24
23
|
`
|
|
25
24
|
|
|
26
25
|
export const WrappCountdown = styled.View`
|
|
27
|
-
padding-top: 20px;
|
|
28
26
|
padding-bottom: 20px;
|
|
27
|
+
padding-top: 20px;
|
|
29
28
|
`
|
|
30
29
|
|
|
31
30
|
export const InputsSection = styled.View`
|
|
32
31
|
display: flex;
|
|
33
32
|
flex-direction: row;
|
|
34
33
|
justify-content: space-between;
|
|
34
|
+
padding-bottom: 20px;
|
|
35
35
|
`
|
|
36
36
|
|
|
37
37
|
export const ErrorSection = styled.View`
|