npm-pkg-hook 1.6.9 → 1.7.0
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
|
@@ -13,32 +13,25 @@ import {
|
|
|
13
13
|
} from './helpers'
|
|
14
14
|
import { useManageQueryParams } from '../../useManageQueryParams'
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* Custom hook for managing cart functionality.
|
|
18
|
-
*
|
|
19
|
-
* @param {Object} options - Options object.
|
|
20
|
-
* @param {Function} options.setAlertBox - Function to set an alert message.
|
|
21
|
-
* @returns {Object} - Object containing cart state and functions.
|
|
22
|
-
*/
|
|
23
|
-
/**
|
|
24
|
-
* The `useCart` function is a custom hook in JavaScript that handles the management of a shopping
|
|
25
|
-
* cart, including adding products, managing quantities, and handling optional extras.
|
|
26
|
-
* @param [] - - `openModalProduct`: A boolean indicating whether the modal for the product is open or
|
|
27
|
-
* not. Default value is `false`.
|
|
28
|
-
* @returns The `useCart` function returns an object with the following properties and methods:
|
|
29
|
-
*/
|
|
30
16
|
export const useCart = ({
|
|
31
|
-
location = {
|
|
17
|
+
location = {
|
|
18
|
+
push: (props, state, { shallow }) => {
|
|
19
|
+
return { ...props, state, shallow }
|
|
20
|
+
},
|
|
21
|
+
query: {
|
|
22
|
+
plato: ''
|
|
23
|
+
}
|
|
24
|
+
},
|
|
32
25
|
openModalProduct = false,
|
|
33
|
-
handleMenu = () => { },
|
|
34
|
-
setOpenModalProduct = () => { },
|
|
35
|
-
setAlertBox = () => { }
|
|
26
|
+
handleMenu = (number) => { return number },
|
|
27
|
+
setOpenModalProduct = (boolean) => { return boolean },
|
|
28
|
+
setAlertBox = (args) => { return args }
|
|
36
29
|
} = {}) => {
|
|
37
30
|
// sub products
|
|
38
31
|
const { handleCleanQuery } = useManageQueryParams({
|
|
39
32
|
location
|
|
40
33
|
})
|
|
41
|
-
|
|
34
|
+
const [loadingButton, setLoadingButton] = useState(false)
|
|
42
35
|
const [dataOptional, setDataOptional] = useState([])
|
|
43
36
|
const [dataExtra, setDataExtra] = useState([])
|
|
44
37
|
const [quantity, setQuantity] = useState(1)
|
|
@@ -62,8 +55,8 @@ export const useCart = ({
|
|
|
62
55
|
] = useGetOneProductsFood({ fetchOnlyProduct: true })
|
|
63
56
|
|
|
64
57
|
const getOneProduct = async food => {
|
|
65
|
-
const { pId
|
|
66
|
-
|
|
58
|
+
const { pId } = food || {}
|
|
59
|
+
|
|
67
60
|
if (!pId) return {}
|
|
68
61
|
setOpenModalProduct(true)
|
|
69
62
|
const product = await handleGetOneProduct({ variables: { pId } })
|
|
@@ -81,7 +74,7 @@ export const useCart = ({
|
|
|
81
74
|
})
|
|
82
75
|
const comments = matchingItemInShoppingCart?.comments
|
|
83
76
|
if (comments) {
|
|
84
|
-
setComments(comments
|
|
77
|
+
setComments(comments)
|
|
85
78
|
}
|
|
86
79
|
const quantityProduct = matchingItemInShoppingCart?.cantProducts
|
|
87
80
|
if (quantityProduct) {
|
|
@@ -170,7 +163,7 @@ export const useCart = ({
|
|
|
170
163
|
}
|
|
171
164
|
})
|
|
172
165
|
|
|
173
|
-
setDataExtra(fetchedDataExtra
|
|
166
|
+
setDataExtra(fetchedDataExtra)
|
|
174
167
|
}
|
|
175
168
|
}
|
|
176
169
|
|
|
@@ -310,13 +303,13 @@ export const useCart = ({
|
|
|
310
303
|
*
|
|
311
304
|
* @param {Object} food - The selected food item.
|
|
312
305
|
*/
|
|
313
|
-
|
|
314
306
|
const handleAddProducts = async (food) => {
|
|
315
307
|
if (!food) return
|
|
316
308
|
const idStore = food?.getStore?.idStore
|
|
317
309
|
if (!idStore) {
|
|
318
310
|
return
|
|
319
311
|
}
|
|
312
|
+
setLoadingButton(true)
|
|
320
313
|
const isExistItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
321
314
|
return item?.productFood && item?.productFood?.pId === food.pId
|
|
322
315
|
}) ?? null
|
|
@@ -360,11 +353,18 @@ export const useCart = ({
|
|
|
360
353
|
})
|
|
361
354
|
|
|
362
355
|
if (response?.data) {
|
|
356
|
+
if (!idShoppingCart) {
|
|
357
|
+
setAlertBox({ message: 'producto agregado al carrito' })
|
|
358
|
+
}
|
|
359
|
+
if (idShoppingCart) {
|
|
360
|
+
setAlertBox({ message: 'producto actualizado' })
|
|
361
|
+
}
|
|
363
362
|
// Perform actions after adding products to cart
|
|
364
363
|
}
|
|
365
364
|
} catch (error) {
|
|
366
365
|
setAlertBox({ message: 'Ocurrió un error al añadir el producto al carrito' })
|
|
367
366
|
}
|
|
367
|
+
setLoadingButton(false)
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
const handleShowModalProduct = () => {
|
|
@@ -394,6 +394,7 @@ export const useCart = ({
|
|
|
394
394
|
comments,
|
|
395
395
|
loading: loadingProduct || loading,
|
|
396
396
|
dataOneProduct,
|
|
397
|
+
loadingButton,
|
|
397
398
|
dataExtra,
|
|
398
399
|
dataOptional,
|
|
399
400
|
setQuantity,
|