npm-pkg-hook 1.5.7 → 1.5.8
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/getTodayTimestamps/index.js +1 -1
- package/src/hooks/index.js +2 -0
- package/src/hooks/useCategoryInStore/index.js +3 -1
- package/src/hooks/useChartData/index.js +0 -4
- package/src/hooks/useIncomingOrders/index.js +10 -0
- package/src/hooks/useIncomingOrders/queries.js +87 -0
- package/src/hooks/useManageNewOrder/helpers/index.js +0 -0
- package/src/hooks/useManageNewOrder/helpers/mock.js +0 -0
- package/src/hooks/useManageNewOrder/index.js +143 -0
- package/src/hooks/useUser/index.js +1 -1
package/package.json
CHANGED
|
@@ -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)
|
package/src/hooks/index.js
CHANGED
|
@@ -45,6 +45,7 @@ export * from './useScroll'
|
|
|
45
45
|
export * from './useStatusOrdersClient'
|
|
46
46
|
export * from './useUpdateExistingOrders'
|
|
47
47
|
export * from './useConnection'
|
|
48
|
+
export * from './useManageNewOrder'
|
|
48
49
|
export * from './useCreateProduct'
|
|
49
50
|
export * from './useCreateProduct/helpers/useEditImageProduct'
|
|
50
51
|
export * from './useDessert'
|
|
@@ -86,6 +87,7 @@ export * from './useSetState'
|
|
|
86
87
|
export * from './useStore'
|
|
87
88
|
export * from './useStoreCalendar'
|
|
88
89
|
export * from './getCategoriesWithProduct'
|
|
90
|
+
export * from './useIncomingOrders'
|
|
89
91
|
export * from './useTimeAgo/useTimeAgo'
|
|
90
92
|
export * from './useUpdateCart'
|
|
91
93
|
export * from './useUpdateExtProductFoodsSubOptional'
|
|
@@ -57,7 +57,9 @@ export const useCategoryInStore = ({ catStoreId, setAlertBox = () => {} } = {})
|
|
|
57
57
|
console.log({ message: '', duration: 5000 })
|
|
58
58
|
},
|
|
59
59
|
onCompleted: () => {
|
|
60
|
-
|
|
60
|
+
if (data?.getOneCatStore) {
|
|
61
|
+
setOneCategoryInStore(data?.getOneCatStore)
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
})
|
|
63
65
|
// HANDLESS
|
|
@@ -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,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
|
+
`
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
useGetSale,
|
|
4
|
+
updateExistingOrders,
|
|
5
|
+
convertDateFormat,
|
|
6
|
+
useOrdersFromStore
|
|
7
|
+
} from '../../hooks'
|
|
8
|
+
|
|
9
|
+
export const useManageNewOrder = ({
|
|
10
|
+
client,
|
|
11
|
+
idStore,
|
|
12
|
+
setAlertBox = ({ message, duration }) => {
|
|
13
|
+
return { message, duration }
|
|
14
|
+
},
|
|
15
|
+
playNotificationSound = () => {},
|
|
16
|
+
sendNotification = ({ title, description, backgroundColor }) => {
|
|
17
|
+
return {
|
|
18
|
+
title,
|
|
19
|
+
description,
|
|
20
|
+
backgroundColor
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}) => {
|
|
24
|
+
const KEY_STATUS_ORDER = 'ACEPTA'
|
|
25
|
+
const [orders, setOrders] = useState([])
|
|
26
|
+
|
|
27
|
+
const [data] = useOrdersFromStore({
|
|
28
|
+
idStore,
|
|
29
|
+
fromDate: convertDateFormat({ start: true }),
|
|
30
|
+
toDate: convertDateFormat({ start: false })
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const [isOpenOrder, setIsOpenOrder] = useState(false)
|
|
34
|
+
const { getOnePedidoStore } = useGetSale()
|
|
35
|
+
|
|
36
|
+
const handleNewOrder = (order) => {
|
|
37
|
+
const dataOrder = data[KEY_STATUS_ORDER]
|
|
38
|
+
setOrders(dataOrder)
|
|
39
|
+
const { pCodeRef } = order || {}
|
|
40
|
+
if (pCodeRef) {
|
|
41
|
+
const isCodeRefExists = orders.some(item => item.pCodeRef === pCodeRef)
|
|
42
|
+
if (isCodeRefExists) {
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
setIsOpenOrder(true)
|
|
46
|
+
playNotificationSound()
|
|
47
|
+
getOnePedidoStore({
|
|
48
|
+
variables: {
|
|
49
|
+
pCodeRef: pCodeRef ?? ''
|
|
50
|
+
}
|
|
51
|
+
}).then((response) => {
|
|
52
|
+
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
|
+
}
|
|
107
|
+
client.cache.modify({
|
|
108
|
+
fields: {
|
|
109
|
+
getAllOrdersFromStore (existingOrders = []) {
|
|
110
|
+
try {
|
|
111
|
+
const cache = updateExistingOrders(
|
|
112
|
+
existingOrders,
|
|
113
|
+
pCodeRef,
|
|
114
|
+
1,
|
|
115
|
+
currentSale
|
|
116
|
+
)
|
|
117
|
+
const currentOrder = cache[KEY_STATUS_ORDER]
|
|
118
|
+
const isCodeRefExists = currentOrder.some(item => item.pCodeRef === pCodeRef)
|
|
119
|
+
if (isCodeRefExists) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
if (currentOrder) {
|
|
123
|
+
setOrders(currentOrder)
|
|
124
|
+
}
|
|
125
|
+
return cache
|
|
126
|
+
} catch (e) {
|
|
127
|
+
return existingOrders
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
setAlertBox({ message: 'Nuevo pedido', duration: 100000 })
|
|
134
|
+
sendNotification({
|
|
135
|
+
title: 'Pedido',
|
|
136
|
+
description: 'Nuevo pedido',
|
|
137
|
+
backgroundColor: 'success'
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return [orders, { handleNewOrder, isOpenOrder, setIsOpenOrder }]
|
|
143
|
+
}
|