npm-pkg-hook 1.6.9 → 1.7.1
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 +1 -1
- package/src/hooks/statusOpenStores/index.js +1 -1
- package/src/hooks/useAsideCart/index.js +28 -15
- package/src/hooks/useCart/useCart/index.js +25 -24
- package/src/hooks/useEvent/index.js +1 -0
- package/src/hooks/useMobile/index.js +31 -23
- package/src/hooks/useSales/index.js +1 -2
- package/src/hooks/useStatusOpenStore/index.js +1 -1
package/package.json
CHANGED
|
@@ -92,7 +92,7 @@ export const statusOpenStores = ({
|
|
|
92
92
|
if (findNextDay && findDataNextDay?.schHoSta) {
|
|
93
93
|
const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow]
|
|
94
94
|
return handleState(
|
|
95
|
-
`Cerrado - Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
|
|
95
|
+
`Cerrado abre - Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
|
|
96
96
|
findDataNextDay?.schHoSta ? findDataNextDay?.schHoSta : ''
|
|
97
97
|
}`,
|
|
98
98
|
false
|
|
@@ -11,23 +11,36 @@ import { calculateTotalPrice } from './helpers'
|
|
|
11
11
|
import { statusOpenStores } from '../statusOpenStores'
|
|
12
12
|
export * from './helpers'
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Custom hook for managing the shopping cart functionality.
|
|
16
|
-
* @param {Object} props - Props to control various UI elements.
|
|
17
|
-
* @param {function} props.setCountItemProduct - Function to set the count of items in the cart.
|
|
18
|
-
* @param {function} props.setAlertBox - Function to set an alert message.
|
|
19
|
-
* @param {function} props.handleMenu - Function to handle cart menu visibility.
|
|
20
|
-
* @returns {Object} An object with various shopping cart-related functions and data.
|
|
21
|
-
*/
|
|
22
14
|
export const useAsideCart = ({
|
|
23
15
|
openModalProduct = false,
|
|
24
|
-
location = {
|
|
16
|
+
location = {
|
|
17
|
+
pathname: '',
|
|
18
|
+
push: (props, state, { shallow }) => {
|
|
19
|
+
return { ...props, state, shallow }
|
|
20
|
+
},
|
|
21
|
+
query: {
|
|
22
|
+
plato: ''
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
25
|
setCountItemProduct = (number) => { return number },
|
|
26
|
-
setAlertBox = () => { },
|
|
26
|
+
setAlertBox = (args) => { return args },
|
|
27
27
|
setOpenModalProduct = () => { },
|
|
28
|
-
handleMenu = () => { }
|
|
28
|
+
handleMenu = (boolean) => { return boolean }
|
|
29
29
|
} = {
|
|
30
|
-
|
|
30
|
+
openModalProduct: false,
|
|
31
|
+
location: {
|
|
32
|
+
pathname: '',
|
|
33
|
+
push: (props, state, { shallow }) => {
|
|
34
|
+
return { ...props, state, shallow }
|
|
35
|
+
},
|
|
36
|
+
query: {
|
|
37
|
+
plato: ''
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
setCountItemProduct: (number) => { return number },
|
|
41
|
+
setAlertBox: () => { },
|
|
42
|
+
setOpenModalProduct: () => { },
|
|
43
|
+
handleMenu: () => { }
|
|
31
44
|
}) => {
|
|
32
45
|
const { getOneProduct } = useCart({
|
|
33
46
|
handleMenu,
|
|
@@ -137,9 +150,9 @@ export const useAsideCart = ({
|
|
|
137
150
|
*/
|
|
138
151
|
const sumProduct = (ProPrice, ProDelivery, cant) => {
|
|
139
152
|
// Convertir a números, con manejo de posibles errores
|
|
140
|
-
const price =
|
|
141
|
-
const delivery =
|
|
142
|
-
const quantity =
|
|
153
|
+
const price = ProPrice
|
|
154
|
+
const delivery = ProDelivery || 0
|
|
155
|
+
const quantity = cant
|
|
143
156
|
|
|
144
157
|
// Verificar si las conversiones fueron exitosas
|
|
145
158
|
if (isNaN(price) || isNaN(delivery) || isNaN(quantity)) {
|
|
@@ -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,
|
|
@@ -1,38 +1,46 @@
|
|
|
1
|
-
/* eslint-disable no-void */
|
|
2
1
|
import { useEffect, useState } from 'react'
|
|
3
2
|
|
|
4
3
|
export const useMobile = (props) => {
|
|
5
|
-
const { callBack = () => {
|
|
6
|
-
const [
|
|
7
|
-
const [
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
setInnerWidth(window.innerWidth)
|
|
12
|
-
callBack()
|
|
13
|
-
}, [])
|
|
4
|
+
const { callBack = () => {} } = props || {}
|
|
5
|
+
const [isMobile, setIsMobile] = useState(false)
|
|
6
|
+
const [isTablet, setIsTablet] = useState(false)
|
|
7
|
+
const [innerHeight, setInnerHeight] = useState(0)
|
|
8
|
+
const [innerWidth, setInnerWidth] = useState(0)
|
|
9
|
+
|
|
14
10
|
useEffect(() => {
|
|
15
11
|
const handleResize = () => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
setInnerWidth(
|
|
12
|
+
// Verificar si window está disponible (es decir, estamos en el lado del cliente)
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
const width = window.innerWidth
|
|
15
|
+
const height = window.innerHeight
|
|
16
|
+
setInnerWidth(width)
|
|
17
|
+
setInnerHeight(height)
|
|
18
|
+
callBack()
|
|
19
|
+
|
|
20
|
+
// Determinar el tipo de dispositivo
|
|
21
|
+
if (width <= 768) {
|
|
22
|
+
setIsTablet(true)
|
|
23
|
+
} else if (width <= 960) {
|
|
24
|
+
setIsMobile(true)
|
|
25
|
+
} else {
|
|
26
|
+
setIsMobile(false)
|
|
27
|
+
}
|
|
21
28
|
}
|
|
22
|
-
callBack()
|
|
23
|
-
}
|
|
24
|
-
if (typeof window !== 'undefined') {
|
|
25
|
-
window.addEventListener('resize', handleResize)
|
|
26
29
|
}
|
|
30
|
+
|
|
31
|
+
// Ejecutar handleResize al cargar y al cambiar el tamaño de la pantalla
|
|
32
|
+
handleResize()
|
|
33
|
+
window.addEventListener('resize', handleResize)
|
|
34
|
+
|
|
35
|
+
// Eliminar el event listener al desmontar el componente
|
|
27
36
|
return () => {
|
|
28
37
|
window.removeEventListener('resize', handleResize)
|
|
29
38
|
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
isMobile = true
|
|
33
|
-
}
|
|
39
|
+
}, [callBack])
|
|
40
|
+
|
|
34
41
|
return {
|
|
35
42
|
isMobile,
|
|
43
|
+
isTablet,
|
|
36
44
|
innerHeight,
|
|
37
45
|
innerWidth
|
|
38
46
|
}
|
|
@@ -56,7 +56,7 @@ const initializer = (initialValue = initialState) => {
|
|
|
56
56
|
export const useSales = ({
|
|
57
57
|
disabled = false,
|
|
58
58
|
router,
|
|
59
|
-
sendNotification = () => { return },
|
|
59
|
+
sendNotification = (arsg) => { return arsg },
|
|
60
60
|
setAlertBox = () => { return }
|
|
61
61
|
}) => {
|
|
62
62
|
const domain = getCurrentDomain()
|
|
@@ -104,7 +104,6 @@ export const useSales = ({
|
|
|
104
104
|
const [loadingExtraProduct, setLoadingExtraProduct] = useState(false)
|
|
105
105
|
const [dataOptional, setDataOptional] = useState([])
|
|
106
106
|
const [dataExtra, setDataExtra] = useState([])
|
|
107
|
-
|
|
108
107
|
const [registerSalesStore, { loading: loadingRegisterSale }] = useMutation(
|
|
109
108
|
CREATE_SHOPPING_CARD_TO_USER_STORE,
|
|
110
109
|
{
|
|
@@ -94,7 +94,7 @@ export const useStatusOpenStore = ({ dataSchedules = [] } = {}) => {
|
|
|
94
94
|
if (findNextDay && findDataNextDay?.schHoSta) {
|
|
95
95
|
const nameOfDayTomorrow = weekDays[dayOfWeekTomorrow]
|
|
96
96
|
return handleMessageHour(
|
|
97
|
-
`Cerrado
|
|
97
|
+
`Cerrado abre Mañana ${nameOfDayTomorrow} ${!!findDataNextDay?.schHoSta && 'a las'} ${
|
|
98
98
|
findDataNextDay?.schHoSta ? findDataNextDay?.schHoSta : ''
|
|
99
99
|
}`,
|
|
100
100
|
false
|