npm-pkg-hook 1.5.7 → 1.5.9

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.
Files changed (32) hide show
  1. package/package.json +1 -1
  2. package/src/hooks/addTenMinutes/index.js +12 -0
  3. package/src/hooks/calculateLogLatHaversine/index.js +30 -0
  4. package/src/hooks/getCategoriesWithProduct/index.js +1 -1
  5. package/src/hooks/getTodayTimestamps/index.js +1 -1
  6. package/src/hooks/index.js +5 -0
  7. package/src/hooks/useAsideCart/queries.js +1 -1
  8. package/src/hooks/useCart/index.js +1 -1
  9. package/src/hooks/useCart/useCart/helpers/index.js +2 -2
  10. package/src/hooks/useCatWithProductClient/queries.js +1 -1
  11. package/src/hooks/useCategoryInStore/index.js +3 -1
  12. package/src/hooks/useCategoryInStore/queries.js +1 -1
  13. package/src/hooks/useChartData/index.js +0 -4
  14. package/src/hooks/useCreateDeliveryTime/index.js +26 -0
  15. package/src/hooks/useDeliveryTime/index.js +21 -0
  16. package/src/hooks/useFetchJson/index.js +1 -1
  17. package/src/hooks/useGetOneStoreRating/queries.js +1 -1
  18. package/src/hooks/useGoogleLogin/loadScript.js +15 -15
  19. package/src/hooks/useGoogleLogin/removeScript.js +7 -7
  20. package/src/hooks/useIncomingOrders/index.js +10 -0
  21. package/src/hooks/useIncomingOrders/queries.js +87 -0
  22. package/src/hooks/useKeypress/index.js +1 -1
  23. package/src/hooks/useManageNewOrder/helpers/index.js +23 -0
  24. package/src/hooks/useManageNewOrder/helpers/mock.js +0 -0
  25. package/src/hooks/useManageNewOrder/index.js +104 -0
  26. package/src/hooks/useOrderClient/index.js +1 -1
  27. package/src/hooks/useRestaurant/helpers/manageStatusOpen.js +6 -1
  28. package/src/hooks/useRestaurant/queries.js +1 -0
  29. package/src/hooks/useStore/queries.js +1 -0
  30. package/src/hooks/useUser/index.js +1 -1
  31. package/.vscode/extensions.json +0 -6
  32. package/.vscode/settings.json +0 -8
package/package.json CHANGED
@@ -43,5 +43,5 @@
43
43
  "rm": "rm -rf node_modules package-lock.json && npm i",
44
44
  "test": "echo \"Error: no test specified\" && exit 1"
45
45
  },
46
- "version": "1.5.7"
46
+ "version": "1.5.9"
47
47
  }
@@ -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 `${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
+ })
@@ -59,4 +59,4 @@ export const getCategoriesWithProduct = (
59
59
  }).filter(Boolean)
60
60
 
61
61
  return findProduct
62
- }
62
+ }
@@ -47,7 +47,7 @@ export const getStartTimestampDaysAgo = (daysAgo) => {
47
47
  }
48
48
 
49
49
  export function convertDateFormat ({ dateString, start }) {
50
- const parsedDate = new Date(dateString)
50
+ const parsedDate = dateString ? new Date(dateString) : new Date()
51
51
  const year = parsedDate.getFullYear()
52
52
  const month = `0${parsedDate.getMonth() + 1}`.slice(-2)
53
53
  const day = `0${parsedDate.getDate()}`.slice(-2)
@@ -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'
@@ -45,6 +48,7 @@ export * from './useScroll'
45
48
  export * from './useStatusOrdersClient'
46
49
  export * from './useUpdateExistingOrders'
47
50
  export * from './useConnection'
51
+ export * from './useManageNewOrder'
48
52
  export * from './useCreateProduct'
49
53
  export * from './useCreateProduct/helpers/useEditImageProduct'
50
54
  export * from './useDessert'
@@ -86,6 +90,7 @@ export * from './useSetState'
86
90
  export * from './useStore'
87
91
  export * from './useStoreCalendar'
88
92
  export * from './getCategoriesWithProduct'
93
+ export * from './useIncomingOrders'
89
94
  export * from './useTimeAgo/useTimeAgo'
90
95
  export * from './useUpdateCart'
91
96
  export * from './useUpdateExtProductFoodsSubOptional'
@@ -7,4 +7,4 @@ mutation deleteOneItem($cState: Int, $ShoppingCard: ID) {
7
7
  message
8
8
  }
9
9
  }
10
- `
10
+ `
@@ -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
+ }
@@ -52,4 +52,4 @@ query getCatProductsWithProductClient($search: String, $min: Int, $max: Int, $ge
52
52
 
53
53
  }
54
54
  }
55
- `
55
+ `
@@ -57,7 +57,9 @@ export const useCategoryInStore = ({ catStoreId, setAlertBox = () => {} } = {})
57
57
  console.log({ message: '', duration: 5000 })
58
58
  },
59
59
  onCompleted: () => {
60
- setOneCategoryInStore(data.getOneCatStore)
60
+ if (data?.getOneCatStore) {
61
+ setOneCategoryInStore(data?.getOneCatStore)
62
+ }
61
63
  }
62
64
  })
63
65
  // HANDLESS
@@ -75,4 +75,4 @@ getOneCatStore(catStore: $catStore){
75
75
  }
76
76
  }
77
77
  }
78
- `
78
+ `
@@ -31,9 +31,6 @@ export const useChartData = ({ year }) => {
31
31
  sumByMonth[key].totalProductsPrice += value.totalProductsPrice
32
32
  })
33
33
 
34
- console.log(result)
35
-
36
- console.log(data?.getAllSalesStore)
37
34
  const allMonths = Array.from({ length: 12 }, (_, i) => { return i })
38
35
  const missingMonths = allMonths.filter(month => { return !result.some(data => { return data.Mes === month }) })
39
36
 
@@ -88,7 +85,6 @@ export const useChartData = ({ year }) => {
88
85
  }
89
86
  ]
90
87
  }
91
- console.log(result)
92
88
  const options = {
93
89
  interaction: {
94
90
  mode: 'index',
@@ -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
+ }
@@ -22,4 +22,4 @@ export const fetchJson = async (...args) => {
22
22
  }
23
23
  throw error
24
24
  }
25
- }
25
+ }
@@ -15,4 +15,4 @@ getOneRating(idStore: $idStore){
15
15
  updateAt
16
16
  }
17
17
  }
18
- `
18
+ `
@@ -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,10 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_INCOMING_ORDERS } from './queries' // Asegúrate de importar tu consulta GraphQL
3
+
4
+ export const useIncomingOrders = ({ statusOrder, idStore }) => {
5
+ const { data, loading, error } = useQuery(GET_ALL_INCOMING_ORDERS, {
6
+ variables: (statusOrder && idStore) ? { statusOrder, idStore } : {}
7
+ })
8
+
9
+ return [data?.getAllIncomingToDayOrders || [], { loading, error }]
10
+ }
@@ -0,0 +1,87 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ALL_INCOMING_ORDERS = gql`
4
+ query getAllIncomingToDayOrders($statusOrder: Int, $idStore: ID) {
5
+ getAllIncomingToDayOrders(statusOrder: $statusOrder, idStore: $idStore) {
6
+ pdpId
7
+ pCodeRef
8
+ idStore
9
+ pPDate
10
+ channel
11
+ pSState
12
+ pDatCre
13
+ pDatMod
14
+ pPRecoger
15
+ payMethodPState
16
+ pdpId
17
+ totalProductsPrice
18
+ locationUser
19
+ getAllPedidoStore {
20
+ pdpId
21
+ idStore
22
+ pCodeRef
23
+ ShoppingCard
24
+ getAllShoppingCard {
25
+ ShoppingCard
26
+ cantProducts
27
+ priceProduct
28
+ refCodePid
29
+ subProductsId
30
+ comments
31
+ pId
32
+ salesExtProductFoodOptional {
33
+ pId
34
+ opExPid
35
+ OptionalProName
36
+ state
37
+ code
38
+ required
39
+ numbersOptionalOnly
40
+ pDatCre
41
+ pDatMod
42
+ saleExtProductFoodsSubOptionalAll {
43
+ pId
44
+ opExPid
45
+ idStore
46
+ opSubExPid
47
+ OptionalSubProName
48
+ exCodeOptionExtra
49
+ exCode
50
+ state
51
+ pDatCre
52
+ pDatMod
53
+ }
54
+ }
55
+ ExtProductFoodsAll {
56
+ pId
57
+ exPid
58
+ exState
59
+ extraName
60
+ extraPrice
61
+ newExtraPrice
62
+ quantity
63
+ state
64
+ pDatCre
65
+ pDatMod
66
+ }
67
+ productFood {
68
+ pId
69
+ carProId
70
+ colorId
71
+ idStore
72
+ pName
73
+ ProPrice
74
+ ProDescuento
75
+ ProDescription
76
+ ValueDelivery
77
+ ProImage
78
+ ProStar
79
+ pState
80
+ pDatCre
81
+ pDatMod
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ `
@@ -25,4 +25,4 @@ export const useKeyPress = (targetKey) => {
25
25
  }, [targetKey])
26
26
 
27
27
  return keyPressed
28
- }
28
+ }
@@ -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
+ }
File without changes
@@ -0,0 +1,104 @@
1
+ import { useEffect, useState } from 'react'
2
+ import {
3
+ useGetSale,
4
+ updateExistingOrders,
5
+ convertDateFormat,
6
+ useOrdersFromStore
7
+ } from '../../hooks'
8
+ import { findOrderByCodeRef, isDateInRange } from './helpers'
9
+
10
+ export const useManageNewOrder = ({
11
+ client,
12
+ idStore,
13
+ setAlertBox = ({ message, duration }) => {
14
+ return { message, duration }
15
+ },
16
+ playNotificationSound = () => {},
17
+ setCountOrders = (number) => { return number },
18
+ sendNotification = ({ title, description, backgroundColor }) => {
19
+ return {
20
+ title,
21
+ description,
22
+ backgroundColor
23
+ }
24
+ }
25
+ }) => {
26
+ const KEY_STATUS_ORDER = 'ACEPTA'
27
+ const [orders, setOrders] = useState([])
28
+
29
+ const [data] = useOrdersFromStore({
30
+ idStore,
31
+ search: '',
32
+ fromDate: convertDateFormat({ start: true }),
33
+ toDate: convertDateFormat({ start: false })
34
+ })
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
+
49
+ const [isOpenOrder, setIsOpenOrder] = useState(false)
50
+ const { getOnePedidoStore } = useGetSale()
51
+
52
+ const handleNewOrder = (order) => {
53
+ const dataOrder = data[KEY_STATUS_ORDER]
54
+ setOrders(dataOrder)
55
+ const { pCodeRef } = order || {}
56
+ if (pCodeRef) {
57
+ const isCodeRefExists = findOrderByCodeRef(data, pCodeRef)
58
+ if (isCodeRefExists) {
59
+ return
60
+ }
61
+ setIsOpenOrder(true)
62
+ playNotificationSound()
63
+ getOnePedidoStore({
64
+ variables: {
65
+ pCodeRef: pCodeRef ?? ''
66
+ }
67
+ }).then((response) => {
68
+ console.log(response)
69
+ const currentSale = response?.data?.getOnePedidoStore || {}
70
+ client.cache.modify({
71
+ fields: {
72
+ getAllOrdersFromStore (existingOrders = []) {
73
+ try {
74
+ const cache = updateExistingOrders(
75
+ existingOrders,
76
+ pCodeRef,
77
+ 1,
78
+ currentSale
79
+ )
80
+ const currentOrder = cache[KEY_STATUS_ORDER]
81
+ const filteredOrders = currentOrder.filter(order =>
82
+ isDateInRange(order.pDatCre)
83
+ )
84
+ setOrders(filteredOrders)
85
+ playNotificationSound()
86
+ return cache
87
+ } catch (e) {
88
+ return existingOrders
89
+ }
90
+ }
91
+ }
92
+ })
93
+ })
94
+ setAlertBox({ message: 'Nuevo pedido', duration: 100000 })
95
+ sendNotification({
96
+ title: 'Pedido',
97
+ description: 'Nuevo pedido',
98
+ backgroundColor: 'success'
99
+ })
100
+ }
101
+ }
102
+
103
+ return [orders, { handleNewOrder, isOpenOrder, setIsOpenOrder }]
104
+ }
@@ -2,4 +2,4 @@ export const useOrderClient = () => {
2
2
  return {
3
3
 
4
4
  }
5
- }
5
+ }
@@ -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
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,
18
23
  open: status?.open ? 1 : 0
19
24
  }
20
25
  }).sort((a, b) => b.open - a.open)
@@ -16,6 +16,7 @@ query getAllStoreInStore($search: String, $min: Int, $max: Int){
16
16
  cId
17
17
  id
18
18
  dId
19
+ deliveryTimeMinutes
19
20
  ctId
20
21
  catStore
21
22
  neighborhoodStore
@@ -15,6 +15,7 @@ query getStore($id: ID, $idStore: ID){
15
15
  getStore(id: $id, idStore: $idStore){
16
16
  cId
17
17
  id
18
+ deliveryTimeMinutes
18
19
  scheduleOpenAll
19
20
  dId
20
21
  idStore
@@ -14,4 +14,4 @@ export const useUserProfile = () => {
14
14
  export const useSetUserProfile = () => {
15
15
  const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
16
16
  return [setUserProfile, { loading, error }]
17
- }
17
+ }
@@ -1,6 +0,0 @@
1
- {
2
- "recommendations": [
3
- "github.copilot",
4
- "github.copilot-nightly"
5
- ]
6
- }
@@ -1,8 +0,0 @@
1
- {
2
- "cSpell.words": [
3
- "Anauthorized",
4
- "deepmerge",
5
- "Eliminado",
6
- "Pedido"
7
- ]
8
- }