npm-pkg-hook 1.12.0 → 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.12.0"
50
- }
49
+ "version": "1.12.3"
50
+ }
@@ -143,3 +143,4 @@ export * from './useImageUploaderProduct'
143
143
  export * from './useTagProducts'
144
144
  export * from './useOrderStatusTypes'
145
145
  export * from './useCreateOrderStatusType'
146
+ export * from './useDevWS'
@@ -66,26 +66,49 @@ export const useCreateOrderStatusType = ({
66
66
  backgroundColor: 'success' | 'error' | 'info' | 'warning'
67
67
  }) => void
68
68
  }) => {
69
- const [createOrderStatusType, { data, loading, error }] =useMutation<{ createOrderStatusType: ResponseOrderStatusType }>(CREATE_ORDER_STATUS_TYPE, {
70
- onCompleted: (data) => {
71
- const createOrderStatusType = data.createOrderStatusType
72
- const { success, message } = createOrderStatusType ?? {
73
- success: false,
74
- message: 'Error desconocido'
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
+ }
75
103
  }
76
- sendNotification({
77
- title: success ? 'Estado de orden creado' : 'Error al crear el estado de orden',
78
- description: message,
79
- backgroundColor: success ? 'success' : 'error',
80
- })
81
- }
82
- })
104
+ )
83
105
 
84
106
  const handleCreateStatus = async (input: OrderStatusTypeInput) => {
85
107
  try {
86
108
  const response = await createOrderStatusType({
87
109
  variables: { data: input },
88
110
  })
111
+
89
112
  return response.data?.createOrderStatusType
90
113
  } catch (err) {
91
114
  sendNotification({
@@ -97,9 +120,13 @@ export const useCreateOrderStatusType = ({
97
120
  }
98
121
  }
99
122
 
100
- return [handleCreateStatus, {
101
- data: data?.createOrderStatusType,
102
- loading,
103
- error,
104
- }]
123
+ return [
124
+ handleCreateStatus,
125
+ {
126
+ data: data?.createOrderStatusType,
127
+ loading,
128
+ error,
129
+ }
130
+ ]
105
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
+ }