ordering-ui-react-native 0.15.99 → 0.16.2

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.15.99",
3
+ "version": "0.16.2",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -123,7 +123,8 @@
123
123
  "@babel/core": "^7.11.6",
124
124
  "@babel/runtime": "^7.11.2",
125
125
  "@react-native-community/eslint-config": "^2.0.0",
126
- "@types/react": "^16.9.51",
126
+ "@types/react": "^18.0.14",
127
+ "@types/react-dom": "^18.0.5",
127
128
  "@types/react-native": "^0.63.25",
128
129
  "babel-jest": "^26.3.0",
129
130
  "eslint": "^7.10.0",
@@ -37,7 +37,7 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
37
37
  imageStyle: {
38
38
  width: 120,
39
39
  height: 90,
40
- resizeMode: 'cover',
40
+ resizeMode: 'contain',
41
41
  borderRadius: 10
42
42
  },
43
43
  closeUpsellingButton: {
@@ -84,7 +84,7 @@ export const AcceptOrRejectOrder = (props: AcceptOrRejectOrderParams) => {
84
84
  backgroundColor: '#fff',
85
85
  borderColor: theme.colors.lightGray,
86
86
  overflow: 'hidden',
87
- minHeight: 155
87
+ minHeight: 120
88
88
  },
89
89
  rowStyle: {
90
90
  display: 'flex',
@@ -62,6 +62,10 @@ const CartBottomSheetUI = (props: CartBottomSheetUIProps): React.ReactElement |
62
62
  }
63
63
 
64
64
  const handleEditProduct = (product: any) => {
65
+ if (props.onEditProduct) {
66
+ props.onEditProduct(product)
67
+ return
68
+ }
65
69
  setCurProduct(product)
66
70
  setModalIsOpen(true)
67
71
  }
@@ -148,7 +152,7 @@ const CartBottomSheetUI = (props: CartBottomSheetUIProps): React.ReactElement |
148
152
  <StyledBottomContent
149
153
  style={{bottom:10}}
150
154
  minHeight={props.height * 0.01}
151
- >
155
+ >
152
156
  <OButton
153
157
  text={(cart?.subtotal >= cart?.minimum || !cart?.minimum) && cart?.valid_address ? (
154
158
  !openUpselling !== canOpenUpselling ? `${t('CHECKOUT', 'Checkout')} ${parsePrice(cart?.total)}`: t('LOADING', 'Loading')
@@ -198,6 +202,7 @@ const CartBottomSheetUI = (props: CartBottomSheetUIProps): React.ReactElement |
198
202
  canOpenUpselling={canOpenUpselling}
199
203
  setCanOpenUpselling={setCanOpenUpselling}
200
204
  onClose={onCloseUpselling}
205
+ onAddProduct={props.onAddProduct}
201
206
  resetInactivityTimeout={resetInactivityTimeout}
202
207
  />
203
208
  )}
@@ -231,7 +236,7 @@ const TopBar = (props:any) => {
231
236
  <OIconButton
232
237
  bgColor="transparent"
233
238
  borderColor="transparent"
234
- RenderIcon={() =>
239
+ RenderIcon={() =>
235
240
  <EvilIcons
236
241
  name={'close'}
237
242
  size={40}
@@ -260,6 +265,8 @@ interface CartBottomSheetUIProps {
260
265
  onNavigationRedirect: any,
261
266
  clearInactivityTimeout: any,
262
267
  resetInactivityTimeout: any,
268
+ onEditProduct: any,
269
+ onAddProduct: any,
263
270
  }
264
271
 
265
272
  export const CartBottomSheet = (props: any) => {
@@ -1,10 +1,7 @@
1
1
  import React, { useEffect, useState } from 'react';
2
- import { useLanguage } from 'ordering-components/native';
3
2
  import { useCartBottomSheet } from '../../providers/CartBottomSheetProvider';
4
- import { CCNotCarts } from './styles';
5
3
 
6
4
  import { Cart } from '../Cart';
7
- import { OText } from '../shared';
8
5
  import Spinner from 'react-native-loading-spinner-overlay';
9
6
  import { Cart as TypeCart } from '../../types';
10
7
 
@@ -20,7 +17,6 @@ export const CartContent = (props: any) => {
20
17
  resetInactivityTimeout,
21
18
  }: Props = props
22
19
 
23
- const [, t] = useLanguage()
24
20
  const [isCartsLoading, setIsCartsLoading] = useState(false)
25
21
  const [, { hideCartBottomSheet }] = useCartBottomSheet();
26
22
 
@@ -56,13 +52,6 @@ export const CartContent = (props: any) => {
56
52
  }
57
53
  </>
58
54
  )}
59
- {/* {(!cart && showNotFound) && (
60
- <CCNotCarts>
61
- <OText size={24} style={{ textAlign: 'center' }}>
62
- {t('CARTS_NOT_FOUND', 'You don\'t have carts available')}
63
- </OText>
64
- </CCNotCarts>
65
- )} */}
66
55
  <Spinner visible={isCartsLoading} />
67
56
  </>
68
57
  )
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useCallback, useState } from 'react';
2
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'
@@ -41,20 +41,22 @@ const CategoriesMenu = (props: any): React.ReactElement => {
41
41
 
42
42
  const theme = useTheme()
43
43
  const [, t] = useLanguage();
44
- const [curIndexCateg, setIndexCateg] = useState(categories.indexOf(category));
45
44
  const [{ parsePrice }] = useUtils();
46
45
  const [orientationState] = useDeviceOrientation();
47
46
  const [bottomSheetVisibility, { showCartBottomSheet, hideCartBottomSheet }] = useCartBottomSheet();
48
- const [productSelected, setProductSelected] = useState({})
47
+
48
+ const [productState, setProductState] = useState<any>(null)
49
+ const [productSelected, setProductSelected] = useState<any>({})
50
+ const [curIndexCateg, setIndexCateg] = useState(categories.indexOf(category));
49
51
  const [drawerState, setDrawerState] = useState({ isOpen: false, data: { order: null } });
50
52
 
51
53
  const width_dimension = Dimensions.get('window').width;
52
54
  const height_dimension = Dimensions.get('window').height;
53
-
55
+
54
56
  const KeyboardView = styled.KeyboardAvoidingView`
55
57
  flex: 1;
56
58
  `;
57
-
59
+
58
60
  const onChangeTabs = (idx: number) => {
59
61
  resetInactivityTimeout();
60
62
  setIndexCateg(idx);
@@ -76,6 +78,16 @@ const CategoriesMenu = (props: any): React.ReactElement => {
76
78
  cart = cartsList?.find((item: any) => item.business_id == businessId);
77
79
  }
78
80
 
81
+ const onEditProduct = (product: any) => {
82
+ setProductSelected({ ...product, _isEditProduct: true })
83
+ setDrawerValues({ isOpen: true, data: null })
84
+ }
85
+
86
+ const onAddProduct = (product: any) => {
87
+ setProductSelected(product)
88
+ setDrawerValues({ isOpen: true, data: null })
89
+ }
90
+
79
91
  const cartProps = {
80
92
  ...props,
81
93
  cart,
@@ -88,16 +100,32 @@ const CategoriesMenu = (props: any): React.ReactElement => {
88
100
  visible: bottomSheetVisibility,
89
101
  clearInactivityTimeout,
90
102
  resetInactivityTimeout,
103
+ onEditProduct,
104
+ onAddProduct
91
105
  },
92
106
  showNotFound: false,
93
107
  showCartBottomSheet,
94
108
  }
95
109
 
110
+ const onClickDrawer = () => {
111
+ setDrawerValues({ isOpen: !drawerState.isOpen, data: null })
112
+ setProductState(null)
113
+ }
114
+
115
+ const onSaveProductForm = () => {
116
+ showCartBottomSheet()
117
+ onClickDrawer()
118
+ }
119
+
96
120
  const onToggleCart = () => {
97
121
  if (bottomSheetVisibility) hideCartBottomSheet();
98
122
  else showCartBottomSheet();
99
123
  }
100
124
 
125
+ const onProductStateChange = useCallback((val: any) => {
126
+ setProductState({ ...productState, ...val })
127
+ }, [setProductState])
128
+
101
129
  return (
102
130
  <>
103
131
  <View style={{
@@ -144,12 +172,14 @@ const CategoriesMenu = (props: any): React.ReactElement => {
144
172
  onSelectItem={onChangeTabs}
145
173
  />
146
174
 
147
- <GridContainer
148
- style={{
149
- marginTop: 20,
175
+ <GridContainer
176
+ style={{
177
+ marginTop: 20,
150
178
  paddingLeft: orientationState?.orientation === LANDSCAPE
151
- ? bottomSheetVisibility ? orientationState?.dimensions?.width * 0.004 :orientationState?.dimensions?.width * 0.008
152
- : 0
179
+ ? bottomSheetVisibility
180
+ ? orientationState?.dimensions?.width * 0.004
181
+ : orientationState?.dimensions?.width * 0.008
182
+ : 0
153
183
  }}
154
184
  >
155
185
  {categories[curIndexCateg].products.map((product) => (
@@ -170,8 +200,7 @@ const CategoriesMenu = (props: any): React.ReactElement => {
170
200
  onPress={() => {
171
201
  resetInactivityTimeout()
172
202
  if (isDrawer) {
173
- setProductSelected(product)
174
- setDrawerValues({ isOpen: true, data: null })
203
+ onAddProduct && onAddProduct(product)
175
204
  } else {
176
205
  navigation.navigate('ProductDetails', {
177
206
  businessId,
@@ -191,23 +220,22 @@ const CategoriesMenu = (props: any): React.ReactElement => {
191
220
  </GridContainer>
192
221
  </Container>
193
222
  </View>
194
-
195
- <View
196
- style={{
197
- flex: bottomSheetVisibility && orientationState?.orientation === PORTRAIT ? 0 : 0.8,
198
- display: bottomSheetVisibility ? 'flex' : 'none'
199
- }}
200
- >
201
- <CartContent
202
- {...cartProps}
203
- />
204
- </View>
223
+ <View
224
+ style={{
225
+ flex: bottomSheetVisibility && orientationState?.orientation === PORTRAIT ? 0 : 0.8,
226
+ display: bottomSheetVisibility ? 'flex' : 'none'
227
+ }}
228
+ >
229
+ <CartContent
230
+ {...cartProps}
231
+ />
232
+ </View>
205
233
  </View>
206
234
  <DrawerView
207
235
  isOpen={drawerState.isOpen}
208
236
  width={width_dimension - (width_dimension * 0.4)}
209
237
  height={height_dimension}
210
- onClickIcon={() => setDrawerValues({ isOpen: !drawerState.isOpen, data: null })}
238
+ onClickIcon={onClickDrawer}
211
239
  >
212
240
  <KeyboardView
213
241
  enabled
@@ -215,14 +243,24 @@ const CategoriesMenu = (props: any): React.ReactElement => {
215
243
  >
216
244
  <ProductForm
217
245
  isDrawer
218
- product={productSelected}
219
- businessId={parseInt(businessId, 10)}
220
- businessSlug={businessSlug}
221
- onSave={() => {
222
- showCartBottomSheet()
223
- setDrawerValues({ isOpen: !drawerState.isOpen, data: null })
224
- }}
225
246
  navigation={navigation}
247
+ {...(productSelected?._isEditProduct ? {
248
+ isEdit: true,
249
+ productCart: productState?.productCart ?? productSelected,
250
+ product: productState?.product,
251
+ businessSlug: cart?.business?.slug,
252
+ businessId: cart?.business_id,
253
+ categoryId: productSelected?.category_id,
254
+ productId: productSelected?.id,
255
+ } : {
256
+ product: productSelected,
257
+ businessSlug: businessSlug,
258
+ businessId: parseInt(businessId, 10),
259
+ productState: productState,
260
+ productCart: productState,
261
+ })}
262
+ onSave={onSaveProductForm}
263
+ onProductStateChange={onProductStateChange}
226
264
  />
227
265
  </KeyboardView>
228
266
  </DrawerView>
@@ -6,8 +6,7 @@ import {
6
6
  StyleSheet,
7
7
  Animated,
8
8
  ScrollView,
9
- Platform,
10
- ImageBackground
9
+ ImageBackground,
11
10
  } from 'react-native'
12
11
  import {
13
12
  ProductForm as ProductOptions,
@@ -17,7 +16,6 @@ import {
17
16
  useUtils
18
17
  } from 'ordering-components/native'
19
18
  import MaterialCommunityIcon from 'react-native-vector-icons/MaterialCommunityIcons'
20
- import Spinner from 'react-native-loading-spinner-overlay'
21
19
  import { useTheme } from 'styled-components/native'
22
20
 
23
21
  import { ProductIngredient } from '../ProductIngredient'
@@ -32,12 +30,11 @@ import {
32
30
  ProductComment,
33
31
  ProductActions
34
32
  } from './styles'
35
- import { OButton, OImage, OInput, OText } from '../shared'
33
+ import { OButton, OInput, OText } from '../shared'
36
34
  import { ProductOptionSubOption } from '../ProductOptionSubOption'
37
35
  import { NotFoundSource } from '../NotFoundSource'
38
36
  import NavBar from '../NavBar'
39
37
  import { useDeviceOrientation } from '../../../../../src/hooks/DeviceOrientation'
40
- import { useCartBottomSheet } from '../../providers/CartBottomSheetProvider';
41
38
 
42
39
  export const ProductOptionsUI = (props: any) => {
43
40
  const {
@@ -56,7 +53,6 @@ export const ProductOptionsUI = (props: any) => {
56
53
  handleChangeCommentState,
57
54
  productObject,
58
55
  onClose,
59
- isFromCheckout,
60
56
  isDrawer
61
57
  } = props;
62
58
 
@@ -66,7 +62,6 @@ export const ProductOptionsUI = (props: any) => {
66
62
  const [orderState] = useOrder();
67
63
  const [{ auth }] = useSession();
68
64
  const [orientationState] = useDeviceOrientation();
69
- const [, { showCartBottomSheet }] = useCartBottomSheet();
70
65
 
71
66
  const { product, loading, error } = productObject;
72
67
 
@@ -87,6 +82,8 @@ export const ProductOptionsUI = (props: any) => {
87
82
  const handleSaveProduct = () => {
88
83
  const isErrors = Object.values(errors).length > 0
89
84
  if (!isErrors) {
85
+ props.onProductStateChange &&
86
+ props.onProductStateChange(props.isEdit ? { product, productCart }: productCart)
90
87
  handleSave && handleSave()
91
88
  return
92
89
  }
@@ -503,12 +500,14 @@ export const ProductOptionsUI = (props: any) => {
503
500
  </WrapContent>
504
501
  </View>
505
502
  )}
503
+
506
504
  {error && error.length > 0 && (
507
505
  <NotFoundSource
508
506
  content={error[0]?.message || error[0]}
509
507
  />
510
508
  )}
511
509
  </ScrollView>
510
+
512
511
  {!loading && !error && product && (
513
512
  <ProductActions>
514
513
  {productCart && !isSoldOut && maxProductQuantity > 0 && (
@@ -71,6 +71,11 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
71
71
  }, [upsellingProducts.loading, upsellingProducts?.products.length])
72
72
 
73
73
  const handleFormProduct = (product: any) => {
74
+ if (props.onAddProduct) {
75
+ onClose && onClose()
76
+ props.onAddProduct(product)
77
+ return
78
+ }
74
79
  setActualProduct(product)
75
80
  setModalIsOpen(true)
76
81
  }
@@ -81,9 +86,18 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
81
86
  }
82
87
 
83
88
  const UpsellingLayout = () => {
84
-
85
89
  const theme = useTheme()
86
90
 
91
+ const onClickProduct = (product: any) => {
92
+ resetInactivityTimeout()
93
+ if (props.onAddProduct) {
94
+ onClose && onClose()
95
+ props.onAddProduct(product)
96
+ return
97
+ }
98
+ handleFormProduct(product)
99
+ }
100
+
87
101
  return (
88
102
  <Container>
89
103
  {
@@ -167,10 +181,7 @@ const UpsellingProductsUI = (props: UpsellingProductsParams) => {
167
181
  style={{ height: 40, width: '100%' }}
168
182
  bgColor="#EAF2FE"
169
183
  borderColor="#EAF2FE"
170
- onClick={() => {
171
- resetInactivityTimeout()
172
- handleFormProduct(product)
173
- }}
184
+ onClick={() => onClickProduct(product)}
174
185
  />
175
186
  </Item>
176
187
  )) : (
@@ -55,6 +55,7 @@ export interface UpsellingProductsParams {
55
55
  setCanOpenUpselling?: (value: any) => void;
56
56
  onClose?: () => void;
57
57
  resetInactivityTimeout: any;
58
+ onAddProduct: any;
58
59
  }
59
60
 
60
61
  export interface LanguageSelectorParams {
@@ -510,7 +510,7 @@ const AddressFormUI = (props: AddressFormParams) => {
510
510
  onActionLeft={goToBack}
511
511
  showCall={false}
512
512
  btnStyle={{ paddingLeft: 0 }}
513
- style={{ flexDirection: 'column', alignItems: 'flex-start', marginTop: Platform.OS === 'ios' ? 0 : 30 }}
513
+ style={{ marginTop: Platform.OS === 'ios' ? 0 : 30 }}
514
514
  titleWrapStyle={{ paddingHorizontal: 0 }}
515
515
  titleStyle={{ marginRight: 0, marginLeft: 0 }}
516
516
  />
@@ -179,7 +179,7 @@ const AddressListUI = (props: AddressListParams) => {
179
179
  showCall={false}
180
180
  btnStyle={{ paddingLeft: 0 }}
181
181
  paddingTop={0}
182
- style={{ flexDirection: 'column', alignItems: 'flex-start', marginTop: Platform.OS === 'ios' ? 0 : 40 }}
182
+ style={{ marginTop: Platform.OS === 'ios' ? 0 : 40 }}
183
183
  titleWrapStyle={{ paddingHorizontal: 0 }}
184
184
  titleStyle={{ marginLeft: 0, marginRight: 0 }}
185
185
  />
@@ -315,9 +315,9 @@ const BusinessProductsListUI = (props: BusinessProductsListParams) => {
315
315
  ))}
316
316
  <OModal
317
317
  open={!!openDescription}
318
- title={openDescription?.name}
319
318
  onClose={() => setOpenDescription(null)}
320
319
  >
320
+ <OText size={20} style={{paddingLeft: 70, paddingRight: 20, bottom: 25}}>{openDescription?.name}</OText>
321
321
  <ScrollView style={{ padding: 20 }}>
322
322
  {!!openDescription?.image && (
323
323
  <OIcon
@@ -506,7 +506,7 @@ export const OrderDetailsUI = (props: OrderDetailsParams) => {
506
506
  onActionLeft={handleArrowBack}
507
507
  showCall={false}
508
508
  btnStyle={{ paddingLeft: 0 }}
509
- style={{ flexDirection: 'column', alignItems: 'flex-start', marginTop: Platform.OS === 'ios' ? 0 : 20 }}
509
+ style={{ marginTop: Platform.OS === 'ios' ? 0 : 20 }}
510
510
  titleWrapStyle={{ paddingHorizontal: 0 }}
511
511
  titleStyle={{ marginRight: 0, marginLeft: 0 }}
512
512
  subTitle={<OText size={12} lineHeight={18} color={theme.colors.textNormal}>
@@ -49,7 +49,7 @@ export const ProductItemAccordion = (props: ProductItemAccordionParams) => {
49
49
  color: theme.colors.textNormal
50
50
  },
51
51
  inputIOS: {
52
- width: 27,
52
+ width: 34,
53
53
  textAlign: 'center',
54
54
  overflow: 'visible',
55
55
  fontSize: 12,