npm-pkg-hook 1.11.3 → 1.11.6

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.
Files changed (81) hide show
  1. package/.env +5 -1
  2. package/package.json +1 -1
  3. package/src/config/content/en.json +5 -0
  4. package/src/config/content/es.json +5 -0
  5. package/src/config/content/index.js +16 -0
  6. package/src/hooks/index.js +6 -0
  7. package/src/hooks/newStoreOrderSubscription/index.js +1 -12
  8. package/src/hooks/updateExtProductFoodsOptional/index.js +2 -2
  9. package/src/hooks/useCatWithProduct/queries.js +50 -24
  10. package/src/hooks/useCategoriesProduct/index.js +1 -0
  11. package/src/hooks/useCategoriesProduct/queries.js +2 -2
  12. package/src/hooks/useCategoryInStore/queries.js +2 -2
  13. package/src/hooks/useClients/queries.js +72 -23
  14. package/src/hooks/useCreateProduct/helpers/index.js +2 -2
  15. package/src/hooks/useCreateProduct/index.js +45 -46
  16. package/src/hooks/useDessert/index.js +20 -3
  17. package/src/hooks/useDessertWithPrice/helpers/index.js +2 -2
  18. package/src/hooks/useDessertWithPrice/index.js +70 -60
  19. package/src/hooks/useDessertWithPrice/queries.js +2 -2
  20. package/src/hooks/useDevices/queries.js +16 -7
  21. package/src/hooks/useDevices/useGetDevices.js +12 -19
  22. package/src/hooks/useDevices/useRegisterDevices.js +3 -3
  23. package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +21 -0
  24. package/src/hooks/useDownloadReports/index.ts +2 -0
  25. package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +103 -0
  26. package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +115 -0
  27. package/src/hooks/useEditCategory/index.js +10 -10
  28. package/src/hooks/useFormTools/index.js +2 -1
  29. package/src/hooks/useFormatDate/index.js +56 -3
  30. package/src/hooks/useGetStoreCookie/index.js +1 -1
  31. package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +130 -0
  32. package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +53 -0
  33. package/src/hooks/useImageUploaderProduct/helper/index.ts +5 -0
  34. package/src/hooks/useImageUploaderProduct/index.ts +292 -0
  35. package/src/hooks/useImagesStore/index.js +100 -58
  36. package/src/hooks/useImagesStore/queries.js +2 -2
  37. package/src/hooks/useImagesStore/utils/index.js +4 -0
  38. package/src/hooks/useInventory/queries.js +1 -1
  39. package/src/hooks/useLocationManager/index.js +3 -1
  40. package/src/hooks/useLogout/helpers/fetchData.js +1 -1
  41. package/src/hooks/useLogout/helpers/logger.js +8 -8
  42. package/src/hooks/useLogout/index.js +6 -4
  43. package/src/hooks/useManageNewOrder/index.js +3 -3
  44. package/src/hooks/useManageQueryParams/index.js +28 -28
  45. package/src/hooks/useMobile/index.js +38 -8
  46. package/src/hooks/useOrderStatusTypes/index.ts +2 -0
  47. package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +52 -0
  48. package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +97 -0
  49. package/src/hooks/useOrders/index.js +2 -74
  50. package/src/hooks/useOrders/queries.js +31 -195
  51. package/src/hooks/useOrders/useChangeOrderState/index.ts +125 -0
  52. package/src/hooks/useOrders/useOrdersFromStore/index.ts +83 -0
  53. package/src/hooks/usePortFetcher/index.ts +33 -0
  54. package/src/hooks/useProductsFood/index.js +3 -3
  55. package/src/hooks/useProductsFood/queriesStore.js +120 -64
  56. package/src/hooks/useProductsFood/useEditProduct.js +42 -2
  57. package/src/hooks/useProductsFood/usetagsProducts.js +47 -43
  58. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +4 -4
  59. package/src/hooks/useSales/index.js +29 -19
  60. package/src/hooks/useSales/queries.js +140 -162
  61. package/src/hooks/useSales/useGetSale.js +3 -3
  62. package/src/hooks/useSaveAvailableProduct/index.js +1 -0
  63. package/src/hooks/useSetImageProducts/index.js +42 -13
  64. package/src/hooks/useSetImageProducts/queries.js +5 -0
  65. package/src/hooks/useStore/index.js +5 -1
  66. package/src/hooks/useStore/queries.js +71 -72
  67. package/src/hooks/useTagProducts/index.ts +3 -0
  68. package/src/hooks/useTagProducts/useDeleteOneTag.ts +106 -0
  69. package/src/hooks/useTagProducts/useGetAllTags.ts +68 -0
  70. package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +156 -0
  71. package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
  72. package/src/hooks/useUpdateExistingOrders/index.js +3 -9
  73. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +25 -3
  74. package/src/hooks/useUpdateMultipleExtProduct/index.js +33 -0
  75. package/src/hooks/useUpdateMultipleExtProduct/queries.js +33 -0
  76. package/src/hooks/useUploadProducts/index.js +0 -1
  77. package/src/hooks/useUser/queries.js +0 -1
  78. package/src/utils/index.js +97 -5
  79. package/tsconfig.json +5 -0
  80. package/src/hooks/useUpdateMultipleExtProductFoods/index.js +0 -21
  81. package/src/hooks/useUpdateMultipleExtProductFoods/queries.js +0 -19
@@ -1,75 +1,3 @@
1
- import { useQuery } from '@apollo/client'
2
- import { GET_ALL_PEDIDOS, GET_ALL_PEDIDOS_FROM_STORE } from './queries'
3
-
4
- export const useOrders = ({
5
- refetchWritePolicy = 'merge',
6
- refetchReadPolicy,
7
- refetch,
8
- statusOrder,
9
- fromDate,
10
- toDate,
11
- nextFetchPolicy = 'cache-first',
12
- fetchPolicy = 'cache-and-network',
13
- pollInterval = 60000,
14
- onError
15
- }) => {
16
- const { data, loading, error, fetchMore } = useQuery(GET_ALL_PEDIDOS, {
17
- notifyOnNetworkStatusChange: true,
18
- refetchWritePolicy,
19
- pollInterval,
20
- fetchPolicy,
21
- refetch,
22
- refetchReadPolicy,
23
- nextFetchPolicy,
24
- onError: onError || (() => {
25
-
26
- }),
27
- variables: {
28
- statusOrder,
29
- fromDate,
30
- toDate
31
- }
32
- })
33
-
34
- return [
35
- data?.getAllPedidoStoreFinal,
36
- { loading, error, data, fetchMore }
37
- ]
38
- }
39
-
40
- export const useOrdersFromStore = ({
41
- idStore,
42
- cId,
43
- dId,
44
- ctId,
45
- search = '',
46
- min,
47
- fromDate,
48
- toDate,
49
- max,
50
- statusOrder
51
- }) => {
52
- const {
53
- data,
54
- loading,
55
- error,
56
- called
57
- } = useQuery(GET_ALL_PEDIDOS_FROM_STORE, {
58
- variables: {
59
- idStore,
60
- cId,
61
- dId,
62
- ctId,
63
- search,
64
- min,
65
- fromDate,
66
- toDate,
67
- max,
68
- statusOrder
69
- }
70
- })
71
-
72
- return [data?.getAllOrdersFromStore || [], { loading: called ? false : loading, error }]
73
- }
74
-
75
1
  export * from './queries'
2
+ export * from './useChangeOrderState'
3
+ export * from './useOrdersFromStore'
@@ -1,17 +1,17 @@
1
1
  import { gql } from '@apollo/client'
2
2
 
3
- export const CHANGE_STATE_STORE_PEDIDO = gql`
4
- mutation changePPStatePPedido($pPStateP: Int, $pCodeRef: String, $pDatMod: String) {
5
- changePPStatePPedido(pPStateP: $pPStateP, pCodeRef: $pCodeRef, pDatMod: $pDatMod){
3
+ export const CHANGE_STATE_STORE_ORDER = gql`
4
+ mutation changePPStateOrder($pPStateP: Int, $pCodeRef: String, $pDatMod: String) {
5
+ changePPStateOrder(pPStateP: $pPStateP, pCodeRef: $pCodeRef, pDatMod: $pDatMod){
6
6
  success
7
7
  message
8
8
  }
9
9
  }
10
10
 
11
11
  `
12
- export const GET_ALL_PEDIDOS = gql`
13
- query getAllPedidoStoreFinal($idStore: ID, $search: String, $min: Int, $max: Int, $statusOrder: Int, $fromDate: DateTime, $toDate: DateTime) {
14
- getAllPedidoStoreFinal(idStore: $idStore, search: $search, min: $min, max: $max, statusOrder: $statusOrder, toDate: $toDate,fromDate: $fromDate ) {
12
+ export const GET_ALL_ORDER = gql`
13
+ query getAllOrderStoreFinal($idStore: ID, $search: String, $min: Int, $max: Int, $statusOrder: Int, $fromDate: DateTime, $toDate: DateTime) {
14
+ getAllOrderStoreFinal(idStore: $idStore, search: $search, min: $min, max: $max, statusOrder: $statusOrder, toDate: $toDate,fromDate: $fromDate ) {
15
15
  pdpId
16
16
  idStore
17
17
  pCodeRef
@@ -86,101 +86,21 @@ query getAllOrdersFromStore(
86
86
  max: $max
87
87
  statusOrder: $statusOrder
88
88
  ) {
89
- ACCEPT {
90
- pdpId
91
- idStore
92
- pCodeRef
93
- payMethodPState
94
- pPRecoger
95
- totalProductsPrice
96
- pSState
97
- pDatCre
98
- channel
99
- locationUser
100
- pDatMod
101
- getAllPedidoStore {
102
- pdpId
103
- pId
104
- idStore
105
- ShoppingCard
106
- pCodeRef
107
- pPStateP
108
- payMethodPState
109
- pPRecoger
110
- pDatCre
111
- pDatMod
112
- getAllShoppingCard {
113
- ShoppingCard
114
- comments
115
- cantProducts
116
- pId
117
- productFood {
118
- pId
119
- carProId
120
- colorId
121
- idStore
122
- pName
123
- ProPrice
124
- ProDescuento
125
- ProDescription
126
- ValueDelivery
127
- ProImage
128
- ProStar
129
- pState
130
- pDatCre
131
- pDatMod
132
- }
133
- }
134
- }
135
- }
136
- PROCESSING {
137
- pdpId
138
- idStore
139
- pCodeRef
140
- payMethodPState
141
- pPRecoger
142
- totalProductsPrice
143
- pSState
144
- pDatCre
145
- channel
146
- locationUser
147
- pDatMod
148
- getAllPedidoStore {
149
- pdpId
150
- pId
151
- idStore
152
- ShoppingCard
153
- pCodeRef
154
- pPStateP
155
- payMethodPState
156
- pPRecoger
157
- pDatCre
158
- pDatMod
159
- getAllShoppingCard {
160
- ShoppingCard
161
- comments
162
- cantProducts
163
- pId
164
- productFood {
165
- pId
166
- carProId
167
- colorId
168
- idStore
169
- pName
170
- ProPrice
171
- ProDescuento
172
- ProDescription
173
- ValueDelivery
174
- ProImage
175
- ProStar
176
- pState
177
- pDatCre
178
- pDatMod
179
- }
180
- }
181
- }
89
+ statusKey
90
+ priority
91
+ state
92
+ getStatusOrderType {
93
+ idStatus
94
+ backgroundColor
95
+ name
96
+ description
97
+ color
98
+ priority
99
+ state
100
+ createdAt
101
+ updatedAt
182
102
  }
183
- READY {
103
+ items {
184
104
  pdpId
185
105
  idStore
186
106
  pCodeRef
@@ -192,101 +112,18 @@ query getAllOrdersFromStore(
192
112
  channel
193
113
  locationUser
194
114
  pDatMod
195
- getAllPedidoStore {
196
- pdpId
197
- pId
198
- idStore
199
- ShoppingCard
200
- pCodeRef
201
- pPStateP
202
- payMethodPState
203
- pPRecoger
204
- pDatCre
205
- pDatMod
206
- getAllShoppingCard {
207
- ShoppingCard
208
- comments
209
- cantProducts
210
- pId
211
- productFood {
212
- pId
213
- carProId
214
- colorId
215
- idStore
216
- pName
217
- ProPrice
218
- ProDescuento
219
- ProDescription
220
- ValueDelivery
221
- ProImage
222
- ProStar
223
- pState
224
- pDatCre
225
- pDatMod
226
- }
227
- }
115
+ getStatusOrderType {
116
+ idStatus
117
+ name
118
+ description
119
+ backgroundColor
120
+ color
121
+ priority
122
+ state
123
+ createdAt
124
+ updatedAt
228
125
  }
229
- }
230
- CONCLUDES {
231
- pdpId
232
- idStore
233
- pCodeRef
234
- payMethodPState
235
- pPRecoger
236
- totalProductsPrice
237
- pSState
238
- pDatCre
239
- channel
240
- locationUser
241
- pDatMod
242
- getAllPedidoStore {
243
- pdpId
244
- pId
245
- idStore
246
- ShoppingCard
247
- pCodeRef
248
- pPStateP
249
- payMethodPState
250
- pPRecoger
251
- pDatCre
252
- pDatMod
253
- getAllShoppingCard {
254
- ShoppingCard
255
- comments
256
- cantProducts
257
- pId
258
- productFood {
259
- pId
260
- carProId
261
- colorId
262
- idStore
263
- pName
264
- ProPrice
265
- ProDescuento
266
- ProDescription
267
- ValueDelivery
268
- ProImage
269
- ProStar
270
- pState
271
- pDatCre
272
- pDatMod
273
- }
274
- }
275
- }
276
- }
277
- REJECTED {
278
- pdpId
279
- idStore
280
- pCodeRef
281
- payMethodPState
282
- pPRecoger
283
- totalProductsPrice
284
- pSState
285
- pDatCre
286
- channel
287
- locationUser
288
- pDatMod
289
- getAllPedidoStore {
126
+ getStoreOrders {
290
127
  pdpId
291
128
  pId
292
129
  idStore
@@ -324,5 +161,4 @@ query getAllOrdersFromStore(
324
161
  }
325
162
  }
326
163
 
327
-
328
164
  `
@@ -0,0 +1,125 @@
1
+ import { gql, useApolloClient, useMutation } from '@apollo/client'
2
+ import { SendNotificationFn } from '../../useImageUploaderProduct'
3
+ import { updateExistingOrders } from '../../useUpdateExistingOrders'
4
+ /**
5
+ * GraphQL mutation to change the state of a store order (pedido).
6
+ */
7
+ const CHANGE_STATE_STORE_ORDER = gql`
8
+ mutation changePPStateOrder($idStatus: ID, $pCodeRef: String, $pDatMod: String) {
9
+ changePPStateOrder(idStatus: $idStatus, pCodeRef: $pCodeRef, pDatMod: $pDatMod) {
10
+ success
11
+ message
12
+ errors {
13
+ path
14
+ message
15
+ type
16
+ }
17
+ data {
18
+ pdpId
19
+ id
20
+ idStore
21
+ pPStateP
22
+ pSState
23
+
24
+ ppState
25
+ pCodeRef
26
+ }
27
+ }
28
+ }
29
+ `
30
+
31
+ interface IUseChangeStateOrder {
32
+ sendNotification: SendNotificationFn
33
+ }
34
+ /**
35
+ * Hook to trigger the `changePPStateOrder` mutation.
36
+ * @returns {Object} Contains the mutation function, loading and error state.
37
+ */
38
+ export const useChangeStateOrder = ({
39
+ sendNotification
40
+ }: IUseChangeStateOrder) => {
41
+ const client = useApolloClient()
42
+
43
+ const [changeState, { loading, error, data }] = useMutation(CHANGE_STATE_STORE_ORDER, {
44
+ onCompleted: (res) => {
45
+ if (!res || !res.changePPStateOrder) {
46
+ return
47
+ }
48
+ const { success, data } = res?.changePPStateOrder || {}
49
+ if (success) {
50
+ const { pCodeRef, pSState } = data ?? {
51
+ pCodeRef: null,
52
+ pSState: null
53
+ }
54
+ if (!pCodeRef || !pSState) {
55
+ return
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
+ })
69
+ }
70
+ }
71
+ })
72
+
73
+ /**
74
+ * Triggers the mutation to update the pedido state.
75
+ * @param {Object} params
76
+ * @param {number} params.idStatus - New state of the pedido (required).
77
+ * @param {string} params.pCodeRef - Reference code for the pedido (required).
78
+ * @param {string} params.pDatMod - Modification date in ISO format (required).
79
+ * @returns {Promise<Object>} Response from the mutation.
80
+ */
81
+ const changeStateOrder = async ({
82
+ idStatus,
83
+ pCodeRef,
84
+ pDatMod,
85
+ }: {
86
+ idStatus: string
87
+ pCodeRef: string
88
+ pDatMod: string
89
+ }) => {
90
+ try {
91
+ const response = await changeState({
92
+ variables:
93
+ {
94
+ idStatus,
95
+ pCodeRef,
96
+ pDatMod
97
+ },
98
+ })
99
+ const { success, message } = response?.data?.changePPStateOrder ?? {
100
+ success: false,
101
+ message: ''
102
+ }
103
+ sendNotification({
104
+ title: success ? 'Exitoso' : 'Error',
105
+ description: message,
106
+ backgroundColor: success ? 'success' : 'error'
107
+ })
108
+ return response?.data?.changePPStateOrder ?? {
109
+ success: false,
110
+ message,
111
+ }
112
+ } catch (err) {
113
+ return {
114
+ success: false,
115
+ message: err.message || 'Unexpected error occurred',
116
+ }
117
+ }
118
+ }
119
+
120
+ return [changeStateOrder, {
121
+ loading,
122
+ error,
123
+ data,
124
+ }]
125
+ }
@@ -0,0 +1,83 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_ORDER, GET_ALL_PEDIDOS_FROM_STORE } from '../queries.js'
3
+
4
+ export const useOrders = ({
5
+ refetchWritePolicy = 'merge',
6
+ refetchReadPolicy,
7
+ refetch,
8
+ statusOrder,
9
+ fromDate,
10
+ toDate,
11
+ nextFetchPolicy = 'cache-first',
12
+ fetchPolicy = 'cache-and-network',
13
+ pollInterval = 60000,
14
+ onError
15
+ }) => {
16
+ const { data, loading, error, fetchMore } = useQuery(GET_ALL_ORDER, {
17
+ notifyOnNetworkStatusChange: true,
18
+ refetchWritePolicy,
19
+ pollInterval,
20
+ fetchPolicy,
21
+ refetch,
22
+ refetchReadPolicy,
23
+ nextFetchPolicy,
24
+ onError: onError || (() => {
25
+
26
+ }),
27
+ variables: {
28
+ statusOrder,
29
+ fromDate,
30
+ toDate
31
+ }
32
+ })
33
+
34
+ return [
35
+ data?.getAllOrderStoreFinal,
36
+ { loading, error, data, fetchMore }
37
+ ]
38
+ }
39
+
40
+ export const useOrdersFromStore = ({
41
+ idStore,
42
+ cId,
43
+ dId,
44
+ ctId,
45
+ search = '',
46
+ min,
47
+ fromDate,
48
+ toDate,
49
+ max,
50
+ statusOrder,
51
+ callback = () => {
52
+
53
+ }
54
+ }) => {
55
+ const {
56
+ data,
57
+ loading,
58
+ refetch,
59
+ error,
60
+ called
61
+ } = useQuery(GET_ALL_PEDIDOS_FROM_STORE, {
62
+ onCompleted: (data) => {
63
+ if (typeof callback === 'function') {
64
+ callback(data)
65
+ }
66
+ },
67
+ variables: {
68
+ idStore,
69
+ cId,
70
+ dId,
71
+ ctId,
72
+ search,
73
+ min,
74
+ fromDate,
75
+ toDate,
76
+ max,
77
+ statusOrder
78
+ }
79
+ })
80
+
81
+ return [data?.getAllOrdersFromStore || [], { refetch, loading: called ? false : loading, error }]
82
+ }
83
+
@@ -0,0 +1,33 @@
1
+ import { useEffect, useState } from 'react'
2
+
3
+ /**
4
+ * Custom hook to fetch a free port from the API route `/api/port`.
5
+ *
6
+ * @returns {Object} Object containing the fetched port and loading/error states
7
+ */
8
+ export const usePortFetcher = () => {
9
+ const [port, setPort] = useState<string | null>(null)
10
+ const [loading, setLoading] = useState(true)
11
+ const [error, setError] = useState<string | null>(null)
12
+
13
+ useEffect(() => {
14
+ const fetchPort = async () => {
15
+ try {
16
+ const res = await fetch('/api/port')
17
+ if (!res.ok) throw new Error('Failed to fetch port')
18
+
19
+ const data = await res.json()
20
+ setPort(data.port)
21
+ } catch (err: any) {
22
+ console.error('Error fetching port:', err)
23
+ setError(err.message || 'Unknown error')
24
+ } finally {
25
+ setLoading(false)
26
+ }
27
+ }
28
+
29
+ fetchPort()
30
+ }, [])
31
+
32
+ return { port, loading, error }
33
+ }
@@ -37,13 +37,13 @@ export const useProductsFood = ({
37
37
  variables: {
38
38
  categories,
39
39
  desc,
40
- fromDate,
40
+ // fromDate,
41
41
  gender,
42
42
  max,
43
43
  min,
44
44
  pState,
45
- search,
46
- toDate
45
+ search
46
+ // toDate
47
47
  }
48
48
  })
49
49