npm-pkg-hook 1.5.8 → 1.6.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 +1 -1
- package/src/hooks/addTenMinutes/index.js +12 -0
- package/src/hooks/calculateLogLatHaversine/index.js +30 -0
- package/src/hooks/getCategoriesWithProduct/index.js +1 -1
- package/src/hooks/index.js +3 -0
- package/src/hooks/useAsideCart/queries.js +1 -1
- package/src/hooks/useCart/index.js +1 -1
- package/src/hooks/useCart/useCart/helpers/index.js +2 -2
- package/src/hooks/useCatWithProductClient/queries.js +1 -1
- package/src/hooks/useCategoryInStore/queries.js +1 -1
- package/src/hooks/useCreateDeliveryTime/index.js +26 -0
- package/src/hooks/useDeliveryTime/index.js +21 -0
- package/src/hooks/useFetchJson/index.js +1 -1
- package/src/hooks/useGetOneStoreRating/queries.js +1 -1
- package/src/hooks/useGoogleLogin/loadScript.js +15 -15
- package/src/hooks/useGoogleLogin/removeScript.js +7 -7
- package/src/hooks/useKeypress/index.js +1 -1
- package/src/hooks/useManageNewOrder/helpers/index.js +23 -0
- package/src/hooks/useManageNewOrder/index.js +24 -63
- package/src/hooks/useOrderClient/index.js +1 -1
- package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +6 -1
- package/src/hooks/useRestaurant/queries.js +1 -0
- package/src/hooks/useStore/queries.js +1 -0
- package/.vscode/extensions.json +0 -6
- package/.vscode/settings.json +0 -8
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Function that adds 10 to a given number representing minutes.
|
|
3
|
+
* @param {number} num - The number of minutes (between 1 and 60).
|
|
4
|
+
* @returns {string} A string indicating the original number and the result of adding 10 minutes.
|
|
5
|
+
*/
|
|
6
|
+
export const addTenMinutes = (num) => {
|
|
7
|
+
if (num >= 50) {
|
|
8
|
+
return `${10 - num} - ${60} min`
|
|
9
|
+
} else {
|
|
10
|
+
return `${num} - ${num + 10} min`
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function deg2rad (deg) {
|
|
2
|
+
return deg * (Math.PI / 180)
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
// Función para calcular la distancia entre un punto fijo y un punto dado utilizando la fórmula de Haversine
|
|
6
|
+
export function calculateLogLatHaversine (lat1, lon1, lat2, lon2) {
|
|
7
|
+
const radioTierra = 6371 // Radio de la Tierra en kilómetros
|
|
8
|
+
const dLat = deg2rad(lat2 - lat1)
|
|
9
|
+
const dLon = deg2rad(lon2 - lon1)
|
|
10
|
+
const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
11
|
+
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
|
|
12
|
+
Math.sin(dLon / 2) * Math.sin(dLon / 2)
|
|
13
|
+
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
14
|
+
const distancia = radioTierra * c
|
|
15
|
+
return distancia
|
|
16
|
+
}
|
|
17
|
+
// 768px
|
|
18
|
+
// Coordenadas del punto fijo
|
|
19
|
+
const puntoFijo = { lat: 4.7984084, lon: -75.7338831 }
|
|
20
|
+
|
|
21
|
+
// Array de coordenadas de ejemplo
|
|
22
|
+
const coordenadas = [
|
|
23
|
+
{ lat: 4.7954221, lon: -75.730596 }
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
// Calcular distancias entre cada punto y el punto fijo
|
|
27
|
+
coordenadas.forEach((coordenada, index) => {
|
|
28
|
+
const distancia = calculateLogLatHaversine(puntoFijo.lat, puntoFijo.lon, coordenada.lat, coordenada.lon)
|
|
29
|
+
console.log(`La distancia entre el punto fijo y coordenada ${index + 1} es ${distancia.toFixed(2)} kilómetros`)
|
|
30
|
+
})
|
package/src/hooks/index.js
CHANGED
|
@@ -5,8 +5,11 @@ export * from './useCategoryInStore'
|
|
|
5
5
|
export * from './useCategoryStore'
|
|
6
6
|
export * from './useCatWithProduct'
|
|
7
7
|
export * from './useManageQueryParams'
|
|
8
|
+
export * from './useDeliveryTime'
|
|
8
9
|
export * from './statusOpenStores'
|
|
9
10
|
export * from './newMessageSubscription'
|
|
11
|
+
export * from './useCreateDeliveryTime'
|
|
12
|
+
export * from './addTenMinutes'
|
|
10
13
|
export * from './useCategoriesProduct'
|
|
11
14
|
export * from './useLogout'
|
|
12
15
|
export * from './useStatusOpenStore'
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './useCart'
|
|
2
|
-
export * from './useGetCart'
|
|
2
|
+
export * from './useGetCart'
|
|
@@ -2,7 +2,7 @@ import { filterKeyObject } from '../../../../utils'
|
|
|
2
2
|
|
|
3
3
|
const filters = ['__typename']
|
|
4
4
|
|
|
5
|
-
export const filterDataOptional = (dataOptional) => {
|
|
5
|
+
export const filterDataOptional = (dataOptional) => {
|
|
6
6
|
if (!Array.isArray(dataOptional)) {
|
|
7
7
|
throw new Error('Input data is not an array')
|
|
8
8
|
}
|
|
@@ -72,4 +72,4 @@ export const filterExtra = (dataExtra) => {
|
|
|
72
72
|
} catch (error) {
|
|
73
73
|
return []
|
|
74
74
|
}
|
|
75
|
-
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useMutation, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const CREATE_DELIVERY_TIME = gql`
|
|
4
|
+
mutation CreateDeliveryTime($minutes: Int!) {
|
|
5
|
+
createDeliveryTime(minutes: $minutes) {
|
|
6
|
+
success
|
|
7
|
+
message
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
export const useCreateDeliveryTime = () => {
|
|
13
|
+
const [createDeliveryTimeMutation, { loading, error }] = useMutation(CREATE_DELIVERY_TIME)
|
|
14
|
+
|
|
15
|
+
const createDeliveryTime = async (minutes) => {
|
|
16
|
+
try {
|
|
17
|
+
const { data } = await createDeliveryTimeMutation({ variables: { minutes } })
|
|
18
|
+
return data.createDeliveryTime
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.error('Error creating delivery time:', error)
|
|
21
|
+
return { success: false, message: 'An error occurred while creating delivery time' }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { createDeliveryTime, loading, error }
|
|
26
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom hook to handle delivery time input validation and formatting.
|
|
5
|
+
* @returns {Object} An object containing state and functions for handling delivery time.
|
|
6
|
+
*/
|
|
7
|
+
export const useDeliveryTime = () => {
|
|
8
|
+
const [deliveryTime, setDeliveryTime] = useState('')
|
|
9
|
+
/**
|
|
10
|
+
* Handles changes to the delivery time input.
|
|
11
|
+
* @param {String} value - The input change value.
|
|
12
|
+
*/
|
|
13
|
+
const handleDeliveryTimeChange = (value) => {
|
|
14
|
+
setDeliveryTime(value)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
deliveryTime,
|
|
19
|
+
handleDeliveryTimeChange
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export default (d, s, id, jsSrc, cb, onError) => {
|
|
2
|
-
const element = d.getElementsByTagName(s)[0]
|
|
3
|
-
const fjs = element
|
|
4
|
-
let js = element
|
|
5
|
-
js = d.createElement(s)
|
|
6
|
-
js.id = id
|
|
7
|
-
js.src = jsSrc
|
|
8
|
-
if (fjs && fjs.parentNode) {
|
|
9
|
-
fjs.parentNode.insertBefore(js, fjs)
|
|
10
|
-
} else {
|
|
11
|
-
d.head.appendChild(js)
|
|
12
|
-
}
|
|
13
|
-
js.onerror = onError
|
|
14
|
-
js.onload = cb
|
|
15
|
-
}
|
|
1
|
+
export default (d, s, id, jsSrc, cb, onError) => {
|
|
2
|
+
const element = d.getElementsByTagName(s)[0]
|
|
3
|
+
const fjs = element
|
|
4
|
+
let js = element
|
|
5
|
+
js = d.createElement(s)
|
|
6
|
+
js.id = id
|
|
7
|
+
js.src = jsSrc
|
|
8
|
+
if (fjs && fjs.parentNode) {
|
|
9
|
+
fjs.parentNode.insertBefore(js, fjs)
|
|
10
|
+
} else {
|
|
11
|
+
d.head.appendChild(js)
|
|
12
|
+
}
|
|
13
|
+
js.onerror = onError
|
|
14
|
+
js.onload = cb
|
|
15
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default (d, id) => {
|
|
2
|
-
const element = d.getElementById(id)
|
|
3
|
-
|
|
4
|
-
if (element) {
|
|
5
|
-
element.parentNode.removeChild(element)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
1
|
+
export default (d, id) => {
|
|
2
|
+
const element = d.getElementById(id)
|
|
3
|
+
|
|
4
|
+
if (element) {
|
|
5
|
+
element.parentNode.removeChild(element)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const findOrderByCodeRef = (data, pCodeRef) => {
|
|
2
|
+
// Iterar sobre cada columna en el objeto data
|
|
3
|
+
for (const column of Object.values(data)) {
|
|
4
|
+
// Buscar el objeto por pCodeRef dentro de la columna actual
|
|
5
|
+
const foundOrder = column.find(order => order.pCodeRef === pCodeRef)
|
|
6
|
+
// Si se encuentra el objeto, devolverlo
|
|
7
|
+
if (foundOrder) {
|
|
8
|
+
return foundOrder
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
// Si no se encuentra el objeto en ninguna columna, devolver null
|
|
12
|
+
return null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const isDateInRange = (dateString) => {
|
|
16
|
+
const currentDate = new Date()
|
|
17
|
+
const todayStart = new Date(currentDate.setHours(0, 0, 0, 0))
|
|
18
|
+
const tomorrowStart = new Date(todayStart)
|
|
19
|
+
tomorrowStart.setDate(tomorrowStart.getDate() + 1)
|
|
20
|
+
|
|
21
|
+
const date = new Date(dateString)
|
|
22
|
+
return date >= todayStart && date < tomorrowStart
|
|
23
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { useState } from 'react'
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
useGetSale,
|
|
4
4
|
updateExistingOrders,
|
|
5
5
|
convertDateFormat,
|
|
6
6
|
useOrdersFromStore
|
|
7
7
|
} from '../../hooks'
|
|
8
|
+
import { findOrderByCodeRef, isDateInRange } from './helpers'
|
|
8
9
|
|
|
9
10
|
export const useManageNewOrder = ({
|
|
10
11
|
client,
|
|
@@ -13,6 +14,7 @@ export const useManageNewOrder = ({
|
|
|
13
14
|
return { message, duration }
|
|
14
15
|
},
|
|
15
16
|
playNotificationSound = () => {},
|
|
17
|
+
setCountOrders = (number) => { return number },
|
|
16
18
|
sendNotification = ({ title, description, backgroundColor }) => {
|
|
17
19
|
return {
|
|
18
20
|
title,
|
|
@@ -26,10 +28,24 @@ export const useManageNewOrder = ({
|
|
|
26
28
|
|
|
27
29
|
const [data] = useOrdersFromStore({
|
|
28
30
|
idStore,
|
|
31
|
+
search: '',
|
|
29
32
|
fromDate: convertDateFormat({ start: true }),
|
|
30
33
|
toDate: convertDateFormat({ start: false })
|
|
31
34
|
})
|
|
32
35
|
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
if (data) {
|
|
38
|
+
const dataOrder = data[KEY_STATUS_ORDER]
|
|
39
|
+
if (Array.isArray(dataOrder) && dataOrder) {
|
|
40
|
+
const filteredOrders = dataOrder.filter(order =>
|
|
41
|
+
isDateInRange(order?.pDatCre) && order?.pSState === 1
|
|
42
|
+
) ?? []
|
|
43
|
+
setOrders(filteredOrders)
|
|
44
|
+
setCountOrders(filteredOrders.length)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, [data])
|
|
48
|
+
|
|
33
49
|
const [isOpenOrder, setIsOpenOrder] = useState(false)
|
|
34
50
|
const { getOnePedidoStore } = useGetSale()
|
|
35
51
|
|
|
@@ -38,7 +54,7 @@ export const useManageNewOrder = ({
|
|
|
38
54
|
setOrders(dataOrder)
|
|
39
55
|
const { pCodeRef } = order || {}
|
|
40
56
|
if (pCodeRef) {
|
|
41
|
-
const isCodeRefExists =
|
|
57
|
+
const isCodeRefExists = findOrderByCodeRef(data, pCodeRef)
|
|
42
58
|
if (isCodeRefExists) {
|
|
43
59
|
return
|
|
44
60
|
}
|
|
@@ -50,60 +66,7 @@ export const useManageNewOrder = ({
|
|
|
50
66
|
}
|
|
51
67
|
}).then((response) => {
|
|
52
68
|
console.log(response)
|
|
53
|
-
const currentSale = {
|
|
54
|
-
__typename: 'StorePedidos',
|
|
55
|
-
pdpId: null,
|
|
56
|
-
idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
|
|
57
|
-
pCodeRef,
|
|
58
|
-
payMethodPState: 0,
|
|
59
|
-
pPRecoger: null,
|
|
60
|
-
totalProductsPrice: 36000,
|
|
61
|
-
pSState: 1,
|
|
62
|
-
pDatCre: '2023-05-23T18:00:36.000Z',
|
|
63
|
-
channel: 1,
|
|
64
|
-
locationUser: null,
|
|
65
|
-
pDatMod: '2023-05-23T18:10:12.000Z',
|
|
66
|
-
getAllPedidoStore: [
|
|
67
|
-
{
|
|
68
|
-
__typename: 'StorePedidos',
|
|
69
|
-
pdpId: 'MTg3NzQxMjgyMjQ3NTQ2MzUwMDA=',
|
|
70
|
-
pId: null,
|
|
71
|
-
idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
|
|
72
|
-
ShoppingCard: 'Mjc0ODA5NzAzMDAwMDMxNjQwMDA=',
|
|
73
|
-
pCodeRef: 'Gi8OfUk9X6',
|
|
74
|
-
pPStateP: 1,
|
|
75
|
-
payMethodPState: 0,
|
|
76
|
-
pPRecoger: null,
|
|
77
|
-
pDatCre: '2023-05-23T18:00:36.000Z',
|
|
78
|
-
pDatMod: '2023-05-23T18:00:36.000Z',
|
|
79
|
-
getAllShoppingCard: {
|
|
80
|
-
__typename: 'ShoppingCard',
|
|
81
|
-
ShoppingCard: 'Mjc0ODA5NzAzMDAwMDMxNjQwMDA=',
|
|
82
|
-
comments: '',
|
|
83
|
-
cantProducts: 3,
|
|
84
|
-
pId: 'NDM1MzQyMTAzNzYyNDI2MzAwMA==',
|
|
85
|
-
productFood: {
|
|
86
|
-
__typename: 'ProductFood',
|
|
87
|
-
pId: 'MjUwMzIxNzA5NjYzMzk1MTQwMDA=',
|
|
88
|
-
carProId: 'MTM2MDQ0NDA3NDI1NzU4MjMwMA==',
|
|
89
|
-
colorId: null,
|
|
90
|
-
idStore: 'MjcyMDg4ODE0ODUxNTE2NDUw',
|
|
91
|
-
pName: 'Hamburguesa mas papas y gaseosa',
|
|
92
|
-
ProPrice: 12000,
|
|
93
|
-
ProDescuento: '12',
|
|
94
|
-
ProDescription: '12312312312',
|
|
95
|
-
ValueDelivery: null,
|
|
96
|
-
ProImage:
|
|
97
|
-
'//front-back-server.fly.dev/static/platos/undefined',
|
|
98
|
-
ProStar: 0,
|
|
99
|
-
pState: 1,
|
|
100
|
-
pDatCre: '2023-05-19T22:42:50.000Z',
|
|
101
|
-
pDatMod: '2023-05-19T22:42:50.000Z'
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
]
|
|
106
|
-
}
|
|
69
|
+
const currentSale = response?.data?.getOnePedidoStore || {}
|
|
107
70
|
client.cache.modify({
|
|
108
71
|
fields: {
|
|
109
72
|
getAllOrdersFromStore (existingOrders = []) {
|
|
@@ -115,13 +78,11 @@ export const useManageNewOrder = ({
|
|
|
115
78
|
currentSale
|
|
116
79
|
)
|
|
117
80
|
const currentOrder = cache[KEY_STATUS_ORDER]
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
setOrders(currentOrder)
|
|
124
|
-
}
|
|
81
|
+
const filteredOrders = currentOrder.filter(order =>
|
|
82
|
+
isDateInRange(order.pDatCre)
|
|
83
|
+
)
|
|
84
|
+
setOrders(filteredOrders)
|
|
85
|
+
playNotificationSound()
|
|
125
86
|
return cache
|
|
126
87
|
} catch (e) {
|
|
127
88
|
return existingOrders
|
|
@@ -1,20 +1,25 @@
|
|
|
1
|
+
import { addTenMinutes } from '../../addTenMinutes'
|
|
1
2
|
import { statusOpenStores } from '../../statusOpenStores'
|
|
2
3
|
|
|
3
4
|
export const getStatusForStores = (stores = []) => {
|
|
4
5
|
return stores.map((store) => {
|
|
6
|
+
const min = addTenMinutes(store?.deliveryTimeMinutes)
|
|
5
7
|
if (store?.scheduleOpenAll) {
|
|
6
8
|
return {
|
|
7
9
|
...store,
|
|
8
10
|
status: { message: '', open: true },
|
|
9
|
-
open: 1
|
|
11
|
+
open: 1,
|
|
12
|
+
min: min ?? ''
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
const dataSchedules =
|
|
13
16
|
(store?.getStoreSchedules?.length > 0 && store.getStoreSchedules) || []
|
|
14
17
|
const status = statusOpenStores({ dataSchedules })
|
|
18
|
+
|
|
15
19
|
return {
|
|
16
20
|
...store,
|
|
17
21
|
status,
|
|
22
|
+
min: min ?? '',
|
|
18
23
|
open: status?.open ? 1 : 0
|
|
19
24
|
}
|
|
20
25
|
}).sort((a, b) => b.open - a.open)
|
package/.vscode/extensions.json
DELETED