npm-pkg-hook 1.11.7 → 1.12.3

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
@@ -7,8 +7,8 @@
7
7
  "js-cookie": "3.0.1",
8
8
  "lodash": "^4.17.21",
9
9
  "moment": "^2.29.4",
10
- "react": "18.1.0",
11
- "react-dom": "18.1.0",
10
+ "react": "^19.0.0",
11
+ "react-dom": "^19.0.0",
12
12
  "react-query": "^3.39.2",
13
13
  "xlsx": "0.18.5"
14
14
  },
@@ -46,5 +46,5 @@
46
46
  "rm": "rm -rf node_modules package-lock.json && npm i",
47
47
  "test": "echo \"Error: no test specified\" && exit 1"
48
48
  },
49
- "version": "1.11.7"
50
- }
49
+ "version": "1.12.3"
50
+ }
@@ -142,3 +142,5 @@ export * from './usePortFetcher'
142
142
  export * from './useImageUploaderProduct'
143
143
  export * from './useTagProducts'
144
144
  export * from './useOrderStatusTypes'
145
+ export * from './useCreateOrderStatusType'
146
+ export * from './useDevWS'
@@ -11,7 +11,6 @@ const NEW_STORE_ORDER_SUBSCRIPTION = gql`
11
11
  `
12
12
 
13
13
  export const newStoreOrderSubscription = (idStore, onOrderReceived) => {
14
- console.log('🚀 ~ newStoreOrderSubscription ~ idStore:', idStore)
15
14
  const subscription = useSubscription(NEW_STORE_ORDER_SUBSCRIPTION, {
16
15
  variables: { idStore },
17
16
  onSubscriptionData: ({ client, subscriptionData }) => {
@@ -0,0 +1,132 @@
1
+ import { gql, useMutation } from '@apollo/client'
2
+
3
+ const CREATE_ORDER_STATUS_TYPE = gql`
4
+ mutation CreateOrderStatusType($data: OrderStatusTypeInput!) {
5
+ createOrderStatusType(data: $data) {
6
+ success
7
+ message
8
+ data {
9
+ idStatus
10
+ name
11
+ description
12
+ color
13
+ priority
14
+ createdAt
15
+ updatedAt
16
+ }
17
+ errors {
18
+ message
19
+ path
20
+ type
21
+ __typename
22
+ }
23
+ }
24
+ }
25
+ `
26
+
27
+ interface OrderStatusTypeInput {
28
+ name: string
29
+ description?: string
30
+ color?: string
31
+ priority?: number
32
+ state?: number
33
+ }
34
+
35
+ interface OrderStatusType {
36
+ idStatus: string
37
+ name: string
38
+ description: string
39
+ color: string
40
+ priority: number
41
+ createdAt: string
42
+ updatedAt: string
43
+ }
44
+
45
+ interface ResponseOrderStatusType {
46
+ success: boolean
47
+ message: string
48
+ data?: OrderStatusType
49
+ errors?: Array<{
50
+ message: string
51
+ path?: string
52
+ type?: string
53
+ __typename?: string
54
+ }>
55
+ }
56
+
57
+ /**
58
+ * 🧩 Hook personalizado para crear un OrderStatusType
59
+ */
60
+ export const useCreateOrderStatusType = ({
61
+ sendNotification
62
+ }: {
63
+ sendNotification: (options: {
64
+ title: string
65
+ description: string
66
+ backgroundColor: 'success' | 'error' | 'info' | 'warning'
67
+ }) => void
68
+ }) => {
69
+ const [createOrderStatusType, { data, loading, error }] =
70
+ useMutation<{ createOrderStatusType: ResponseOrderStatusType }>(
71
+ CREATE_ORDER_STATUS_TYPE,
72
+ {
73
+ update(cache, { data }) {
74
+ console.log("🚀 ~ useCreateOrderStatusType ~ data:", data, cache)
75
+ const newItem = data?.createOrderStatusType?.data
76
+ if (!newItem) return
77
+
78
+ cache.modify({
79
+ fields: {
80
+ getAllOrderStatusTypes(existing = {}) {
81
+ console.log("🚀 ~ useCreateOrderStatusType ~ existing:", existing)
82
+
83
+ }
84
+ }
85
+ })
86
+ },
87
+
88
+ onCompleted: (data) => {
89
+ const res = data.createOrderStatusType
90
+ const { success, message } = res ?? {
91
+ success: false,
92
+ message: 'Error desconocido'
93
+ }
94
+
95
+ sendNotification({
96
+ title: success
97
+ ? 'Estado de orden creado'
98
+ : 'Error al crear el estado de orden',
99
+ description: message,
100
+ backgroundColor: success ? 'success' : 'error',
101
+ })
102
+ }
103
+ }
104
+ )
105
+
106
+ const handleCreateStatus = async (input: OrderStatusTypeInput) => {
107
+ try {
108
+ const response = await createOrderStatusType({
109
+ variables: { data: input },
110
+ })
111
+
112
+ return response.data?.createOrderStatusType
113
+ } catch (err) {
114
+ sendNotification({
115
+ title: 'Error al crear el estado de orden',
116
+ description: 'Ha ocurrido un error inesperado al crear el estado de orden.',
117
+ backgroundColor: 'error',
118
+ })
119
+ throw err
120
+ }
121
+ }
122
+
123
+ return [
124
+ handleCreateStatus,
125
+ {
126
+ data: data?.createOrderStatusType,
127
+ loading,
128
+ error,
129
+ }
130
+ ]
131
+ }
132
+
@@ -0,0 +1,53 @@
1
+ 'use client'
2
+ import { useEffect, useRef, useState } from 'react'
3
+
4
+ export const useDevWS = () => {
5
+ const [status, setStatus] = useState("loading")
6
+ const wsRef = useRef<WebSocket | null>(null)
7
+
8
+ useEffect(() => {
9
+ let reconnectTimer: any
10
+
11
+ const connect = async () => {
12
+ try {
13
+ const r = await fetch('/api/ws-port')
14
+ const { port } = await r.json()
15
+
16
+ if (!port) {
17
+ setStatus("down")
18
+ reconnectTimer = setTimeout(connect, 2000)
19
+ return
20
+ }
21
+
22
+ const ws = new WebSocket(`ws://localhost:${port}`)
23
+ wsRef.current = ws
24
+
25
+ ws.onopen = () => {
26
+ setStatus("up")
27
+ }
28
+
29
+ ws.onerror = () => {
30
+ setStatus("down")
31
+ ws.close()
32
+ }
33
+
34
+ ws.onclose = () => {
35
+ setStatus("down")
36
+ reconnectTimer = setTimeout(connect, 2000)
37
+ }
38
+ } catch {
39
+ setStatus("down")
40
+ reconnectTimer = setTimeout(connect, 2000)
41
+ }
42
+ }
43
+
44
+ connect()
45
+
46
+ return () => {
47
+ wsRef.current?.close()
48
+ clearTimeout(reconnectTimer)
49
+ }
50
+ }, [])
51
+
52
+ return status
53
+ }
@@ -65,28 +65,28 @@ export const useManageNewOrder = ({
65
65
  }
66
66
  }).then((response) => {
67
67
  console.log(response)
68
- const currentSale = response?.data?.getOneSalesStore || {}
68
+ // const currentSale = response?.data?.getOneSalesStore || {}
69
69
  client.cache.modify({
70
70
  fields: {
71
- getAllOrdersFromStore (existingOrders = []) {
72
- try {
73
- const cache = updateExistingOrders(
74
- existingOrders,
75
- pCodeRef,
76
- 1,
77
- currentSale
78
- )
79
- const currentOrder = cache[KEY_STATUS_ORDER]
80
- const filteredOrders = currentOrder.filter(order =>
81
- isDateInRange(order.pDatCre)
82
- )
83
- setOrders(filteredOrders)
84
- playNotificationSound()
85
- return cache
86
- } catch (e) {
87
- return existingOrders
88
- }
89
- }
71
+ // getAllOrdersFromStore (existingOrders = []) {
72
+ // try {
73
+ // const cache = updateExistingOrders(
74
+ // existingOrders,
75
+ // pCodeRef,
76
+ // 1,
77
+ // currentSale
78
+ // )
79
+ // const currentOrder = cache[KEY_STATUS_ORDER]
80
+ // const filteredOrders = currentOrder.filter(order =>
81
+ // isDateInRange(order.pDatCre)
82
+ // )
83
+ // setOrders(filteredOrders)
84
+ // playNotificationSound()
85
+ // return cache
86
+ // } catch (e) {
87
+ // return existingOrders
88
+ // }
89
+ // }
90
90
  }
91
91
  })
92
92
  })
@@ -6,12 +6,36 @@ import { useQuery, gql } from '@apollo/client'
6
6
  const GET_ORDER_STATUS_TYPES = gql`
7
7
  query getAllOrderStatusTypes {
8
8
  getAllOrderStatusTypes {
9
- idStatus
10
- name
11
- priority
12
- backgroundColor
13
- color
14
- state
9
+ message
10
+ success
11
+ __typename
12
+ data {
13
+ backgroundColor
14
+ color
15
+ createdAt
16
+ description
17
+ idStatus
18
+ name
19
+ priority
20
+ state
21
+ updatedAt
22
+ __typename
23
+ }
24
+ pagination {
25
+ currentPage
26
+ totalPages
27
+ totalRecords
28
+ __typename
29
+ }
30
+ errors {
31
+ context {
32
+ key
33
+ label
34
+ limit
35
+ value
36
+ __typename
37
+ }
38
+ }
15
39
  }
16
40
  }
17
41
  `
@@ -36,15 +60,72 @@ const GET_ORDER_STATUS_TYPES = gql`
36
60
  * refetch: () => void
37
61
  * }}
38
62
  */
39
- export const useOrderStatusTypes = () => {
40
- const { data, loading, error, refetch } = useQuery(GET_ORDER_STATUS_TYPES, {
63
+ /**
64
+ * Retrieves order status types via the corresponding GraphQL query and exposes loading state, errors, and refetch capabilities.
65
+ *
66
+ * @param options - Optional configuration values for the hook.
67
+ * @param options.callback - Callback invoked when the query completes successfully, receiving the raw query response.
68
+ * @returns An object containing the normalized status types data along with loading, error, and refetch helpers.
69
+ */
70
+ export interface OrderStatusType {
71
+ idStatus: string
72
+ name: string
73
+ priority: number
74
+ backgroundColor: string
75
+ color: string
76
+ state: number
77
+ description: string
78
+ createdAt: string
79
+ updatedAt: string
80
+ __typename: string
81
+ }
82
+
83
+ export interface OrderStatusTypeErrorContext {
84
+ key: string
85
+ label: string
86
+ limit: number
87
+ value: string
88
+ __typename: string
89
+ }
90
+
91
+ export interface OrderStatusTypeError {
92
+ context: OrderStatusTypeErrorContext[]
93
+ __typename: string
94
+ }
95
+
96
+ export interface GetAllOrderStatusTypesResponse {
97
+ message: string
98
+ success: boolean
99
+ __typename: string
100
+ data: OrderStatusType[]
101
+ errors?: OrderStatusTypeError[] | null
102
+ }
103
+
104
+ export interface OrderStatusTypesQueryResult {
105
+ getAllOrderStatusTypes: GetAllOrderStatusTypesResponse
106
+ }
107
+
108
+ export interface UseOrderStatusTypesOptions {
109
+ callback?: (payload: OrderStatusTypesQueryResult) => void
110
+ }
111
+
112
+ export const useOrderStatusTypes = ({
113
+ callback = () => undefined
114
+ }: UseOrderStatusTypesOptions = {}) => {
115
+ const {
116
+ data,
117
+ loading,
118
+ error,
119
+ refetch
120
+ } = useQuery<OrderStatusTypesQueryResult>(GET_ORDER_STATUS_TYPES, {
121
+ onCompleted: callback,
41
122
  fetchPolicy: 'cache-and-network'
42
123
  })
43
124
 
44
- const statusTypes = data?.getAllOrderStatusTypes ?? null
125
+ const statusTypes = data?.getAllOrderStatusTypes?.data ?? null
45
126
 
46
127
  return {
47
- statusTypes,
128
+ data: statusTypes,
48
129
  loading,
49
130
  error,
50
131
  refetch
@@ -61,104 +61,29 @@ query getAllOrderStoreFinal($idStore: ID, $search: String, $min: Int, $max: Int,
61
61
  }
62
62
  `
63
63
 
64
- export const GET_ALL_PEDIDOS_FROM_STORE = gql`
65
- query getAllOrdersFromStore(
66
- $idStore: ID
67
- $cId: ID
68
- $dId: ID
69
- $ctId: ID
70
- $search: String
71
- $min: Int
72
- $fromDate: DateTime
73
- $toDate: DateTime
74
- $max: Int
75
- $statusOrder: Int
76
- ) {
77
- getAllOrdersFromStore(
78
- idStore: $idStore
79
- cId: $cId
80
- dId: $dId
81
- ctId: $ctId
82
- search: $search
83
- min: $min
84
- fromDate: $fromDate
85
- toDate: $toDate
86
- max: $max
87
- statusOrder: $statusOrder
88
- ) {
89
- statusKey
90
- priority
91
- state
92
- getStatusOrderType {
93
- idStatus
94
- backgroundColor
95
- name
96
- description
97
- color
98
- priority
99
- state
64
+ export const GET_ALL_ORDER_FROM_STORE = gql`
65
+ query getAllSalesStore {
66
+ getAllSalesStore {
67
+ change
68
+ channel
69
+ status
100
70
  createdAt
101
- updatedAt
102
- }
103
- items {
104
- pdpId
105
- idStore
106
71
  pCodeRef
72
+ idStore
73
+ pdpId
74
+ locationUser
75
+ shoppingCartRefCode
107
76
  payMethodPState
108
- pPRecoger
77
+ updatedAt
109
78
  totalProductsPrice
110
- pSState
111
- pDatCre
112
- channel
113
- locationUser
114
- pDatMod
115
- getStatusOrderType {
116
- idStatus
117
- name
118
- description
119
- backgroundColor
120
- color
121
- priority
122
- state
123
- createdAt
124
- updatedAt
125
- }
126
- getStoreOrders {
127
- pdpId
128
- pId
129
- idStore
130
- ShoppingCard
131
- pCodeRef
132
- pPStateP
133
- payMethodPState
134
- pPRecoger
135
- pDatCre
136
- pDatMod
137
- getAllShoppingCard {
138
- ShoppingCard
139
- comments
140
- cantProducts
141
- pId
142
- productFood {
143
- pId
144
- carProId
145
- colorId
146
- idStore
147
- pName
148
- ProPrice
149
- ProDescuento
150
- ProDescription
151
- ValueDelivery
152
- ProImage
153
- ProStar
154
- pState
155
- pDatCre
156
- pDatMod
157
- }
158
- }
79
+ unidProducts
80
+ getUser {
81
+ associateStore
82
+ avatar
83
+ createdAt
84
+ id
85
+ email
159
86
  }
160
- }
161
87
  }
162
88
  }
163
-
164
89
  `
@@ -54,18 +54,18 @@ export const useChangeStateOrder = ({
54
54
  if (!pCodeRef || !pSState) {
55
55
  return
56
56
  }
57
- client.cache.modify({
58
- fields: {
59
- getAllOrdersFromStore(existingOrders = []) {
60
- try {
61
- // return
62
- console.log({ cache: updateExistingOrders(existingOrders, pCodeRef, pSState) })
63
- } catch (e) {
64
- return existingOrders
65
- }
66
- }
67
- }
68
- })
57
+ // client.cache.modify({
58
+ // fields: {
59
+ // getAllOrdersFromStore(existingOrders = []) {
60
+ // try {
61
+ // // return
62
+ // console.log({ cache: updateExistingOrders(existingOrders, pCodeRef, pSState) })
63
+ // } catch (e) {
64
+ // return existingOrders
65
+ // }
66
+ // }
67
+ // }
68
+ // })
69
69
  }
70
70
  }
71
71
  })
@@ -1,5 +1,6 @@
1
1
  import { useQuery } from '@apollo/client'
2
- import { GET_ALL_ORDER, GET_ALL_PEDIDOS_FROM_STORE } from '../queries.js'
2
+ import { GET_ALL_ORDER, GET_ALL_ORDER_FROM_STORE } from '../queries.js'
3
+ import groupBy from 'lodash/groupBy'
3
4
 
4
5
  export const useOrders = ({
5
6
  refetchWritePolicy = 'merge',
@@ -48,36 +49,29 @@ export const useOrdersFromStore = ({
48
49
  toDate,
49
50
  max,
50
51
  statusOrder,
51
- callback = () => {
52
-
52
+ callback = (data) => {
53
+ return data
53
54
  }
54
55
  }) => {
56
+ const key = 'status'
55
57
  const {
56
58
  data,
57
59
  loading,
58
60
  refetch,
59
61
  error,
60
62
  called
61
- } = useQuery(GET_ALL_PEDIDOS_FROM_STORE, {
63
+ } = useQuery(GET_ALL_ORDER_FROM_STORE, {
64
+ notifyOnNetworkStatusChange: true,
65
+ fetchPolicy: 'network-only',
62
66
  onCompleted: (data) => {
63
67
  if (typeof callback === 'function') {
64
68
  callback(data)
65
69
  }
66
- },
67
- variables: {
68
- idStore,
69
- cId,
70
- dId,
71
- ctId,
72
- search,
73
- min,
74
- fromDate,
75
- toDate,
76
- max,
77
- statusOrder
78
70
  }
79
71
  })
72
+ const grouped = groupBy(data?.getAllSalesStore ?? [], key)
73
+
80
74
 
81
- return [data?.getAllOrdersFromStore || [], { refetch, loading: called ? false : loading, error }]
75
+ return [grouped, { refetch, loading: called ? false : loading, error }]
82
76
  }
83
77
 
@@ -1118,18 +1118,18 @@ export const useSales = ({
1118
1118
  const currentSale = responseSale?.data?.getOneSalesStore || {}
1119
1119
  const inComingCodeRef = currentSale?.pCodeRef || null
1120
1120
  if (!inComingCodeRef) return
1121
- client.cache.modify({
1122
- fields: {
1123
- getAllOrdersFromStore (existingOrders = []) {
1124
- try {
1125
- const newGetAllOrdersFromStore = updateExistingOrders(existingOrders, inComingCodeRef, 4, currentSale)
1126
- return newGetAllOrdersFromStore
1127
- } catch (e) {
1128
- return existingOrders
1129
- }
1130
- }
1131
- }
1132
- })
1121
+ // client.cache.modify({
1122
+ // fields: {
1123
+ // getAllOrdersFromStore (existingOrders = []) {
1124
+ // try {
1125
+ // const newGetAllOrdersFromStore = updateExistingOrders(existingOrders, inComingCodeRef, 4, currentSale)
1126
+ // return newGetAllOrdersFromStore
1127
+ // } catch (e) {
1128
+ // return existingOrders
1129
+ // }
1130
+ // }
1131
+ // }
1132
+ // })
1133
1133
  }
1134
1134
  })
1135
1135
  router.push(