npm-pkg-hook 1.5.6 → 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 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.6"
46
+ "version": "1.5.8"
47
47
  }
@@ -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)
@@ -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'
@@ -42,6 +45,7 @@ export * from './useScroll'
42
45
  export * from './useStatusOrdersClient'
43
46
  export * from './useUpdateExistingOrders'
44
47
  export * from './useConnection'
48
+ export * from './useManageNewOrder'
45
49
  export * from './useCreateProduct'
46
50
  export * from './useCreateProduct/helpers/useEditImageProduct'
47
51
  export * from './useDessert'
@@ -83,6 +87,7 @@ export * from './useSetState'
83
87
  export * from './useStore'
84
88
  export * from './useStoreCalendar'
85
89
  export * from './getCategoriesWithProduct'
90
+ export * from './useIncomingOrders'
86
91
  export * from './useTimeAgo/useTimeAgo'
87
92
  export * from './useUpdateCart'
88
93
  export * from './useUpdateExtProductFoodsSubOptional'
@@ -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
+ }
@@ -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
@@ -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
 
@@ -60,7 +57,7 @@ export const useChartData = ({ year }) => {
60
57
  datasets: [
61
58
  {
62
59
  label: labelTitle,
63
- data: asFilter ? newResult.map(data => { return data.totalProductsPrice }) : result.map(data => { return data.totalProductsPrice }),
60
+ data: asFilter ? newResult.map(data => { return data?.totalProductsPrice }) : result.map(data => { return data?.totalProductsPrice }),
64
61
  backgroundColor: [
65
62
  'rgba(255, 99, 132, 0.2)',
66
63
  'rgba(54, 162, 235, 0.2)',
@@ -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',
@@ -111,7 +107,7 @@ export const useChartData = ({ year }) => {
111
107
  }
112
108
  const groupedData = {}
113
109
 
114
- data && data.getAllSalesStore.forEach((item) => {
110
+ Boolean(data?.getAllSalesStore?.length) && data?.getAllSalesStore?.forEach((item) => {
115
111
  const year = new Date(item.pDatCre).getFullYear()
116
112
  if (!groupedData[year]) {
117
113
  groupedData[year] = []
@@ -119,7 +115,8 @@ export const useChartData = ({ year }) => {
119
115
  groupedData[year].push(item)
120
116
  })
121
117
  const years = []
122
- data && data.getAllSalesStore.forEach((item) => {
118
+
119
+ Boolean(data?.getAllSalesStore?.length) && data?.getAllSalesStore?.forEach((item) => {
123
120
  const y = new Date(item.pDatCre).getFullYear()
124
121
  if (!years.includes(y)) {
125
122
  years.push(y)
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }