ordering-ui-react-native 0.21.53 → 0.21.54

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.21.53",
3
+ "version": "0.21.54",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,45 +1,56 @@
1
- import React from 'react'
2
- import { ScrollView, StyleSheet, View } from 'react-native'
1
+ import React, { useCallback } from 'react'
2
+ import { StyleSheet, View, TouchableOpacity } from 'react-native'
3
3
  import { useTheme } from 'styled-components/native';
4
- import { OIcon, OText, OIconButton } from '../shared';
4
+ import { OIcon, OText } from '../shared';
5
5
  import { NotFoundSource } from '../NotFoundSource';
6
6
  import ToggleSwitch from 'toggle-switch-react-native';
7
7
  import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
8
+ import { SearchBar } from '../SearchBar';
9
+ import { IOScrollView } from 'react-native-intersection-observer';
8
10
  import {
9
11
  useLanguage,
10
- useUtils
12
+ useUtils,
13
+ ToastType,
14
+ useToast,
11
15
  } from 'ordering-components/native'
12
16
 
17
+ const PIXELS_TO_SCROLL = 2000
18
+
13
19
  export const ProductList = (props: any) => {
14
- const { categoryState, onClose, updateProduct } = props
20
+ const { productsList, onClose, updateProduct, searchValue, handleChangeSearch, getCategoryProducts } = props
15
21
 
16
- const { loading, products, error } = categoryState
22
+ const { loading, products, error } = productsList
17
23
 
18
24
  const theme = useTheme()
19
25
  const [{ optimizeImage }] = useUtils();
26
+ const [, { showToast }] = useToast()
20
27
  const [, t] = useLanguage()
21
28
 
22
29
  const styles = StyleSheet.create({
23
30
  container: {
24
- paddingBottom: 20,
25
- marginBottom: 0,
26
31
  flex: 1,
32
+ marginBottom: 0
27
33
  },
28
34
  header: {
29
35
  flexDirection: 'row',
30
36
  justifyContent: 'space-between',
31
37
  marginBottom: 10,
32
38
  },
33
- arrowLeft: {
34
- maxWidth: 40,
35
- height: 25,
36
- justifyContent: 'flex-end',
37
- marginTop: 8
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
38
49
  },
39
50
  sectionTitle: {
40
51
  fontStyle: 'normal',
41
52
  fontWeight: '600',
42
- fontSize: 24,
53
+ fontSize: 20,
43
54
  color: theme.colors.textGray,
44
55
  },
45
56
  logo: {
@@ -60,27 +71,60 @@ export const ProductList = (props: any) => {
60
71
  height: 35,
61
72
  marginRight: 5
62
73
  },
74
+ borderStyle: {
75
+ borderColor: theme.colors.red,
76
+ borderWidth: 0,
77
+ borderRadius: 10,
78
+ },
63
79
  });
64
80
 
65
81
  const handleSwitch = (enabled: boolean, categoryId: any, productId: any) => {
66
82
  updateProduct && updateProduct(categoryId, productId, { enabled })
67
83
  };
68
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
+
69
98
  return (
70
99
  <View style={{ flex: 1, paddingHorizontal: 20, paddingVertical: 20 }}>
71
100
  <View style={styles.header}>
72
- <OIconButton
73
- icon={theme.images.general.arrow_left}
74
- borderColor={theme.colors.clear}
75
- iconStyle={{ width: 20, height: 20 }}
76
- style={styles.arrowLeft}
77
- onClick={onClose}
78
- />
79
- <OText style={styles.sectionTitle}>{t('PRODUCTS', 'Products')}</OText>
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('FIND_PRODUCT', 'Find a product')}
119
+ />
120
+ </View>
80
121
  </View>
81
- <ScrollView
82
- showsVerticalScrollIndicator={false}
83
- style={styles.container}>
122
+ <IOScrollView
123
+ style={styles.container}
124
+ onScroll={handleScroll}
125
+ scrollEventThrottle={16}
126
+ bounces={false}
127
+ >
84
128
  {!loading && products?.length === 0 && (
85
129
  <NotFoundSource
86
130
  content={t('NO_RESULTS_FOUND', 'Sorry, no results found')}
@@ -98,7 +142,7 @@ export const ProductList = (props: any) => {
98
142
  justifyContent: 'space-between',
99
143
  borderBottomColor: theme.colors.borderTops,
100
144
  borderBottomWidth: 1,
101
- paddingVertical: 10
145
+ paddingVertical: 15
102
146
  }}
103
147
  >
104
148
  <View style={{ flex: 1, flexDirection: 'row', alignItems: 'center', marginRight: 36 }}>
@@ -145,7 +189,7 @@ export const ProductList = (props: any) => {
145
189
  ))}
146
190
  </View>
147
191
  )}
148
- </ScrollView>
192
+ </IOScrollView>
149
193
  </View>
150
194
  )
151
195
  }
@@ -1,15 +1,16 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { View, StyleSheet, ScrollView, Dimensions } from 'react-native';
2
+ import { View, StyleSheet, ScrollView, Dimensions, TouchableOpacity } from 'react-native';
3
3
  import { Placeholder, PlaceholderLine, Fade } from 'rn-placeholder';
4
4
  import { useTheme } from 'styled-components/native';
5
+ import { SearchBar } from '../SearchBar';
5
6
  import {
6
7
  ToastType,
7
8
  useToast,
8
9
  useLanguage,
9
- BusinessAndProductList,
10
+ StoreProductList
10
11
  } from 'ordering-components/native';
11
12
  import { NotFoundSource } from '../NotFoundSource';
12
- import { OText, OIconButton } from '../shared';
13
+ import { OText, OIcon } from '../shared';
13
14
  import { IterateCategories } from './IterateCategories';
14
15
  import { ProductList } from './ProductList'
15
16
 
@@ -17,10 +18,16 @@ const BusinessProductListUI = (props: any) => {
17
18
  const {
18
19
  navigation,
19
20
  businessState,
20
- handleChangeCategory,
21
- categoryState,
21
+ productsList,
22
22
  updateStoreCategory,
23
- updateStoreProduct
23
+ updateStoreProduct,
24
+ productSearch,
25
+ categorySearch,
26
+ handleChangeCategory,
27
+ handleChangeProductSearch,
28
+ handleChangeCategorySearch,
29
+ getCategoryProducts,
30
+ categories
24
31
  } = props;
25
32
 
26
33
  const { loading, error, business } = businessState;
@@ -59,28 +66,50 @@ const BusinessProductListUI = (props: any) => {
59
66
  sectionTitle: {
60
67
  fontStyle: 'normal',
61
68
  fontWeight: '600',
62
- fontSize: 24,
69
+ fontSize: 20,
63
70
  color: theme.colors.textGray,
64
71
  },
65
- arrowLeft: {
66
- maxWidth: 40,
67
- height: 25,
68
- justifyContent: 'flex-end',
69
- marginTop: 8
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
70
87
  },
71
88
  });
72
89
 
73
90
  return (
74
91
  <>
75
92
  <View style={styles.header}>
76
- <OIconButton
77
- icon={theme.images.general.arrow_left}
78
- borderColor={theme.colors.clear}
79
- iconStyle={{ width: 20, height: 20 }}
80
- style={styles.arrowLeft}
81
- onClick={() => navigation?.canGoBack() && navigation.goBack()}
82
- />
83
- <OText style={styles.sectionTitle}>{t('CATEGORIES', 'Categories')}</OText>
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('FIND_CATEGORY', 'Find a category')}
111
+ />
112
+ </View>
84
113
  </View>
85
114
  <ScrollView
86
115
  showsVerticalScrollIndicator={false}
@@ -92,7 +121,7 @@ const BusinessProductListUI = (props: any) => {
92
121
  conditioned={false}
93
122
  />
94
123
  )}
95
- {!error && !loading && business?.categories?.length > 0 && (
124
+ {!error && !loading && categories?.length > 0 && (
96
125
  <View
97
126
  style={{
98
127
  borderTopColor: theme.colors.borderTops,
@@ -100,7 +129,7 @@ const BusinessProductListUI = (props: any) => {
100
129
  }}
101
130
  >
102
131
  <IterateCategories
103
- list={business?.categories}
132
+ list={categories}
104
133
  handlerClickCategory={handleOpenProducts}
105
134
  updateCategory={updateStoreCategory}
106
135
  />
@@ -143,8 +172,11 @@ const BusinessProductListUI = (props: any) => {
143
172
  }}
144
173
  >
145
174
  <ProductList
146
- categoryState={categoryState}
175
+ productsList={productsList}
147
176
  updateProduct={updateStoreProduct}
177
+ searchValue={productSearch}
178
+ handleChangeSearch={handleChangeProductSearch}
179
+ getCategoryProducts={getCategoryProducts}
148
180
  onClose={() => setShowModal(false)}
149
181
  />
150
182
  </View>
@@ -156,9 +188,8 @@ const BusinessProductListUI = (props: any) => {
156
188
  export const BusinessProductList = (props: any) => {
157
189
  const businessProductListProps = {
158
190
  ...props,
159
- isFetchAllProducts: true,
160
191
  UIComponent: BusinessProductListUI,
161
192
  };
162
193
 
163
- return <BusinessAndProductList {...businessProductListProps} />;
194
+ return <StoreProductList {...businessProductListProps} />;
164
195
  };