npm-pkg-hook 1.11.6 → 1.12.0
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 +3 -2
- package/src/config/client/errors.js +1 -1
- package/src/hooks/{index.js → index.ts} +1 -0
- package/src/hooks/newStoreOrderSubscription/index.js +0 -1
- package/src/hooks/useCreateOrderStatusType/index.ts +105 -0
- package/src/hooks/useManageNewOrder/index.js +20 -20
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +91 -10
- package/src/hooks/useOrders/queries.js +18 -93
- package/src/hooks/useOrders/useChangeOrderState/index.ts +12 -12
- package/src/hooks/useOrders/useOrdersFromStore/index.ts +11 -17
- package/src/hooks/useSales/index.js +12 -12
package/package.json
CHANGED
|
@@ -39,11 +39,12 @@
|
|
|
39
39
|
"type": "git",
|
|
40
40
|
"url": "https://github.com/Jesus123780/pkg-hook"
|
|
41
41
|
},
|
|
42
|
+
"private": false,
|
|
42
43
|
"scripts": {
|
|
43
44
|
"lint": "eslint .",
|
|
44
45
|
"lint:fix": "npm run lint -- --fix",
|
|
45
46
|
"rm": "rm -rf node_modules package-lock.json && npm i",
|
|
46
47
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
47
48
|
},
|
|
48
|
-
"version": "1.
|
|
49
|
-
}
|
|
49
|
+
"version": "1.12.0"
|
|
50
|
+
}
|
|
@@ -5,7 +5,7 @@ export const errorHandler = (error) => {
|
|
|
5
5
|
if (error && Array.isArray(error?.errors)) {
|
|
6
6
|
error.errors?.length && error?.errors?.forEach(err => {
|
|
7
7
|
if (err?.extensions) {
|
|
8
|
-
const { code, message
|
|
8
|
+
const { code, message } = err?.extensions || {}
|
|
9
9
|
if (code === 'UNAUTHENTICATED' || code === 'FORBIDDEN') {
|
|
10
10
|
logout = true
|
|
11
11
|
return {
|
|
@@ -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,105 @@
|
|
|
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 }] =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'
|
|
75
|
+
}
|
|
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
|
+
})
|
|
83
|
+
|
|
84
|
+
const handleCreateStatus = async (input: OrderStatusTypeInput) => {
|
|
85
|
+
try {
|
|
86
|
+
const response = await createOrderStatusType({
|
|
87
|
+
variables: { data: input },
|
|
88
|
+
})
|
|
89
|
+
return response.data?.createOrderStatusType
|
|
90
|
+
} catch (err) {
|
|
91
|
+
sendNotification({
|
|
92
|
+
title: 'Error al crear el estado de orden',
|
|
93
|
+
description: 'Ha ocurrido un error inesperado al crear el estado de orden.',
|
|
94
|
+
backgroundColor: 'error',
|
|
95
|
+
})
|
|
96
|
+
throw err
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return [handleCreateStatus, {
|
|
101
|
+
data: data?.createOrderStatusType,
|
|
102
|
+
loading,
|
|
103
|
+
error,
|
|
104
|
+
}]
|
|
105
|
+
}
|
|
@@ -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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
40
|
-
|
|
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
|
|
65
|
-
query
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
77
|
+
updatedAt
|
|
109
78
|
totalProductsPrice
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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,
|
|
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(
|
|
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 [
|
|
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
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
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(
|