ordering-ui-react-native 0.17.55 → 0.17.56

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.55",
3
+ "version": "0.17.56",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -75,7 +75,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
75
75
  const theme = useTheme();
76
76
  const [, t] = useLanguage()
77
77
  const [{ auth }] = useSession()
78
- const [orderState, { clearCart }] = useOrder()
78
+ const [orderState, { addProduct, updateProduct }] = useOrder()
79
79
  const [{ parsePrice }] = useUtils()
80
80
  const [, { showToast }] = useToast()
81
81
  const [{ configs }] = useConfig()
@@ -134,6 +134,7 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
134
134
  const [searchBarHeight, setSearchBarHeight] = useState(60)
135
135
 
136
136
  const isCheckoutMultiBusinessEnabled: Boolean = configs?.checkout_multi_business_enabled?.value === '1'
137
+ const isQuickAddProduct = configs?.add_product_with_one_click?.value === '1'
137
138
  const openCarts = (Object.values(orderState?.carts)?.filter((cart: any) => cart?.products && cart?.products?.length && cart?.status !== 2 && cart?.valid_schedule && cart?.valid_products && cart?.valid_address && cart?.valid_maximum && cart?.valid_minimum && !cart?.wallets) || null) || []
138
139
 
139
140
  const currentCart: any = Object.values(orderState.carts).find((cart: any) => cart?.business?.slug === business?.slug) ?? {}
@@ -142,20 +143,39 @@ const BusinessProductsListingUI = (props: BusinessProductsListingParams) => {
142
143
  const onRedirect = (route: string, params?: any) => {
143
144
  navigation.navigate(route, params)
144
145
  }
145
-
146
- const onProductClick = (product: any) => {
147
- const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
148
- if (product?.type === 'service' && business?.professionals?.length > 0) {
149
- setCurrentProduct(product)
150
- setOpenService(true)
151
- return
146
+ const onProductClick = async (product: any) => {
147
+ if (product.extras.length === 0 && !product.inventoried && auth && isQuickAddProduct) {
148
+ const isProductAddedToCart = currentCart?.products?.find((Cproduct: any) => Cproduct.id === product.id)
149
+ const productQuantity = isProductAddedToCart?.quantity
150
+ const addCurrentProduct = {
151
+ ...product,
152
+ quantity: 1
153
+ }
154
+ const updateCurrentProduct = {
155
+ id: product.id,
156
+ code: isProductAddedToCart?.code,
157
+ quantity: productQuantity + 1
158
+ }
159
+ const cartData = currentCart?.business_id ? currentCart : { business_id: business.id }
160
+ if (isProductAddedToCart) {
161
+ await updateProduct(updateCurrentProduct, cartData, isQuickAddProduct)
162
+ } else {
163
+ await addProduct(addCurrentProduct, cartData, isQuickAddProduct)
164
+ }
165
+ } else {
166
+ const productAddedToCartLength = currentCart?.products?.reduce((productsLength: number, Cproduct: any) => { return productsLength + (Cproduct?.id === product?.id ? Cproduct?.quantity : 0) }, 0) || 0
167
+ if (product?.type === 'service' && business?.professionals?.length > 0) {
168
+ setCurrentProduct(product)
169
+ setOpenService(true)
170
+ return
171
+ }
172
+ onRedirect('ProductDetails', {
173
+ product: product,
174
+ businessSlug: business.slug,
175
+ businessId: business.id,
176
+ productAddedToCartLength
177
+ })
152
178
  }
153
- onRedirect('ProductDetails', {
154
- product: product,
155
- businessSlug: business.slug,
156
- businessId: business.id,
157
- productAddedToCartLength
158
- })
159
179
  }
160
180
 
161
181
  const handleCancel = () => {