npm-pkg-hook 1.5.6 → 1.5.7
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
package/src/hooks/index.js
CHANGED
|
@@ -6,9 +6,12 @@ export * from './useCategoryStore'
|
|
|
6
6
|
export * from './useCatWithProduct'
|
|
7
7
|
export * from './useManageQueryParams'
|
|
8
8
|
export * from './statusOpenStores'
|
|
9
|
+
export * from './newMessageSubscription'
|
|
9
10
|
export * from './useCategoriesProduct'
|
|
10
11
|
export * from './useLogout'
|
|
11
12
|
export * from './useStatusOpenStore'
|
|
13
|
+
export * from './usePushNotificationOrder'
|
|
14
|
+
export * from './newStoreOrderSubscription'
|
|
12
15
|
export * from './useChatRoomSubscription'
|
|
13
16
|
export * from './useScheduleData'
|
|
14
17
|
export * from './useGetMessagesToRoom'
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useSubscription, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const NEW_MESSAGE_SUBSCRIPTION = gql`
|
|
4
|
+
subscription NewMessage($idStore: String!) {
|
|
5
|
+
newMessage(idStore: $idStore) {
|
|
6
|
+
uuid
|
|
7
|
+
content
|
|
8
|
+
aDatCre
|
|
9
|
+
from
|
|
10
|
+
to
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
export const newMessageSubscription = (idStore, onMessageReceived) => {
|
|
16
|
+
const subscription = useSubscription(NEW_MESSAGE_SUBSCRIPTION, {
|
|
17
|
+
variables: { idStore },
|
|
18
|
+
onSubscriptionData: ({ client, subscriptionData }) => {
|
|
19
|
+
if (subscriptionData.data && subscriptionData.data.newMessage) {
|
|
20
|
+
// Llama a la función proporcionada cuando se recibe un nuevo mensaje
|
|
21
|
+
onMessageReceived(subscriptionData.data.newMessage)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// Puedes ajustar lo que devuelve el hook según tus necesidades
|
|
27
|
+
return subscription
|
|
28
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useSubscription, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
const NEW_STORE_ORDER_SUBSCRIPTION = gql`
|
|
4
|
+
subscription NewStoreOrder($idStore: String!) {
|
|
5
|
+
newStoreOrder(idStore: $idStore) {
|
|
6
|
+
pdpId
|
|
7
|
+
id
|
|
8
|
+
idStore
|
|
9
|
+
pId
|
|
10
|
+
ppState
|
|
11
|
+
pCodeRef
|
|
12
|
+
pPDate
|
|
13
|
+
pSState
|
|
14
|
+
pPStateP
|
|
15
|
+
payMethodPState
|
|
16
|
+
pPRecoger
|
|
17
|
+
totalProductsPrice
|
|
18
|
+
unidProducts
|
|
19
|
+
pDatCre
|
|
20
|
+
pDatMod
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
`
|
|
24
|
+
|
|
25
|
+
export const newStoreOrderSubscription = (idStore, onOrderReceived) => {
|
|
26
|
+
const subscription = useSubscription(NEW_STORE_ORDER_SUBSCRIPTION, {
|
|
27
|
+
variables: { idStore },
|
|
28
|
+
onSubscriptionData: ({ client, subscriptionData }) => {
|
|
29
|
+
if (subscriptionData.data && subscriptionData.data.newStoreOrder) {
|
|
30
|
+
// Llama a la función proporcionada cuando se recibe una nueva orden
|
|
31
|
+
onOrderReceived(subscriptionData.data.newStoreOrder)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
// Puedes ajustar lo que devuelve el hook según tus necesidades
|
|
37
|
+
return subscription
|
|
38
|
+
}
|
|
@@ -60,7 +60,7 @@ export const useChartData = ({ year }) => {
|
|
|
60
60
|
datasets: [
|
|
61
61
|
{
|
|
62
62
|
label: labelTitle,
|
|
63
|
-
data: asFilter ? newResult.map(data => { return data
|
|
63
|
+
data: asFilter ? newResult.map(data => { return data?.totalProductsPrice }) : result.map(data => { return data?.totalProductsPrice }),
|
|
64
64
|
backgroundColor: [
|
|
65
65
|
'rgba(255, 99, 132, 0.2)',
|
|
66
66
|
'rgba(54, 162, 235, 0.2)',
|
|
@@ -111,7 +111,7 @@ export const useChartData = ({ year }) => {
|
|
|
111
111
|
}
|
|
112
112
|
const groupedData = {}
|
|
113
113
|
|
|
114
|
-
data && data
|
|
114
|
+
Boolean(data?.getAllSalesStore?.length) && data?.getAllSalesStore?.forEach((item) => {
|
|
115
115
|
const year = new Date(item.pDatCre).getFullYear()
|
|
116
116
|
if (!groupedData[year]) {
|
|
117
117
|
groupedData[year] = []
|
|
@@ -119,7 +119,8 @@ export const useChartData = ({ year }) => {
|
|
|
119
119
|
groupedData[year].push(item)
|
|
120
120
|
})
|
|
121
121
|
const years = []
|
|
122
|
-
|
|
122
|
+
|
|
123
|
+
Boolean(data?.getAllSalesStore?.length) && data?.getAllSalesStore?.forEach((item) => {
|
|
123
124
|
const y = new Date(item.pDatCre).getFullYear()
|
|
124
125
|
if (!years.includes(y)) {
|
|
125
126
|
years.push(y)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { useMutation, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
// Define el mutation GraphQL
|
|
4
|
+
const PUSH_NOTIFICATION_ORDER = gql`
|
|
5
|
+
mutation PushNotificationOrder($pCodeRef: String!, $idStore: ID!) {
|
|
6
|
+
pushNotificationOrder(pCodeRef: $pCodeRef, idStore: $idStore) {
|
|
7
|
+
pdpId
|
|
8
|
+
id
|
|
9
|
+
idStore
|
|
10
|
+
pId
|
|
11
|
+
ppState
|
|
12
|
+
pCodeRef
|
|
13
|
+
pPDate
|
|
14
|
+
pSState
|
|
15
|
+
pPStateP
|
|
16
|
+
payMethodPState
|
|
17
|
+
pPRecoger
|
|
18
|
+
totalProductsPrice
|
|
19
|
+
unidProducts
|
|
20
|
+
pDatCre
|
|
21
|
+
pDatMod
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
// Definir el hook personalizado
|
|
27
|
+
export const usePushNotificationOrder = ({ client }) => {
|
|
28
|
+
// Usar el hook useMutation para ejecutar el mutation
|
|
29
|
+
const [pushNotificationOrderMutation] = useMutation(PUSH_NOTIFICATION_ORDER, {
|
|
30
|
+
context: { clientName: client }
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// Función para ejecutar el mutation
|
|
34
|
+
const pushNotificationOrder = async (pCodeRef, idStore) => {
|
|
35
|
+
try {
|
|
36
|
+
// Ejecutar el mutation con los parámetros proporcionados
|
|
37
|
+
const { data } = await pushNotificationOrderMutation({
|
|
38
|
+
variables: { pCodeRef, idStore }
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// Devolver los datos de la orden recibidos del servidor
|
|
42
|
+
return data.pushNotificationOrder
|
|
43
|
+
} catch (error) {
|
|
44
|
+
// Manejar cualquier error que ocurra durante la ejecución del mutation
|
|
45
|
+
console.error('Error al ejecutar el mutation pushNotificationOrder:', error)
|
|
46
|
+
throw new Error('Error al publicar la nueva orden de tienda. Por favor, vuelve a intentarlo.')
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Devolver la función pushNotificationOrder para ser utilizada por el componente
|
|
51
|
+
return pushNotificationOrder
|
|
52
|
+
}
|