ordering-ui-react-native 0.12.15 → 0.12.19

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.
@@ -1,5 +1,5 @@
1
- import React, { useState } from 'react';
2
- import { Platform, View } from 'react-native';
1
+ import React, { useEffect, useState } from 'react';
2
+ import { Dimensions, Platform, View } from 'react-native';
3
3
  import { useLanguage, useOrder, useUtils } from 'ordering-components/native';
4
4
  import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons'
5
5
 
@@ -17,13 +17,16 @@ import { CartContent } from '../../components/CartContent';
17
17
  import { TouchableOpacity } from 'react-native-gesture-handler';
18
18
  import { LANDSCAPE, PORTRAIT, useDeviceOrientation } from '../../../../../src/hooks/DeviceOrientation';
19
19
  import { useCartBottomSheet } from '../../providers/CartBottomSheetProvider';
20
- import { useTheme } from 'styled-components/native';
20
+ import styled, { useTheme } from 'styled-components/native';
21
+ import { DrawerView } from '../DrawerView';
22
+ import { ProductForm } from '../ProductForm';
21
23
 
22
24
  const CategoriesMenu = (props: any): React.ReactElement => {
23
25
 
24
26
  const {
25
27
  navigation,
26
28
  route,
29
+ isDrawer
27
30
  } = props;
28
31
 
29
32
  const {
@@ -41,7 +44,16 @@ const CategoriesMenu = (props: any): React.ReactElement => {
41
44
  const [{ parsePrice }] = useUtils();
42
45
  const [orientationState] = useDeviceOrientation();
43
46
  const [bottomSheetVisibility, { showCartBottomSheet, hideCartBottomSheet }] = useCartBottomSheet();
44
-
47
+ const [productSelected, setProductSelected] = useState({})
48
+ const [drawerState, setDrawerState] = useState({ isOpen: false, data: { order: null } });
49
+
50
+ const width_dimension = Dimensions.get('window').width;
51
+ const height_dimension = Dimensions.get('window').height;
52
+
53
+ const KeyboardView = styled.KeyboardAvoidingView`
54
+ flex: 1;
55
+ `;
56
+
45
57
  const onChangeTabs = (idx: number) => {
46
58
  resetInactivityTimeout();
47
59
  setIndexCateg(idx);
@@ -49,6 +61,10 @@ const CategoriesMenu = (props: any): React.ReactElement => {
49
61
 
50
62
  const goToBack = () => navigation.goBack()
51
63
 
64
+ const setDrawerValues = ({ isOpen, data }: any) => {
65
+ setDrawerState({ ...drawerState, isOpen, data });
66
+ }
67
+
52
68
  const [{ carts }] = useOrder();
53
69
  const cartsList = (carts && Object.values(carts).filter((cart: any) => cart.products.length > 0)) || [];
54
70
  const VISIBLE_CART_BOTTOM_SHEET_HEIGHT = orientationState?.dimensions?.height * (orientationState.orientation === PORTRAIT ? 0.5 : 1);
@@ -82,91 +98,120 @@ const CategoriesMenu = (props: any): React.ReactElement => {
82
98
  }
83
99
 
84
100
  return (
85
- <View style={{
86
- flex: 1,
87
- flexDirection: orientationState?.orientation === PORTRAIT ? 'column' : 'row'
88
- }}>
89
- <View
90
- style={{
91
- flex: 1,
92
- paddingBottom: bottomSheetVisibility && !!cart && orientationState?.orientation === PORTRAIT
93
- ? VISIBLE_CART_BOTTOM_SHEET_HEIGHT
94
- : 0,
95
- }}
96
- >
97
- <Container nopadding nestedScrollEnabled>
98
- <View style={{ paddingTop: 20 }}>
99
- <NavBar
100
- title={categories[curIndexCateg].name}
101
- onActionLeft={goToBack}
102
- rightComponent={cart && (
103
- <TouchableOpacity
104
- style={{ paddingHorizontal: 20, flexDirection: 'row', alignItems: 'center' }}
105
- onPress={onToggleCart}
106
- >
107
- <OText
108
- color={theme.colors.mediumGray}
101
+ <>
102
+ <View style={{
103
+ flex: 1,
104
+ flexDirection: orientationState?.orientation === PORTRAIT ? 'column' : 'row'
105
+ }}>
106
+ <View
107
+ style={{
108
+ flex: 1,
109
+ paddingBottom: bottomSheetVisibility && !!cart && orientationState?.orientation === PORTRAIT
110
+ ? VISIBLE_CART_BOTTOM_SHEET_HEIGHT
111
+ : 0,
112
+ }}
113
+ >
114
+ <Container nopadding nestedScrollEnabled>
115
+ <View style={{ paddingTop: 20 }}>
116
+ <NavBar
117
+ title={categories[curIndexCateg].name}
118
+ onActionLeft={goToBack}
119
+ rightComponent={cart && (
120
+ <TouchableOpacity
121
+ style={{ paddingHorizontal: 20, flexDirection: 'row', alignItems: 'center' }}
122
+ onPress={onToggleCart}
109
123
  >
110
- {`${cart?.products?.length || 0} ${t('ITEMS', 'items')}`} {parsePrice(cart?.total || 0)} {' '}
111
- </OText>
112
-
113
- <MaterialIcon
114
- name={bottomSheetVisibility ? "cart-off" : "cart-outline"}
115
- color={theme.colors.primary}
116
- size={30}
117
- />
118
- </TouchableOpacity>
119
- )}
120
- />
121
- <OSegment
122
- items={categories.map((category) => ({
123
- text: category.name
124
- }))}
125
- selectedIdx={curIndexCateg}
126
- onSelectItem={onChangeTabs}
124
+ <OText
125
+ color={theme.colors.mediumGray}
126
+ >
127
+ {`${cart?.products?.length || 0} ${t('ITEMS', 'items')}`} {parsePrice(cart?.total || 0)} {' '}
128
+ </OText>
129
+
130
+ <MaterialIcon
131
+ name={bottomSheetVisibility ? "cart-off" : "cart-outline"}
132
+ color={theme.colors.primary}
133
+ size={30}
134
+ />
135
+ </TouchableOpacity>
136
+ )}
137
+ />
138
+ <OSegment
139
+ items={categories.map((category) => ({
140
+ text: category.name
141
+ }))}
142
+ selectedIdx={curIndexCateg}
143
+ onSelectItem={onChangeTabs}
144
+ />
145
+ </View>
146
+
147
+ <GridContainer style={{ marginTop: 20 }}>
148
+ {categories[curIndexCateg].products.map((product) => (
149
+ <OCard
150
+ key={product.id}
151
+ title={product?.name}
152
+ image={{ uri: product?.images }}
153
+ style={{
154
+ width: orientationState?.orientation === LANDSCAPE
155
+ ? bottomSheetVisibility ? orientationState?.dimensions?.width * 0.145 :orientationState?.dimensions?.width * 0.16
156
+ : orientationState?.dimensions?.width * 0.20
157
+ }}
158
+ titleStyle={{marginTop: Platform.OS === 'ios' ? 10 : 0}}
159
+ onPress={() => {
160
+ resetInactivityTimeout()
161
+ if (isDrawer) {
162
+ setProductSelected(product)
163
+ setDrawerValues({ isOpen: true, data: null })
164
+ } else {
165
+ navigation.navigate('ProductDetails', {
166
+ businessId,
167
+ businessSlug,
168
+ product,
169
+ });
170
+ }
171
+ }}
172
+ {...(!!product?.description && { description: product?.description } )}
173
+ {...(!!product?.price && { price: parsePrice(product?.price) } )}
174
+ {...(product?.in_offer && { prevPrice: `$${product?.offer_price}` } )}
175
+ />
176
+ ))}
177
+ </GridContainer>
178
+ </Container>
179
+ </View>
180
+
181
+ <View
182
+ style={{
183
+ flex: bottomSheetVisibility && orientationState?.orientation === PORTRAIT ? 0 : 0.8,
184
+ display: bottomSheetVisibility ? 'flex' : 'none'
185
+ }}
186
+ >
187
+ <CartContent
188
+ {...cartProps}
127
189
  />
128
190
  </View>
129
-
130
- <GridContainer style={{ marginTop: 20 }}>
131
- {categories[curIndexCateg].products.map((product) => (
132
- <OCard
133
- key={product.id}
134
- title={product?.name}
135
- image={{ uri: product?.images }}
136
- style={{
137
- width: orientationState?.orientation === LANDSCAPE
138
- ? bottomSheetVisibility ? orientationState?.dimensions?.width * 0.145 :orientationState?.dimensions?.width * 0.16
139
- : orientationState?.dimensions?.width * 0.20
140
- }}
141
- titleStyle={{marginTop: Platform.OS === 'ios' ? 10 : 0}}
142
- onPress={() => {
143
- resetInactivityTimeout()
144
- navigation.navigate('ProductDetails', {
145
- businessId,
146
- businessSlug,
147
- product,
148
- });
149
- }}
150
- {...(!!product?.description && { description: product?.description } )}
151
- {...(!!product?.price && { price: parsePrice(product?.price) } )}
152
- {...(product?.in_offer && { prevPrice: `$${product?.offer_price}` } )}
153
- />
154
- ))}
155
- </GridContainer>
156
- </Container>
157
191
  </View>
158
-
159
- <View
160
- style={{
161
- flex: bottomSheetVisibility && orientationState?.orientation === PORTRAIT ? 0 : 0.8,
162
- display: bottomSheetVisibility ? 'flex' : 'none'
163
- }}
192
+ <DrawerView
193
+ isOpen={drawerState.isOpen}
194
+ width={width_dimension - (width_dimension * 0.4)}
195
+ height={height_dimension}
196
+ onClickIcon={() => setDrawerValues({ isOpen: !drawerState.isOpen, data: null })}
197
+ >
198
+ <KeyboardView
199
+ enabled
200
+ behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
164
201
  >
165
- <CartContent
166
- {...cartProps}
202
+ <ProductForm
203
+ isDrawer
204
+ product={productSelected}
205
+ businessId={parseInt(businessId, 10)}
206
+ businessSlug={businessSlug}
207
+ onSave={() => {
208
+ setDrawerValues({ isOpen: !drawerState.isOpen, data: null })
209
+ }}
210
+ navigation={navigation}
167
211
  />
168
- </View>
169
- </View>
212
+ </KeyboardView>
213
+ </DrawerView>
214
+ </>
170
215
  );
171
216
  };
172
217
 
@@ -0,0 +1,57 @@
1
+ import React from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons';
4
+
5
+ import {
6
+ Container,
7
+ Wrapper,
8
+ WrapperFloatBtn,
9
+ IconControl
10
+ } from './styles';
11
+
12
+ export const DrawerView = (props: any) => {
13
+ const {
14
+ children,
15
+ isOpen,
16
+ width,
17
+ height,
18
+ onClickIcon,
19
+ iconStyles
20
+ } = props;
21
+
22
+ return (
23
+ isOpen && (
24
+ <>
25
+ <WrapperFloatBtn>
26
+ <IconControl
27
+ activeOpacity={1}
28
+ style={{ ...iconStyles, ...styles.shadow}}
29
+ onPress={() => onClickIcon()}
30
+ >
31
+ <MaterialCommunityIcon
32
+ name='arrow-expand-right'
33
+ size={24}
34
+ />
35
+ </IconControl>
36
+ </WrapperFloatBtn>
37
+ <Container style={styles.shadow}>
38
+ <Wrapper width={width} height={height}>
39
+ {children}
40
+ </Wrapper>
41
+ </Container>
42
+ </>
43
+ )
44
+ )
45
+ }
46
+
47
+ const styles = StyleSheet.create({
48
+ shadow:{
49
+ shadowColor: 'rgba(0.0, 0.0, 0.0, 0.5)',
50
+ shadowOffset: {
51
+ width: 0,
52
+ height: 1.5,
53
+ },
54
+ shadowOpacity: 0.21,
55
+ shadowRadius: 5,
56
+ }
57
+ })
@@ -0,0 +1,30 @@
1
+ import styled, { css } from 'styled-components/native';
2
+
3
+ export const Container = styled.View`
4
+ position: absolute;
5
+ top: 0;
6
+ right: 0;
7
+ z-index: 10001;
8
+ elevation: 5;
9
+ background-color: #FFF;
10
+ `;
11
+
12
+ export const Wrapper = styled.View`
13
+ width: ${(props: any) => props.width}px;
14
+ height: ${(props: any) => props.height}px;
15
+ `;
16
+
17
+ export const WrapperFloatBtn = styled.View`
18
+ position: absolute;
19
+ top: 10%;
20
+ right: ${(props: any) => props.outside ? 11 : 58}%;
21
+ z-index: 20002;
22
+ elevation: 11;
23
+ `;
24
+
25
+ export const IconControl = styled.TouchableOpacity`
26
+ background-color: ${(props: any) => props.theme.colors.white};
27
+ padding: 10px;
28
+ border-radius: 8px;
29
+ elevation: 11;
30
+ `;
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react'
1
+ import React, { useEffect, useState } from 'react'
2
2
  import { TouchableOpacity, View, StyleSheet } from 'react-native'
3
3
  import { LanguageSelector as LanguageSelectorController, useLanguage } from 'ordering-components/native'
4
4
  import CountryPicker, { Flag } from 'react-native-country-picker-modal'
@@ -9,6 +9,7 @@ import { LanguageSelectorParams } from '../../types'
9
9
  import { OText } from '../shared'
10
10
  import MatarialIcon from "react-native-vector-icons/MaterialIcons"
11
11
  import { useTheme } from 'styled-components/native'
12
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
12
13
  const LanguageSelectorUI = (props: LanguageSelectorParams) => {
13
14
  const {
14
15
  languagesState,
@@ -18,7 +19,7 @@ const LanguageSelectorUI = (props: LanguageSelectorParams) => {
18
19
 
19
20
  const theme = useTheme()
20
21
  const [{loading}] = useLanguage()
21
-
22
+ const [isLoading, setIsLoading] = useState(true)
22
23
  const styles = StyleSheet.create({
23
24
  closeIcon: {
24
25
  width: 48, marginLeft: 32
@@ -27,6 +28,15 @@ const LanguageSelectorUI = (props: LanguageSelectorParams) => {
27
28
  marginLeft: 40
28
29
  }
29
30
  })
31
+ useEffect(() => {
32
+ if (!isLoading) return
33
+ const loadingLanguage = setTimeout(() =>{
34
+ setIsLoading(false)
35
+ }, 1000);
36
+ return () => {
37
+ clearTimeout(loadingLanguage);
38
+ }
39
+ }, [])
30
40
 
31
41
  const _languages = languagesState?.languages?.map((language: any) => {
32
42
  return {
@@ -48,63 +58,73 @@ const LanguageSelectorUI = (props: LanguageSelectorParams) => {
48
58
  const currentLanguageData = _languages?.find((item:any) => item.value == currentLanguage);
49
59
 
50
60
  return (
51
- <Container>
52
- {languagesState?.languages && (
53
- <CountryPicker
54
- countryCode={currentLanguageData?.countryCode}
55
- visible={isCountryModalVisible}
56
- onClose={() => setCountryModalVisible(false)}
57
- withCountryNameButton
58
- countryCodes={countryCodes}
59
- closeButtonStyle={styles.closeIcon}
60
- renderFlagButton={() => (
61
- <TouchableOpacity
62
- onPress={() => setCountryModalVisible(true)}
63
- disabled={loading}
64
- >
65
- <LanguageItem>
66
- <Flag
67
- withEmoji
68
- flagSize={24}
69
- countryCode={currentLanguageData?.countryCode}
70
- />
71
- <OText color={theme.colors.primary}>{currentLanguageData?.label}</OText>
72
- <MatarialIcon name='keyboard-arrow-down' size={24}/>
73
- </LanguageItem>
74
- </TouchableOpacity>
61
+ <>
62
+ { isLoading ?
63
+ (<Container>
64
+ <Placeholder style={{ width: 130, paddingTop: 10 }} Animation={Fade}>
65
+ <PlaceholderLine height={15}/>
66
+ </Placeholder>
67
+ </Container>
68
+ ):(
69
+ <Container>
70
+ {languagesState?.languages && (
71
+ <CountryPicker
72
+ countryCode={currentLanguageData?.countryCode}
73
+ visible={isCountryModalVisible}
74
+ onClose={() => setCountryModalVisible(false)}
75
+ withCountryNameButton
76
+ countryCodes={countryCodes}
77
+ closeButtonStyle={styles.closeIcon}
78
+ renderFlagButton={() => (
79
+ <TouchableOpacity
80
+ onPress={() => setCountryModalVisible(true)}
81
+ disabled={loading}
82
+ >
83
+ <LanguageItem>
84
+ <Flag
85
+ withEmoji
86
+ flagSize={24}
87
+ countryCode={currentLanguageData?.countryCode}
88
+ />
89
+ <OText color={theme.colors.primary}>{currentLanguageData?.label}</OText>
90
+ <MatarialIcon name='keyboard-arrow-down' size={24}/>
91
+ </LanguageItem>
92
+ </TouchableOpacity>
93
+ )}
94
+ flatListProps={{
95
+ /* @ts-ignore */
96
+ keyExtractor: (item) => item.value,
97
+ data: _languages || [],
98
+ renderItem: ({item} : any) => (
99
+ <TouchableOpacity
100
+ onPress={() => {
101
+ /* @ts-ignore */
102
+ handleChangeLanguage(item.value);
103
+ setCountryModalVisible(false);
104
+ }}
105
+ disabled={loading}
106
+ >
107
+ <LanguageItem>
108
+ <View style={styles.flagsContainer} />
109
+ <Flag
110
+ withEmoji
111
+ flagSize={24}
112
+ /* @ts-ignore */
113
+ countryCode={item.countryCode}
114
+ />
115
+ <OText>{
116
+ /* @ts-ignore */
117
+ item.label
118
+ }</OText>
119
+ </LanguageItem>
120
+ </TouchableOpacity>
121
+ )
122
+ }}
123
+ />
75
124
  )}
76
- flatListProps={{
77
- /* @ts-ignore */
78
- keyExtractor: (item) => item.value,
79
- data: _languages || [],
80
- renderItem: ({item} : any) => (
81
- <TouchableOpacity
82
- onPress={() => {
83
- /* @ts-ignore */
84
- handleChangeLanguage(item.value);
85
- setCountryModalVisible(false);
86
- }}
87
- disabled={loading}
88
- >
89
- <LanguageItem>
90
- <View style={styles.flagsContainer} />
91
- <Flag
92
- withEmoji
93
- flagSize={24}
94
- /* @ts-ignore */
95
- countryCode={item.countryCode}
96
- />
97
- <OText>{
98
- /* @ts-ignore */
99
- item.label
100
- }</OText>
101
- </LanguageItem>
102
- </TouchableOpacity>
103
- )
104
- }}
105
- />
106
- )}
107
- </Container>
125
+ </Container>
126
+ )}
127
+ </>
108
128
  )
109
129
  }
110
130
 
@@ -33,7 +33,7 @@ import OptionSwitch, { Opt } from '../../components/shared/OOptionToggle';
33
33
  import { verifyDecimals } from '../../../../../src/utils'
34
34
  import { LANDSCAPE, PORTRAIT, useDeviceOrientation } from '../../../../../src/hooks/DeviceOrientation'
35
35
  import { useTheme } from 'styled-components/native'
36
- import { _retrieveStoreData } from '../../../../../src/providers/StoreUtil';
36
+ import { _retrieveStoreData, _setStoreData } from '../../../../../src/providers/StoreUtil';
37
37
  import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons'
38
38
  import EvilIcons from 'react-native-vector-icons/EvilIcons'
39
39
  const _EMAIL = 'email';
@@ -218,6 +218,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
218
218
  }
219
219
  getCustomerName()
220
220
  const redirectHome = setTimeout(() =>{
221
+ _setStoreData('customer_name', {customerName: ''});
221
222
  navigation.reset({
222
223
  routes: [{ name: 'Intro' }],
223
224
  });
@@ -344,6 +345,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
344
345
  <OButton
345
346
  text={`${t('YOU_ARE_DONE', 'You are done! Click to close')}!`}
346
347
  onClick={() => {
348
+ _setStoreData('customer_name', {customerName: ''});
347
349
  navigation.reset({
348
350
  routes: [{ name: 'Intro' }],
349
351
  });