npm-pkg-hook 1.12.3 → 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
package/src/hooks/index.ts
CHANGED
|
@@ -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
|
+
}
|