ordering-ui-react-native 0.17.6 → 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.6",
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
 
@@ -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,