ordering-ui-react-native 0.17.5 → 0.17.7

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.17.5",
3
+ "version": "0.17.7",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -138,6 +138,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
138
138
  }
139
139
 
140
140
  const onProductClick = (product: any) => {
141
+ const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0)
141
142
  if (product?.type === 'service' && professionalSelected) {
142
143
  setCurrentProduct(product)
143
144
  setOpenService(true)
@@ -147,6 +148,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
147
148
  product: product,
148
149
  businessSlug: business.slug,
149
150
  businessId: business.id,
151
+ productAddedToCartLength
150
152
  })
151
153
  }
152
154
 
@@ -14,6 +14,7 @@ import { Container, WrappButton } from './styles'
14
14
  import { OButton } from '../shared';
15
15
  import { BusinessController } from '../BusinessController';
16
16
  import { SingleProductCard } from '../SingleProductCard';
17
+ import { NotFoundSource } from '../NotFoundSource';
17
18
  import moment from 'moment';
18
19
 
19
20
 
@@ -224,6 +225,12 @@ const FavoriteListUI = (props: FavoriteParams) => {
224
225
  <BusinessSkeleton key={i} />
225
226
  ))
226
227
  )}
228
+ {!favoriteList?.loading && !favoriteList?.favorites?.length && (
229
+ <NotFoundSource
230
+ content={t('NOT_FOUND_FAVORITES_LIST', 'No favorites to show at this time.')
231
+ }
232
+ />
233
+ )}
227
234
  </>
228
235
  )}
229
236
 
@@ -250,6 +257,12 @@ const FavoriteListUI = (props: FavoriteParams) => {
250
257
  <OrderSkeleton key={i} />
251
258
  ))
252
259
  )}
260
+ {!favoriteList?.loading && !favoriteList?.favorites?.length && (
261
+ <NotFoundSource
262
+ content={t('NOT_FOUND_FAVORITES_LIST', 'No favorites to show at this time.')
263
+ }
264
+ />
265
+ )}
253
266
  </>
254
267
  )}
255
268
 
@@ -271,6 +284,12 @@ const FavoriteListUI = (props: FavoriteParams) => {
271
284
  <ProductSkeleton key={i} />
272
285
  ))
273
286
  )}
287
+ {!favoriteList?.loading && !favoriteList?.favorites?.length && (
288
+ <NotFoundSource
289
+ content={t('NOT_FOUND_FAVORITES_LIST', 'No favorites to show at this time.')
290
+ }
291
+ />
292
+ )}
274
293
  </>
275
294
  )}
276
295
 
@@ -11,6 +11,7 @@ export const PreviousProductsOrdered = (props: PreviousProductsOrderedParams) =>
11
11
  const {
12
12
  products,
13
13
  onProductClick,
14
+ handleUpdateProducts,
14
15
  isBusinessesSearchList
15
16
  } = props
16
17
 
@@ -28,12 +29,14 @@ export const PreviousProductsOrdered = (props: PreviousProductsOrderedParams) =>
28
29
  {products?.map((product: any) => (
29
30
  <SingleProductCard
30
31
  key={product?.id}
32
+ isProductId
31
33
  isSoldOut={(product.inventoried && !product.quantity)}
32
34
  product={product}
33
35
  businessId={product?.business?.id}
34
36
  onProductClick={onProductClick}
35
37
  style={style}
36
38
  productAddedToCartLength={0}
39
+ handleUpdateProducts={handleUpdateProducts}
37
40
  />
38
41
  ))}
39
42
  </>
@@ -48,7 +48,8 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
48
48
  hideOrders,
49
49
  BusinessControllerSkeletons,
50
50
  businesses,
51
- businessPaginationProps
51
+ businessPaginationProps,
52
+ handleUpdateProducts
52
53
  } = props
53
54
 
54
55
  const theme = useTheme();
@@ -234,6 +235,7 @@ const OrdersOptionUI = (props: OrdersOptionParams) => {
234
235
  <PreviousProductsOrdered
235
236
  products={products}
236
237
  onProductClick={onProductClick}
238
+ handleUpdateProducts={handleUpdateProducts}
237
239
  isBusinessesSearchList={!!businessesSearchList}
238
240
  />
239
241
  )}
@@ -69,6 +69,7 @@ export const ProductOptionsUI = (props: any) => {
69
69
  handleChangeSuboptionState,
70
70
  handleChangeCommentState,
71
71
  productObject,
72
+ productAddedToCartLength
72
73
  } = props;
73
74
 
74
75
  const theme = useTheme();
@@ -406,14 +407,14 @@ export const ProductOptionsUI = (props: any) => {
406
407
  ? t('UPDATE', 'Update')
407
408
  : t('ADD', 'Add')
408
409
  }`}
409
- isDisabled={isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && (productCart?.quantity < product?.minimum_per_order)) || (product?.maximum_per_order && (productCart?.quantity > product?.maximum_per_order))}
410
+ isDisabled={isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && ((productCart?.quantity + productAddedToCartLength) < product?.minimum_per_order)) || (product?.maximum_per_order && ((productCart?.quantity + productAddedToCartLength) > product?.maximum_per_order))}
410
411
  textStyle={{
411
412
  color: saveErrors || isSoldOut || maxProductQuantity <= 0 ? theme.colors.primary : theme.colors.white,
412
413
  fontSize: orderState.loading || editMode ? 10 : 14
413
414
  }}
414
415
  style={{
415
- backgroundColor: saveErrors || isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && (productCart?.quantity < product?.minimum_per_order)) || (product?.maximum_per_order && (productCart?.quantity > product?.maximum_per_order)) ? theme.colors.lightGray : theme.colors.primary,
416
- borderColor: saveErrors || isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && (productCart?.quantity < product?.minimum_per_order)) || (product?.maximum_per_order && (productCart?.quantity > product?.maximum_per_order)) ? theme.colors.white : theme.colors.primary,
416
+ backgroundColor: saveErrors || isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && ((productCart?.quantity + productAddedToCartLength) < product?.minimum_per_order)) || (product?.maximum_per_order && ((productCart?.quantity + productAddedToCartLength) > product?.maximum_per_order)) ? theme.colors.lightGray : theme.colors.primary,
417
+ borderColor: saveErrors || isSoldOut || maxProductQuantity <= 0 || (product?.minimum_per_order && ((productCart?.quantity + productAddedToCartLength) < product?.minimum_per_order)) || (product?.maximum_per_order && ((productCart?.quantity + productAddedToCartLength) > product?.maximum_per_order)) ? theme.colors.white : theme.colors.primary,
417
418
  opacity: saveErrors || isSoldOut || maxProductQuantity <= 0 ? 0.3 : 1,
418
419
  borderRadius: 7.6,
419
420
  height: 44,
@@ -995,15 +996,15 @@ export const ProductOptionsUI = (props: any) => {
995
996
  <OText size={16} lineHeight={24} weight={'600'}>
996
997
  {productCart.total ? parsePrice(productCart?.total) : ''}
997
998
  </OText>
998
- {product?.minimum_per_order && productCart?.quantity <= product?.minimum_per_order && productCart?.quantity !== 1 && <OText size={12} color={theme.colors?.red}>{t('MOBILE_MINIMUM_TO_ORDER', 'Min. _number_ ').replace('_number_', product?.minimum_per_order)}</OText>}
999
- {product?.maximum_per_order && productCart?.quantity >= product?.maximum_per_order && <OText size={12} color={theme.colors?.red}>{t('MOBILE_MAXIMUM_TO_ORDER', 'Max. _number_'.replace('_number_', product?.maximum_per_order))}</OText>}
999
+ {product?.minimum_per_order && (productCart?.quantity + productAddedToCartLength) <= product?.minimum_per_order && productCart?.quantity !== 1 && <OText size={12} color={theme.colors?.red}>{t('MOBILE_MINIMUM_TO_ORDER', 'Min. _number_ ').replace('_number_', product?.minimum_per_order)}</OText>}
1000
+ {product?.maximum_per_order && (productCart?.quantity + productAddedToCartLength) >= product?.maximum_per_order && <OText size={12} color={theme.colors?.red}>{t('MOBILE_MAXIMUM_TO_ORDER', 'Max. _number_'.replace('_number_', product?.maximum_per_order))}</OText>}
1000
1001
  </View>
1001
1002
  {productCart && !isSoldOut && maxProductQuantity > 0 && (
1002
1003
  <>
1003
1004
  <View style={styles.quantityControl}>
1004
1005
  <TouchableOpacity
1005
1006
  onPress={decrement}
1006
- disabled={productCart.quantity === 1 || !productCart.quantity || isSoldOut || (productCart?.quantity <= product?.minimum_per_order)}>
1007
+ disabled={productCart.quantity === 1 || !productCart.quantity || isSoldOut || ((productCart?.quantity + productAddedToCartLength) <= product?.minimum_per_order)}>
1007
1008
  <OIcon
1008
1009
  src={theme.images.general.minus}
1009
1010
  width={16}
@@ -1044,8 +1045,8 @@ export const ProductOptionsUI = (props: any) => {
1044
1045
  onPress={increment}
1045
1046
  disabled={
1046
1047
  maxProductQuantity <= 0 ||
1047
- productCart.quantity >= maxProductQuantity ||
1048
- (productCart.quantity >= product?.maximum_per_order && product?.maximum_per_order) ||
1048
+ (productCart?.quantity + productAddedToCartLength) >= maxProductQuantity ||
1049
+ ((productCart?.quantity + productAddedToCartLength) >= product?.maximum_per_order && product?.maximum_per_order) ||
1049
1050
  isSoldOut
1050
1051
  }>
1051
1052
  <OIcon
@@ -1053,8 +1054,8 @@ export const ProductOptionsUI = (props: any) => {
1053
1054
  width={16}
1054
1055
  color={
1055
1056
  maxProductQuantity <= 0 ||
1056
- productCart.quantity >= maxProductQuantity ||
1057
- (productCart.quantity >= product?.maximum_per_order && product?.maximum_per_order) ||
1057
+ (productCart?.quantity + productAddedToCartLength) >= maxProductQuantity ||
1058
+ ((productCart?.quantity + productAddedToCartLength) >= product?.maximum_per_order && product?.maximum_per_order) ||
1058
1059
  isSoldOut
1059
1060
  ? theme.colors.backgroundGray
1060
1061
  : theme.colors.backgroundDark
@@ -5,6 +5,8 @@ import {
5
5
  useOrder,
6
6
  useUtils,
7
7
  useSession,
8
+ ToastType,
9
+ useToast,
8
10
  SingleProductCard as SingleProductCardController
9
11
  } from 'ordering-components/native';
10
12
  import { useTheme } from 'styled-components/native';
@@ -96,6 +98,7 @@ const SingleProductCardUI = React.memo((props: SingleProductCardParams) => {
96
98
  const [{ auth }] = useSession()
97
99
  const [{ parsePrice, optimizeImage, parseDate }] = useUtils();
98
100
  const [orderState] = useOrder()
101
+ const [, { showToast }] = useToast()
99
102
  const [isIntersectionObserver, setIsIntersectionObserver] = useState(!enableIntersection)
100
103
 
101
104
  const editMode = typeof product?.code !== 'undefined';
@@ -136,6 +139,14 @@ const SingleProductCardUI = React.memo((props: SingleProductCardParams) => {
136
139
  }
137
140
  }
138
141
 
142
+ const handleClickproduct = () => {
143
+ if (productAddedToCartLength && product?.maximum_per_order && productAddedToCartLength >= product?.maximum_per_order) {
144
+ showToast(ToastType.Error, t('PRODUCT_ON_MAXIMUM_ORDER', 'The product is on maximum order'))
145
+ return
146
+ }
147
+ onProductClick?.(product)
148
+ }
149
+
139
150
  return (
140
151
  <InView style={{ minHeight: hideAddButton ? 125 : 190 }} triggerOnce={true} onChange={(inView: boolean) => handleChangeIntersection()}>
141
152
  {isIntersectionObserver ? (
@@ -146,7 +157,7 @@ const SingleProductCardUI = React.memo((props: SingleProductCardParams) => {
146
157
  (isSoldOut || maxProductQuantity <= 0) && styles.soldOutBackgroundStyle,
147
158
  (style && { ...style }),
148
159
  ]}
149
- onPress={() => onProductClick?.(product)}
160
+ onPress={() => handleClickproduct()}
150
161
  >
151
162
  <View style={{ flexDirection: 'row' }}>
152
163
  {productAddedToCartLength > 0 && (
@@ -251,7 +262,7 @@ const SingleProductCardUI = React.memo((props: SingleProductCardParams) => {
251
262
  </View>
252
263
  {!hideAddButton && (
253
264
  <OButton
254
- onClick={() => onProductClick?.(product)}
265
+ onClick={() => handleClickproduct()}
255
266
  style={{
256
267
  width: '100%',
257
268
  borderRadius: 7.6,
@@ -306,6 +306,7 @@ export interface SingleProductCardParams {
306
306
  enableIntersection?: boolean;
307
307
  navigation?: any;
308
308
  isPreviously?: any;
309
+ isProductId?: any;
309
310
  }
310
311
  export interface BusinessInformationParams {
311
312
  navigation?: any,
@@ -360,6 +361,7 @@ export interface OrdersOptionParams {
360
361
  refreshOrders?: boolean,
361
362
  setRefreshOrders?: (value: boolean) => void,
362
363
  handleUpdateOrderList?: (orderId: number, changes: any) => {},
364
+ handleUpdateProducts?: (productId: number, changes: any) => {},
363
365
  isBusiness?: boolean,
364
366
  isProducts?: boolean,
365
367
  businessOrderIds?: any,
@@ -764,6 +766,8 @@ export interface OrderItAgainParams {
764
766
 
765
767
  export interface PreviousProductsOrderedParams {
766
768
  products?: any,
769
+ isProductId?: boolean
767
770
  onProductClick?: any,
768
771
  isBusinessesSearchList?: boolean
772
+ handleUpdateProducts?: any
769
773
  }