ordering-ui-react-native 0.18.0-release → 0.18.1-release
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 +1 -1
- package/themes/business/index.tsx +2 -0
- package/themes/business/src/components/BusinessController/index.tsx +19 -16
- package/themes/business/src/components/BusinessProductList/AccordionDropdown.tsx +63 -0
- package/themes/business/src/components/BusinessProductList/IterateCategories.tsx +108 -0
- package/themes/business/src/components/BusinessProductList/ProductList.tsx +196 -0
- package/themes/business/src/components/BusinessProductList/index.tsx +196 -0
- package/themes/business/src/components/BusinessProductList/styles.tsx +10 -0
- package/themes/business/src/components/SearchBar/index.tsx +2 -1
- package/themes/business/src/components/StoresList/index.tsx +3 -1
- package/themes/business/src/types/index.tsx +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
//Components
|
|
2
2
|
import { AcceptOrRejectOrder } from './src/components/AcceptOrRejectOrder';
|
|
3
3
|
import { BusinessController } from './src/components/BusinessController';
|
|
4
|
+
import { BusinessProductList } from './src/components/BusinessProductList';
|
|
4
5
|
import { Chat } from './src/components/Chat';
|
|
5
6
|
import { FloatingButton } from './src/components/FloatingButton';
|
|
6
7
|
import { ForgotPasswordForm } from './src/components/ForgotPasswordForm';
|
|
@@ -70,6 +71,7 @@ export {
|
|
|
70
71
|
//Components
|
|
71
72
|
AcceptOrRejectOrder,
|
|
72
73
|
BusinessController,
|
|
74
|
+
BusinessProductList,
|
|
73
75
|
Chat,
|
|
74
76
|
DriverMap,
|
|
75
77
|
FloatingButton,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import { StyleSheet, View, ActivityIndicator } from 'react-native';
|
|
2
|
+
import { StyleSheet, View, ActivityIndicator, TouchableOpacity } from 'react-native';
|
|
3
3
|
import ToggleSwitch from 'toggle-switch-react-native';
|
|
4
4
|
import { useTheme } from 'styled-components/native';
|
|
5
5
|
import {
|
|
@@ -14,7 +14,7 @@ import { OIcon, OText } from '../shared';
|
|
|
14
14
|
import { BusinessControllerParams } from '../../types';
|
|
15
15
|
|
|
16
16
|
export const BusinessControllerUI = (props: BusinessControllerParams) => {
|
|
17
|
-
const { businessState, updateBusiness, isUpdateStore, setIsUpdateStore } =
|
|
17
|
+
const { businessState, updateBusiness, isUpdateStore, setIsUpdateStore, navigation } =
|
|
18
18
|
props;
|
|
19
19
|
|
|
20
20
|
const { loading, business, error } = businessState;
|
|
@@ -93,20 +93,18 @@ export const BusinessControllerUI = (props: BusinessControllerParams) => {
|
|
|
93
93
|
<>
|
|
94
94
|
{business && (
|
|
95
95
|
<Card key={business?.id}>
|
|
96
|
-
<View style={{
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
alignItems: 'flex-start',
|
|
109
|
-
}}>
|
|
96
|
+
<View style={{ flexDirection: 'row', flex: 1 }}>
|
|
97
|
+
<TouchableOpacity
|
|
98
|
+
style={{ flex: 1, flexDirection: 'row', alignItems: 'center' }}
|
|
99
|
+
onPress={() => navigation && business?.slug && navigation.navigate('BusinessProductListing', { slug: business?.slug })}
|
|
100
|
+
>
|
|
101
|
+
<Logo style={styles.logo}>
|
|
102
|
+
<OIcon
|
|
103
|
+
url={optimizeImage(business?.logo, 'h_300,c_limit')}
|
|
104
|
+
src={!business?.logo && theme?.images?.dummies?.businessLogo}
|
|
105
|
+
style={styles.icon}
|
|
106
|
+
/>
|
|
107
|
+
</Logo>
|
|
110
108
|
<Information>
|
|
111
109
|
<View style={styles.header}>
|
|
112
110
|
<OText style={styles.title} numberOfLines={1}>
|
|
@@ -122,7 +120,12 @@ export const BusinessControllerUI = (props: BusinessControllerParams) => {
|
|
|
122
120
|
{business?.zipcode}
|
|
123
121
|
</OText>
|
|
124
122
|
</Information>
|
|
123
|
+
</TouchableOpacity>
|
|
125
124
|
|
|
125
|
+
<View
|
|
126
|
+
style={{
|
|
127
|
+
alignItems: 'flex-start',
|
|
128
|
+
}}>
|
|
126
129
|
{loading && isUpdateStore ? (
|
|
127
130
|
<ActivityIndicator size="small" color={theme.colors.primary} />
|
|
128
131
|
) : (
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { OText } from "../shared"
|
|
2
|
+
import React, { useState } from "react"
|
|
3
|
+
import { View } from "react-native"
|
|
4
|
+
import { TouchableOpacity } from "react-native-gesture-handler"
|
|
5
|
+
import AntDesignIcon from 'react-native-vector-icons/AntDesign'
|
|
6
|
+
import ToggleSwitch from 'toggle-switch-react-native';
|
|
7
|
+
import { useTheme } from 'styled-components/native';
|
|
8
|
+
import { CategoryTab } from './styles'
|
|
9
|
+
|
|
10
|
+
export const AccordionDropdown = (props: any) => {
|
|
11
|
+
const { category, IterateCategories, handlerClickCategory, updateCategory } = props
|
|
12
|
+
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
15
|
+
|
|
16
|
+
const handleSwitch = (enabled: boolean, categoryId: any) => {
|
|
17
|
+
updateCategory && updateCategory(categoryId, { enabled })
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<View style={{ marginLeft: !!category?.parent_category_id ? 10 : 0 }}>
|
|
22
|
+
<CategoryTab>
|
|
23
|
+
<View style={{ flexDirection: 'row', alignItems: 'center', flex: 1, marginRight: 5 }}>
|
|
24
|
+
<TouchableOpacity onPress={() => setIsOpen(prev => !prev)} style={{ marginRight: 10 }}>
|
|
25
|
+
<AntDesignIcon
|
|
26
|
+
name={isOpen ? 'caretdown' : 'caretright'}
|
|
27
|
+
size={14}
|
|
28
|
+
/>
|
|
29
|
+
</TouchableOpacity>
|
|
30
|
+
<TouchableOpacity onPress={() => handlerClickCategory(category)} style={{ flex: 1 }}>
|
|
31
|
+
<OText numberOfLines={1}>
|
|
32
|
+
{category.name}
|
|
33
|
+
</OText>
|
|
34
|
+
</TouchableOpacity>
|
|
35
|
+
</View>
|
|
36
|
+
<View>
|
|
37
|
+
<ToggleSwitch
|
|
38
|
+
isOn={category?.enabled}
|
|
39
|
+
onColor={theme.colors.primary}
|
|
40
|
+
offColor={theme.colors.offColor}
|
|
41
|
+
size="small"
|
|
42
|
+
onToggle={(value: boolean) => handleSwitch(value, category.id)}
|
|
43
|
+
// disabled={loading}
|
|
44
|
+
animationSpeed={200}
|
|
45
|
+
/>
|
|
46
|
+
</View>
|
|
47
|
+
</CategoryTab>
|
|
48
|
+
{
|
|
49
|
+
isOpen && (
|
|
50
|
+
<View>
|
|
51
|
+
<IterateCategories
|
|
52
|
+
list={category.subcategories}
|
|
53
|
+
isSub
|
|
54
|
+
currentCat={category}
|
|
55
|
+
handlerClickCategory={handlerClickCategory}
|
|
56
|
+
updateCategory={updateCategory}
|
|
57
|
+
/>
|
|
58
|
+
</View>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
</View>
|
|
62
|
+
)
|
|
63
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import React from "react"
|
|
2
|
+
import { View, TouchableOpacity } from "react-native"
|
|
3
|
+
import { OText } from "../shared"
|
|
4
|
+
import ToggleSwitch from 'toggle-switch-react-native';
|
|
5
|
+
import { AccordionDropdown } from './AccordionDropdown'
|
|
6
|
+
import { useTheme } from 'styled-components/native';
|
|
7
|
+
import { CategoryTab } from './styles'
|
|
8
|
+
|
|
9
|
+
export const IterateCategories = (props: any) => {
|
|
10
|
+
const { list, currentCat, isSub, handlerClickCategory, updateCategory } = props
|
|
11
|
+
|
|
12
|
+
const theme = useTheme();
|
|
13
|
+
|
|
14
|
+
const handleSwitch = (enabled: boolean, categoryId: any) => {
|
|
15
|
+
updateCategory && updateCategory(categoryId, { enabled })
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
{list?.length > 0 && list.map((category: any, i: number) => (
|
|
21
|
+
<View key={`${category?.id}_${i}`}>
|
|
22
|
+
{(category?.subcategories?.length > 0 || isSub) ? (
|
|
23
|
+
<>
|
|
24
|
+
{category?.subcategories?.length > 0 && (
|
|
25
|
+
<>
|
|
26
|
+
<View>
|
|
27
|
+
<AccordionDropdown
|
|
28
|
+
category={category}
|
|
29
|
+
IterateCategories={IterateCategories}
|
|
30
|
+
handlerClickCategory={handlerClickCategory}
|
|
31
|
+
updateCategory={updateCategory}
|
|
32
|
+
/>
|
|
33
|
+
</View>
|
|
34
|
+
</>
|
|
35
|
+
)}
|
|
36
|
+
{isSub && !category?.subcategories?.length && (
|
|
37
|
+
<CategoryTab isSpace={!!category?.parent_category_id}>
|
|
38
|
+
<TouchableOpacity
|
|
39
|
+
style={{ flex: 1, marginRight: 5 }}
|
|
40
|
+
onPress={() => handlerClickCategory(category)}
|
|
41
|
+
>
|
|
42
|
+
<OText numberOfLines={1}>
|
|
43
|
+
{category.name}
|
|
44
|
+
</OText>
|
|
45
|
+
</TouchableOpacity>
|
|
46
|
+
<View>
|
|
47
|
+
<ToggleSwitch
|
|
48
|
+
isOn={category?.enabled}
|
|
49
|
+
onColor={theme.colors.primary}
|
|
50
|
+
offColor={theme.colors.offColor}
|
|
51
|
+
size="small"
|
|
52
|
+
onToggle={(value: boolean) => handleSwitch(value, category.id)}
|
|
53
|
+
// disabled={loading}
|
|
54
|
+
animationSpeed={200}
|
|
55
|
+
/>
|
|
56
|
+
</View>
|
|
57
|
+
</CategoryTab>
|
|
58
|
+
)}
|
|
59
|
+
</>
|
|
60
|
+
) : (
|
|
61
|
+
<CategoryTab
|
|
62
|
+
isSpace={!!category?.parent_category_id}
|
|
63
|
+
>
|
|
64
|
+
<TouchableOpacity onPress={() => handlerClickCategory(category)} style={{ flex: 1, marginRight: 5 }}>
|
|
65
|
+
<OText numberOfLines={1}>
|
|
66
|
+
{category.name}
|
|
67
|
+
</OText>
|
|
68
|
+
</TouchableOpacity>
|
|
69
|
+
<View>
|
|
70
|
+
<ToggleSwitch
|
|
71
|
+
isOn={category?.enabled}
|
|
72
|
+
onColor={theme.colors.primary}
|
|
73
|
+
offColor={theme.colors.offColor}
|
|
74
|
+
size="small"
|
|
75
|
+
onToggle={(value: boolean) => handleSwitch(value, category.id)}
|
|
76
|
+
// disabled={loading}
|
|
77
|
+
animationSpeed={200}
|
|
78
|
+
/>
|
|
79
|
+
</View>
|
|
80
|
+
</CategoryTab>
|
|
81
|
+
)}
|
|
82
|
+
</View>
|
|
83
|
+
))}
|
|
84
|
+
{list && list?.length === 0 && isSub && (
|
|
85
|
+
<CategoryTab
|
|
86
|
+
isSpace={!!currentCat?.parent_category_id}
|
|
87
|
+
>
|
|
88
|
+
<TouchableOpacity onPress={() => handlerClickCategory(currentCat)} style={{ flex: 1, marginRight: 5 }}>
|
|
89
|
+
<OText numberOfLines={1}>
|
|
90
|
+
{currentCat.name}
|
|
91
|
+
</OText>
|
|
92
|
+
</TouchableOpacity>
|
|
93
|
+
<View>
|
|
94
|
+
<ToggleSwitch
|
|
95
|
+
isOn={currentCat?.enabled}
|
|
96
|
+
onColor={theme.colors.primary}
|
|
97
|
+
offColor={theme.colors.offColor}
|
|
98
|
+
size="small"
|
|
99
|
+
onToggle={(value: boolean) => handleSwitch(value, currentCat.id)}
|
|
100
|
+
// disabled={loading}
|
|
101
|
+
animationSpeed={200}
|
|
102
|
+
/>
|
|
103
|
+
</View>
|
|
104
|
+
</CategoryTab>
|
|
105
|
+
)}
|
|
106
|
+
</>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { useCallback } from 'react'
|
|
2
|
+
import { StyleSheet, View, TouchableOpacity } from 'react-native'
|
|
3
|
+
import { useTheme } from 'styled-components/native';
|
|
4
|
+
import { OIcon, OText } from '../shared';
|
|
5
|
+
import { NotFoundSource } from '../NotFoundSource';
|
|
6
|
+
import ToggleSwitch from 'toggle-switch-react-native';
|
|
7
|
+
import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
|
|
8
|
+
import { SearchBar } from '../SearchBar';
|
|
9
|
+
import { IOScrollView } from 'react-native-intersection-observer';
|
|
10
|
+
import {
|
|
11
|
+
useLanguage,
|
|
12
|
+
useUtils,
|
|
13
|
+
ToastType,
|
|
14
|
+
useToast,
|
|
15
|
+
} from 'ordering-components/native'
|
|
16
|
+
|
|
17
|
+
const PIXELS_TO_SCROLL = 2000
|
|
18
|
+
|
|
19
|
+
export const ProductList = (props: any) => {
|
|
20
|
+
const { productsList, onClose, updateProduct, searchValue, handleChangeSearch, getCategoryProducts } = props
|
|
21
|
+
|
|
22
|
+
const { loading, products, error } = productsList
|
|
23
|
+
|
|
24
|
+
const theme = useTheme()
|
|
25
|
+
const [{ optimizeImage }] = useUtils();
|
|
26
|
+
const [, { showToast }] = useToast()
|
|
27
|
+
const [, t] = useLanguage()
|
|
28
|
+
|
|
29
|
+
const styles = StyleSheet.create({
|
|
30
|
+
container: {
|
|
31
|
+
flex: 1,
|
|
32
|
+
marginBottom: 0
|
|
33
|
+
},
|
|
34
|
+
header: {
|
|
35
|
+
flexDirection: 'row',
|
|
36
|
+
justifyContent: 'space-between',
|
|
37
|
+
marginBottom: 10,
|
|
38
|
+
},
|
|
39
|
+
btnBackArrow: {
|
|
40
|
+
borderWidth: 0,
|
|
41
|
+
width: 32,
|
|
42
|
+
height: 32,
|
|
43
|
+
tintColor: theme.colors.textGray,
|
|
44
|
+
backgroundColor: theme.colors.clear,
|
|
45
|
+
borderColor: theme.colors.clear,
|
|
46
|
+
shadowColor: theme.colors.clear,
|
|
47
|
+
paddingLeft: 0,
|
|
48
|
+
paddingRight: 0
|
|
49
|
+
},
|
|
50
|
+
sectionTitle: {
|
|
51
|
+
fontStyle: 'normal',
|
|
52
|
+
fontWeight: '600',
|
|
53
|
+
fontSize: 20,
|
|
54
|
+
color: theme.colors.textGray,
|
|
55
|
+
},
|
|
56
|
+
logo: {
|
|
57
|
+
padding: 2,
|
|
58
|
+
borderRadius: 18,
|
|
59
|
+
shadowColor: '#000',
|
|
60
|
+
shadowOffset: {
|
|
61
|
+
width: 0,
|
|
62
|
+
height: 1.5,
|
|
63
|
+
},
|
|
64
|
+
shadowOpacity: 0.21,
|
|
65
|
+
shadowRadius: 3,
|
|
66
|
+
elevation: 7,
|
|
67
|
+
},
|
|
68
|
+
icon: {
|
|
69
|
+
borderRadius: 7.6,
|
|
70
|
+
width: 35,
|
|
71
|
+
height: 35,
|
|
72
|
+
marginRight: 5
|
|
73
|
+
},
|
|
74
|
+
borderStyle: {
|
|
75
|
+
borderColor: theme.colors.red,
|
|
76
|
+
borderWidth: 0,
|
|
77
|
+
borderRadius: 10,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const handleSwitch = (enabled: boolean, categoryId: any, productId: any) => {
|
|
82
|
+
updateProduct && updateProduct(categoryId, productId, { enabled })
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const handleScroll = ({ nativeEvent }: any) => {
|
|
86
|
+
const y = nativeEvent.contentOffset.y;
|
|
87
|
+
const height = nativeEvent.contentSize.height;
|
|
88
|
+
const hasMore = !(
|
|
89
|
+
productsList.pagination.totalPages === productsList.pagination.currentPage
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (y + PIXELS_TO_SCROLL > height && !productsList.loading && hasMore && productsList?.products?.length > 0) {
|
|
93
|
+
getCategoryProducts(false)
|
|
94
|
+
showToast(ToastType.Info, t('LOADING_MORE_PRODUCTS', 'Loading more products'))
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<View style={{ flex: 1, paddingHorizontal: 20, paddingVertical: 20 }}>
|
|
100
|
+
<View style={styles.header}>
|
|
101
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
102
|
+
<TouchableOpacity
|
|
103
|
+
onPress={onClose}
|
|
104
|
+
style={styles.btnBackArrow}
|
|
105
|
+
>
|
|
106
|
+
<OIcon src={theme.images.general.arrow_left} color={theme.colors.textGray} />
|
|
107
|
+
</TouchableOpacity>
|
|
108
|
+
<OText style={styles.sectionTitle}>{t('PRODUCTS', 'Products')}</OText>
|
|
109
|
+
</View>
|
|
110
|
+
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
|
|
111
|
+
<SearchBar
|
|
112
|
+
borderStyle={styles.borderStyle}
|
|
113
|
+
onSearch={handleChangeSearch}
|
|
114
|
+
searchValue={searchValue}
|
|
115
|
+
lazyLoad
|
|
116
|
+
isCancelXButtonShow={!!searchValue}
|
|
117
|
+
onCancel={() => handleChangeSearch('')}
|
|
118
|
+
placeholder={t('SEARCH', 'Search')}
|
|
119
|
+
containerStyle={{ width: 180 }}
|
|
120
|
+
/>
|
|
121
|
+
</View>
|
|
122
|
+
</View>
|
|
123
|
+
<IOScrollView
|
|
124
|
+
style={styles.container}
|
|
125
|
+
onScroll={handleScroll}
|
|
126
|
+
scrollEventThrottle={16}
|
|
127
|
+
bounces={false}
|
|
128
|
+
>
|
|
129
|
+
{!loading && products?.length === 0 && (
|
|
130
|
+
<NotFoundSource
|
|
131
|
+
content={t('NO_RESULTS_FOUND', 'Sorry, no results found')}
|
|
132
|
+
image={theme.images.general.notFound}
|
|
133
|
+
conditioned={false}
|
|
134
|
+
/>
|
|
135
|
+
)}
|
|
136
|
+
{!loading && products?.length > 0 && (
|
|
137
|
+
<View style={{ borderTopColor: theme.colors.borderTops, borderTopWidth: 1 }}>
|
|
138
|
+
{products.map((product: any, i: number) => (
|
|
139
|
+
<View
|
|
140
|
+
key={i}
|
|
141
|
+
style={{
|
|
142
|
+
flexDirection: 'row',
|
|
143
|
+
justifyContent: 'space-between',
|
|
144
|
+
borderBottomColor: theme.colors.borderTops,
|
|
145
|
+
borderBottomWidth: 1,
|
|
146
|
+
paddingVertical: 15
|
|
147
|
+
}}
|
|
148
|
+
>
|
|
149
|
+
<View style={{ flex: 1, flexDirection: 'row', alignItems: 'center', marginRight: 36 }}>
|
|
150
|
+
<OIcon
|
|
151
|
+
url={optimizeImage(product?.images, 'h_300,c_limit')}
|
|
152
|
+
src={!product?.images && theme?.images?.dummies?.businessLogo}
|
|
153
|
+
style={styles.icon}
|
|
154
|
+
/>
|
|
155
|
+
<OText numberOfLines={2} size={12} ellipsizeMode='tail'>{product?.name}</OText>
|
|
156
|
+
</View>
|
|
157
|
+
<ToggleSwitch
|
|
158
|
+
isOn={product?.enabled}
|
|
159
|
+
onColor={theme.colors.primary}
|
|
160
|
+
offColor={theme.colors.offColor}
|
|
161
|
+
size="small"
|
|
162
|
+
onToggle={(value: boolean) => handleSwitch(value, product?.category_id, product.id)}
|
|
163
|
+
disabled={loading}
|
|
164
|
+
animationSpeed={200}
|
|
165
|
+
/>
|
|
166
|
+
</View>
|
|
167
|
+
))}
|
|
168
|
+
</View>
|
|
169
|
+
)}
|
|
170
|
+
{loading && (
|
|
171
|
+
<View style={{ borderTopColor: theme.colors.borderTops, borderTopWidth: 1 }}>
|
|
172
|
+
{[...Array(6)].map((item, i) => (
|
|
173
|
+
<Placeholder key={i} Animation={Fade}>
|
|
174
|
+
<View
|
|
175
|
+
style={{
|
|
176
|
+
flex: 1,
|
|
177
|
+
flexDirection: 'row',
|
|
178
|
+
justifyContent: 'space-between',
|
|
179
|
+
alignItems: 'center',
|
|
180
|
+
marginBottom: 10,
|
|
181
|
+
borderBottomColor: theme.colors.borderTops,
|
|
182
|
+
borderBottomWidth: 1,
|
|
183
|
+
paddingVertical: 10
|
|
184
|
+
}}
|
|
185
|
+
>
|
|
186
|
+
<PlaceholderLine width={50} />
|
|
187
|
+
<PlaceholderLine width={20} />
|
|
188
|
+
</View>
|
|
189
|
+
</Placeholder>
|
|
190
|
+
))}
|
|
191
|
+
</View>
|
|
192
|
+
)}
|
|
193
|
+
</IOScrollView>
|
|
194
|
+
</View>
|
|
195
|
+
)
|
|
196
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { View, StyleSheet, ScrollView, Dimensions, TouchableOpacity } from 'react-native';
|
|
3
|
+
import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
|
|
4
|
+
import { useTheme } from 'styled-components/native';
|
|
5
|
+
import { SearchBar } from '../SearchBar';
|
|
6
|
+
import {
|
|
7
|
+
ToastType,
|
|
8
|
+
useToast,
|
|
9
|
+
useLanguage,
|
|
10
|
+
StoreProductList
|
|
11
|
+
} from 'ordering-components/native';
|
|
12
|
+
import { NotFoundSource } from '../NotFoundSource';
|
|
13
|
+
import { OText, OIcon } from '../shared';
|
|
14
|
+
import { IterateCategories } from './IterateCategories';
|
|
15
|
+
import { ProductList } from './ProductList'
|
|
16
|
+
|
|
17
|
+
const BusinessProductListUI = (props: any) => {
|
|
18
|
+
const {
|
|
19
|
+
navigation,
|
|
20
|
+
businessState,
|
|
21
|
+
productsList,
|
|
22
|
+
updateStoreCategory,
|
|
23
|
+
updateStoreProduct,
|
|
24
|
+
productSearch,
|
|
25
|
+
categorySearch,
|
|
26
|
+
handleChangeCategory,
|
|
27
|
+
handleChangeProductSearch,
|
|
28
|
+
handleChangeCategorySearch,
|
|
29
|
+
getCategoryProducts,
|
|
30
|
+
categories
|
|
31
|
+
} = props;
|
|
32
|
+
|
|
33
|
+
const { loading, error, business } = businessState;
|
|
34
|
+
|
|
35
|
+
const [, t] = useLanguage();
|
|
36
|
+
const [, { showToast }] = useToast();
|
|
37
|
+
const theme = useTheme();
|
|
38
|
+
|
|
39
|
+
const [showModal, setShowModal] = useState(false)
|
|
40
|
+
|
|
41
|
+
const handleOpenProducts = (category: any) => {
|
|
42
|
+
handleChangeCategory(category)
|
|
43
|
+
setShowModal(true)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (error) {
|
|
48
|
+
showToast(
|
|
49
|
+
ToastType.Error,
|
|
50
|
+
error || error[0] || t('NETWORK_ERROR', 'Network Error'),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}, [loading]);
|
|
54
|
+
|
|
55
|
+
const styles = StyleSheet.create({
|
|
56
|
+
container: {
|
|
57
|
+
paddingBottom: 20,
|
|
58
|
+
marginBottom: 0,
|
|
59
|
+
flex: 1,
|
|
60
|
+
},
|
|
61
|
+
header: {
|
|
62
|
+
flexDirection: 'row',
|
|
63
|
+
justifyContent: 'space-between',
|
|
64
|
+
marginBottom: 10,
|
|
65
|
+
},
|
|
66
|
+
sectionTitle: {
|
|
67
|
+
fontStyle: 'normal',
|
|
68
|
+
fontWeight: '600',
|
|
69
|
+
fontSize: 20,
|
|
70
|
+
color: theme.colors.textGray,
|
|
71
|
+
},
|
|
72
|
+
borderStyle: {
|
|
73
|
+
borderColor: theme.colors.red,
|
|
74
|
+
borderWidth: 0,
|
|
75
|
+
borderRadius: 10,
|
|
76
|
+
},
|
|
77
|
+
btnBackArrow: {
|
|
78
|
+
borderWidth: 0,
|
|
79
|
+
width: 32,
|
|
80
|
+
height: 32,
|
|
81
|
+
tintColor: theme.colors.textGray,
|
|
82
|
+
backgroundColor: theme.colors.clear,
|
|
83
|
+
borderColor: theme.colors.clear,
|
|
84
|
+
shadowColor: theme.colors.clear,
|
|
85
|
+
paddingLeft: 0,
|
|
86
|
+
paddingRight: 0
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<>
|
|
92
|
+
<View style={styles.header}>
|
|
93
|
+
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
|
94
|
+
<TouchableOpacity
|
|
95
|
+
onPress={() => navigation?.canGoBack() && navigation.goBack()}
|
|
96
|
+
style={styles.btnBackArrow}
|
|
97
|
+
>
|
|
98
|
+
<OIcon src={theme.images.general.arrow_left} color={theme.colors.textGray} />
|
|
99
|
+
</TouchableOpacity>
|
|
100
|
+
<OText style={styles.sectionTitle}>{t('CATEGORIES', 'Categories')}</OText>
|
|
101
|
+
</View>
|
|
102
|
+
<View style={{ flexDirection: 'row', justifyContent: 'flex-end' }}>
|
|
103
|
+
<SearchBar
|
|
104
|
+
borderStyle={styles.borderStyle}
|
|
105
|
+
onSearch={handleChangeCategorySearch}
|
|
106
|
+
searchValue={categorySearch}
|
|
107
|
+
lazyLoad
|
|
108
|
+
isCancelXButtonShow={!!categorySearch}
|
|
109
|
+
onCancel={() => handleChangeCategorySearch('')}
|
|
110
|
+
placeholder={t('SEARCH', 'Search')}
|
|
111
|
+
containerStyle={{ width: 180 }}
|
|
112
|
+
/>
|
|
113
|
+
</View>
|
|
114
|
+
</View>
|
|
115
|
+
<ScrollView
|
|
116
|
+
showsVerticalScrollIndicator={false}
|
|
117
|
+
style={styles.container}>
|
|
118
|
+
{!loading && business?.categories?.length === 0 && (
|
|
119
|
+
<NotFoundSource
|
|
120
|
+
content={t('NO_RESULTS_FOUND', 'Sorry, no results found')}
|
|
121
|
+
image={theme.images.general.notFound}
|
|
122
|
+
conditioned={false}
|
|
123
|
+
/>
|
|
124
|
+
)}
|
|
125
|
+
{!error && !loading && categories?.length > 0 && (
|
|
126
|
+
<View
|
|
127
|
+
style={{
|
|
128
|
+
borderTopColor: theme.colors.borderTops,
|
|
129
|
+
borderTopWidth: 1
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
<IterateCategories
|
|
133
|
+
list={categories}
|
|
134
|
+
handlerClickCategory={handleOpenProducts}
|
|
135
|
+
updateCategory={updateStoreCategory}
|
|
136
|
+
/>
|
|
137
|
+
</View>
|
|
138
|
+
)}
|
|
139
|
+
{loading && (
|
|
140
|
+
<View style={{ borderTopColor: theme.colors.borderTops, borderTopWidth: 1 }}>
|
|
141
|
+
{[...Array(6)].map((item, i) => (
|
|
142
|
+
<Placeholder key={i} Animation={Fade}>
|
|
143
|
+
<View
|
|
144
|
+
style={{
|
|
145
|
+
flex: 1,
|
|
146
|
+
flexDirection: 'row',
|
|
147
|
+
justifyContent: 'space-between',
|
|
148
|
+
alignItems: 'center',
|
|
149
|
+
marginBottom: 10,
|
|
150
|
+
borderBottomColor: theme.colors.borderTops,
|
|
151
|
+
borderBottomWidth: 1,
|
|
152
|
+
paddingVertical: 10
|
|
153
|
+
}}
|
|
154
|
+
>
|
|
155
|
+
<PlaceholderLine width={50} />
|
|
156
|
+
<PlaceholderLine width={20} />
|
|
157
|
+
</View>
|
|
158
|
+
</Placeholder>
|
|
159
|
+
))}
|
|
160
|
+
</View>
|
|
161
|
+
)}
|
|
162
|
+
</ScrollView>
|
|
163
|
+
{showModal && (
|
|
164
|
+
<View
|
|
165
|
+
style={{
|
|
166
|
+
flex: 1,
|
|
167
|
+
position: 'absolute',
|
|
168
|
+
top: 0,
|
|
169
|
+
width: Dimensions.get('window').width,
|
|
170
|
+
height: Dimensions.get('window').height,
|
|
171
|
+
backgroundColor: theme.colors.backgroundLight,
|
|
172
|
+
left: 0
|
|
173
|
+
}}
|
|
174
|
+
>
|
|
175
|
+
<ProductList
|
|
176
|
+
productsList={productsList}
|
|
177
|
+
updateProduct={updateStoreProduct}
|
|
178
|
+
searchValue={productSearch}
|
|
179
|
+
handleChangeSearch={handleChangeProductSearch}
|
|
180
|
+
getCategoryProducts={getCategoryProducts}
|
|
181
|
+
onClose={() => setShowModal(false)}
|
|
182
|
+
/>
|
|
183
|
+
</View>
|
|
184
|
+
)}
|
|
185
|
+
</>
|
|
186
|
+
);
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export const BusinessProductList = (props: any) => {
|
|
190
|
+
const businessProductListProps = {
|
|
191
|
+
...props,
|
|
192
|
+
UIComponent: BusinessProductListUI,
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return <StoreProductList {...businessProductListProps} />;
|
|
196
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import styled from 'styled-components/native';
|
|
2
|
+
|
|
3
|
+
export const CategoryTab = styled.View`
|
|
4
|
+
flex-direction: row;
|
|
5
|
+
justify-content: space-between;
|
|
6
|
+
padding-vertical: 10px;
|
|
7
|
+
border-bottom-color: ${(props: any) => props.theme.colors.borderTops};
|
|
8
|
+
border-bottom-width: 1px;
|
|
9
|
+
margin-left: ${(props: any) => props.isSpace ? '10px' : '0px'};
|
|
10
|
+
`
|
|
@@ -16,6 +16,7 @@ export const SearchBar = (props: any) => {
|
|
|
16
16
|
isCancelXButtonShow,
|
|
17
17
|
noBorderShow,
|
|
18
18
|
borderStyle,
|
|
19
|
+
containerStyle
|
|
19
20
|
} = props;
|
|
20
21
|
|
|
21
22
|
const [, t] = useLanguage();
|
|
@@ -67,7 +68,7 @@ export const SearchBar = (props: any) => {
|
|
|
67
68
|
});
|
|
68
69
|
|
|
69
70
|
return (
|
|
70
|
-
<View style={
|
|
71
|
+
<View style={{ ...styles.container, ...containerStyle}}>
|
|
71
72
|
<OInput
|
|
72
73
|
forwardRef={inputRef}
|
|
73
74
|
value={searchValue}
|
|
@@ -133,7 +133,8 @@ const StoresListUI = (props: BusinessesListingParams) => {
|
|
|
133
133
|
lazyLoad
|
|
134
134
|
isCancelXButtonShow={!!searchValue}
|
|
135
135
|
onCancel={() => handleChangeSearch('')}
|
|
136
|
-
placeholder={t('
|
|
136
|
+
placeholder={t('SEARCH', 'Search')}
|
|
137
|
+
containerStyle={{ width: 210 }}
|
|
137
138
|
/>
|
|
138
139
|
</View>
|
|
139
140
|
)}
|
|
@@ -180,6 +181,7 @@ const StoresListUI = (props: BusinessesListingParams) => {
|
|
|
180
181
|
isBusinessOpen={business?.open}
|
|
181
182
|
setIsUpdateStore={setIsUpdateStore}
|
|
182
183
|
isUpdateStore={isUpdateStore}
|
|
184
|
+
navigation={navigation}
|
|
183
185
|
/>
|
|
184
186
|
))}
|
|
185
187
|
|
|
@@ -173,6 +173,7 @@ export interface BusinessControllerParams {
|
|
|
173
173
|
isBusinessOpen?: boolean;
|
|
174
174
|
businessWillCloseSoonMinutes?: number;
|
|
175
175
|
updateBusiness?: (id: any, value: any) => {};
|
|
176
|
+
navigation?: any;
|
|
176
177
|
}
|
|
177
178
|
export interface BusinessProductsListingParams {
|
|
178
179
|
navigation?: any;
|