ordering-ui-react-native 0.23.75 → 0.23.76
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,22 +1,48 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import { useLanguage, useOrder, useConfig } from 'ordering-components/native';
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useLanguage, useOrder, useConfig, useSession, useApi, ToastType, useToast } from 'ordering-components/native';
|
|
3
3
|
import { useTheme } from 'styled-components/native';
|
|
4
4
|
import { StyleSheet, View } from 'react-native';
|
|
5
5
|
import { OButton, OIcon, OText } from '../shared';
|
|
6
6
|
import { LanguageSelector } from '../LanguageSelector';
|
|
7
7
|
import { TouchableOpacity } from 'react-native-gesture-handler';
|
|
8
8
|
import { useWindowDimensions, Platform } from 'react-native';
|
|
9
|
+
import uuid from 'react-native-uuid';
|
|
9
10
|
|
|
10
11
|
export const Home = (props: any) => {
|
|
11
12
|
const { onNavigationRedirect, businessSlug } = props;
|
|
12
13
|
const { width, height } = useWindowDimensions();
|
|
13
14
|
const [, t] = useLanguage();
|
|
14
|
-
const [orderState] = useOrder();
|
|
15
|
+
const [orderState, { handleOrderStateLoading, setStateInitialValues }] = useOrder();
|
|
15
16
|
const [{ configs }] = useConfig()
|
|
17
|
+
const [, { login }] = useSession()
|
|
18
|
+
const [ordering] = useApi()
|
|
19
|
+
const [, { showToast }] = useToast()
|
|
16
20
|
|
|
17
21
|
const theme = useTheme();
|
|
18
|
-
|
|
19
|
-
const
|
|
22
|
+
|
|
23
|
+
const handleCreateGuestUser = async (values: any) => {
|
|
24
|
+
try {
|
|
25
|
+
await handleOrderStateLoading(true)
|
|
26
|
+
const { content: { error, result } } = await ordering.users().save(values)
|
|
27
|
+
if (!error) {
|
|
28
|
+
await login({
|
|
29
|
+
user: result,
|
|
30
|
+
token: result.session?.access_token
|
|
31
|
+
})
|
|
32
|
+
} else {
|
|
33
|
+
showToast(ToastType.Error, t('ERROR_CREATING_GUEST_USER', 'Error creating guest users'))
|
|
34
|
+
}
|
|
35
|
+
await handleOrderStateLoading(false)
|
|
36
|
+
} catch (err) {
|
|
37
|
+
await handleOrderStateLoading(false)
|
|
38
|
+
showToast(ToastType.Error, t('ERROR_CREATING_GUEST_USER', 'Error creating guest users'))
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const handleUpdateGuest = async () => {
|
|
43
|
+
const guestToken = uuid.v4()
|
|
44
|
+
if (guestToken) await handleCreateGuestUser({ guest_token: guestToken })
|
|
45
|
+
}
|
|
20
46
|
|
|
21
47
|
return (
|
|
22
48
|
<View style={styles.container}>
|
|
@@ -47,6 +73,7 @@ export const Home = (props: any) => {
|
|
|
47
73
|
isCircle={false}
|
|
48
74
|
onClick={() => onNavigationRedirect('Login')}
|
|
49
75
|
imgRightSrc={null}
|
|
76
|
+
isDisabled={orderState?.loading}
|
|
50
77
|
/>
|
|
51
78
|
<OButton
|
|
52
79
|
text={t('SIGNUP', 'Signup')}
|
|
@@ -56,15 +83,13 @@ export const Home = (props: any) => {
|
|
|
56
83
|
textStyle={{ color: 'black' }}
|
|
57
84
|
onClick={() => onNavigationRedirect('Signup')}
|
|
58
85
|
imgRightSrc={null}
|
|
86
|
+
isDisabled={orderState?.loading}
|
|
59
87
|
/>
|
|
60
88
|
<TouchableOpacity
|
|
89
|
+
disabled={orderState?.loading}
|
|
61
90
|
style={{ ...styles.textLink, marginTop: 12 }}
|
|
62
|
-
onPress={() =>
|
|
63
|
-
|
|
64
|
-
? onNavigationRedirect(!!businessSlug ? 'Business' : 'BusinessList', { isGuestUser: true })
|
|
65
|
-
: onNavigationRedirect('AddressForm', { isGuestUser: true })
|
|
66
|
-
}>
|
|
67
|
-
<OText weight="normal" size={18} color={theme.colors.white}>
|
|
91
|
+
onPress={() => handleUpdateGuest()}>
|
|
92
|
+
<OText weight="normal" size={18} color={orderState?.loading ? '#ccc' : theme.colors.white}>
|
|
68
93
|
{t('CONTINUE_AS_GUEST', 'Continue as guest')}
|
|
69
94
|
</OText>
|
|
70
95
|
</TouchableOpacity>
|
|
@@ -107,9 +107,9 @@ const LoginFormUI = (props: LoginParams) => {
|
|
|
107
107
|
|
|
108
108
|
const [isCheckingCode, setCheckingCode] = useState(false)
|
|
109
109
|
|
|
110
|
-
const googleLoginEnabled = configs?.google_login_enabled?.value === '1'
|
|
111
|
-
const facebookLoginEnabled = configs?.facebook_login_enabled?.value === '1'
|
|
112
|
-
const appleLoginEnabled = Platform.OS === 'ios' && (configs?.apple_login_enabled?.value === '1'
|
|
110
|
+
const googleLoginEnabled = configs?.google_login_enabled?.value === '1'
|
|
111
|
+
const facebookLoginEnabled = configs?.facebook_login_enabled?.value === '1'
|
|
112
|
+
const appleLoginEnabled = Platform.OS === 'ios' && (configs?.apple_login_enabled?.value === '1')
|
|
113
113
|
|
|
114
114
|
const loginStyle = StyleSheet.create({
|
|
115
115
|
btnOutline: {
|
|
@@ -301,7 +301,7 @@ const LoginFormUI = (props: LoginParams) => {
|
|
|
301
301
|
setTabLayouts(_tabLayouts)
|
|
302
302
|
}
|
|
303
303
|
|
|
304
|
-
const handleChangePhoneNumber = (number
|
|
304
|
+
const handleChangePhoneNumber = (number: any, rawNumber: any) => {
|
|
305
305
|
setPhoneInputData(number)
|
|
306
306
|
setCellphoneStartZero && setCellphoneStartZero(rawNumber?.number && rawNumber?.countryCallingCode ? rawNumber?.number : null)
|
|
307
307
|
}
|