npm-pkg-hook 1.12.0 → 1.12.4
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": "
|
|
11
|
-
"react-dom": "
|
|
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.
|
|
50
|
-
}
|
|
49
|
+
"version": "1.12.4"
|
|
50
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -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 }] =
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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 [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// usePrintSaleTicket.ts
|
|
2
|
+
import { gql, useMutation, MutationHookOptions } from '@apollo/client'
|
|
3
|
+
import { useCallback } from 'react'
|
|
4
|
+
|
|
5
|
+
/* ------------------------------
|
|
6
|
+
TYPES
|
|
7
|
+
------------------------------ */
|
|
8
|
+
|
|
9
|
+
export interface PrintSaleTicketResponse {
|
|
10
|
+
printSaleTicket: {
|
|
11
|
+
message: string
|
|
12
|
+
success: boolean
|
|
13
|
+
data: string | null
|
|
14
|
+
__typename: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PrintSaleTicketVars {
|
|
19
|
+
saleId: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/* ------------------------------
|
|
23
|
+
GQL
|
|
24
|
+
------------------------------ */
|
|
25
|
+
|
|
26
|
+
const PRINT_SALE_TICKET = gql`
|
|
27
|
+
mutation printSaleTicket($saleId: ID!) {
|
|
28
|
+
printSaleTicket(saleId: $saleId) {
|
|
29
|
+
message
|
|
30
|
+
success
|
|
31
|
+
data
|
|
32
|
+
__typename
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`
|
|
36
|
+
|
|
37
|
+
/* ------------------------------
|
|
38
|
+
HOOK
|
|
39
|
+
------------------------------ */
|
|
40
|
+
|
|
41
|
+
export function usePrintSaleTicket(
|
|
42
|
+
options?: MutationHookOptions<PrintSaleTicketResponse, PrintSaleTicketVars>
|
|
43
|
+
) {
|
|
44
|
+
const [runMutation, { loading, data, error }] = useMutation<
|
|
45
|
+
PrintSaleTicketResponse,
|
|
46
|
+
PrintSaleTicketVars
|
|
47
|
+
>(PRINT_SALE_TICKET, options)
|
|
48
|
+
|
|
49
|
+
const printSale = useCallback(
|
|
50
|
+
async (saleId: string) => {
|
|
51
|
+
const result = await runMutation({
|
|
52
|
+
variables: { saleId }
|
|
53
|
+
})
|
|
54
|
+
return result.data?.printSaleTicket
|
|
55
|
+
},
|
|
56
|
+
[runMutation]
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return [printSale, {
|
|
60
|
+
loading,
|
|
61
|
+
data: data?.printSaleTicket,
|
|
62
|
+
error
|
|
63
|
+
}]
|
|
64
|
+
}
|