ordering-ui-react-native 0.23.75-test6 → 0.23.76-test

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.23.75-test6",
3
+ "version": "0.23.76-test",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -121,6 +121,14 @@ const MapViewComponent = (props: MapViewParams) => {
121
121
  };
122
122
  }, [isFocused]);
123
123
 
124
+ useEffect(() => {
125
+ return () => {
126
+ if (mapRef) {
127
+ mapRef.current = null
128
+ }
129
+ }
130
+ }, [])
131
+
124
132
  useFocusEffect(
125
133
  useCallback(() => {
126
134
  setIsFocused(true)
@@ -186,7 +194,7 @@ const MapViewComponent = (props: MapViewParams) => {
186
194
  longitude: coordinateLng
187
195
  })
188
196
  }
189
- ref={(ref) => markerRef.current = ref}
197
+ ref={(ref: any) => markerRef.current = ref}
190
198
  >
191
199
  <Icon
192
200
  name="map-marker"
@@ -262,7 +270,7 @@ const MapViewComponent = (props: MapViewParams) => {
262
270
  <View style={{ flex: 1 }}>
263
271
  {!isLoadingBusinessMarkers && isFocused ? (
264
272
  <View style={{ flex: 1 }}>
265
- {/* <MapView
273
+ <MapView
266
274
  ref={mapRef}
267
275
  provider={PROVIDER_GOOGLE}
268
276
  initialRegion={{
@@ -319,8 +327,8 @@ const MapViewComponent = (props: MapViewParams) => {
319
327
  </Marker>
320
328
  ) : null}
321
329
  </>
322
- </MapView> */}
323
- {/* <OFab
330
+ </MapView>
331
+ <OFab
324
332
  materialIcon
325
333
  iconName="plus"
326
334
  onPress={() => onPressZoomIn()}
@@ -333,19 +341,13 @@ const MapViewComponent = (props: MapViewParams) => {
333
341
  <OFab
334
342
  materialIcon
335
343
  iconName="minus"
336
- onPress={() => {
337
- onPressZoomOut()
338
- setAlertState({
339
- open: true,
340
- content: [t('THISISATEST', 'This is a test')]
341
- })
342
- }}
344
+ onPress={() => onPressZoomOut()}
343
345
  style={{
344
346
  position: 'absolute',
345
347
  bottom: 35,
346
348
  right: 20,
347
349
  }}
348
- /> */}
350
+ />
349
351
  </View>
350
352
  ) : null}
351
353
  </View>
@@ -1,22 +1,48 @@
1
- import React, { useEffect } from '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
- const unaddressedTypes = configs?.unaddressed_order_types_allowed?.value.split('|').map((value: any) => Number(value)) || []
19
- const isAllowUnaddressOrderType = unaddressedTypes.includes(orderState?.options?.type)
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
- orderState?.options?.address?.address || isAllowUnaddressOrderType
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' || !configs?.google_login_enabled?.enabled
111
- const facebookLoginEnabled = configs?.facebook_login_enabled?.value === '1' || !configs?.facebook_login_enabled?.enabled
112
- const appleLoginEnabled = Platform.OS === 'ios' && (configs?.apple_login_enabled?.value === '1' || !configs?.apple_login_enabled?.enabled)
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 : any, rawNumber: any) => {
304
+ const handleChangePhoneNumber = (number: any, rawNumber: any) => {
305
305
  setPhoneInputData(number)
306
306
  setCellphoneStartZero && setCellphoneStartZero(rawNumber?.number && rawNumber?.countryCallingCode ? rawNumber?.number : null)
307
307
  }