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
@@ -6,7 +6,7 @@ import {
6
6
  useState,
7
7
  createRef
8
8
  } from 'react'
9
- import { useUpdateMultipleExtProductFoods } from '../useUpdateMultipleExtProductFoods'
9
+ import { useUpdateMultipleExtProduct } from '../useUpdateMultipleExtProduct'
10
10
  import { useMutation } from '@apollo/client'
11
11
  import { EDIT_EXTRA_PRODUCT_FOODS } from './queries'
12
12
  import { findNumbersExceedingRange, transformData, updateErrorFieldByIndex } from './helpers'
@@ -82,7 +82,10 @@ export const useDessertWithPrice = ({
82
82
  setLine(Array.isArray(dataExtra) && dataExtra.length > 0 ? { Lines: transformedData } : initialLineItems)
83
83
  }, [initialLineItems])
84
84
 
85
- const [updateMultipleExtProductFoods, { loading }] = useUpdateMultipleExtProductFoods({ handleCleanLines: () => { return } })
85
+ const [updateMultipleExtProduct, { loading }] = useUpdateMultipleExtProduct({
86
+ handleCleanLines: () => { },
87
+ sendNotification
88
+ })
86
89
  /**
87
90
  * Handles the addition of two new lines to the Lines array in LineItems state.
88
91
  */
@@ -151,51 +154,82 @@ export const useDessertWithPrice = ({
151
154
  * @param {number} index - Index of the line to be filtered out.
152
155
  */
153
156
  const filterOneLine = (index) => {
154
- // Use optional chaining to safely access nested properties.
157
+ // Use optional chaining to safely access nested properties.
155
158
  const Lines = LineItems?.Lines?.filter((_, i) => { return i !== index })
156
159
  // Use spread operator to create a new object with the filtered Lines array.
157
160
  return setLine({ ...LineItems, Lines })
158
161
  }
162
+
163
+ /**
164
+ * Removes a product extra by index or external product ID.
165
+ *
166
+ * @param {number} i - Index of the item in the list.
167
+ * @param {string} [exPid] - External product ID to remove (optional).
168
+ * @returns {Promise<void>}
169
+ */
159
170
  const handleRemove = async (i, exPid) => {
160
171
  try {
161
- if (exPid) {
162
- const findDataExtra = dataExtra?.find(x => { return x?.exPid === exPid })
163
- if (findDataExtra) {
164
- const data = await deleteExtraProductFoods({
165
- variables: {
166
- state: 1,
167
- id: exPid
168
- },
169
- update: (cache) => {
170
- cache.modify({
171
- fields: {
172
- ExtProductFoodsAll: (dataOld = []) => {
173
- const { success } = data?.data?.deleteextraproductfoods || {}
174
- if (success && Array.isArray(dataOld)) {
175
- const transformedData = transformData(dataOld)
176
- const Lines = transformedData.filter((_, index) => { return index !== i })
177
- const newCache = dataOld.filter((_, index) => { return index !== i })
178
- setLine({ ...LineItems, Lines })
179
- return newCache
180
- }
181
- }
182
- }
183
- })
184
- }
185
- })
186
- }
187
- }
188
172
  if (!exPid) {
189
173
  return filterOneLine(i)
190
174
  }
175
+
176
+ const findDataExtra = dataExtra?.find(x => x?.exPid === exPid)
177
+ if (!findDataExtra) return
178
+
179
+ await deleteExtraProductFoods({
180
+ variables: {
181
+ state: 1,
182
+ id: exPid
183
+ },
184
+ update: (cache, { data }) => {
185
+ const res = data?.deleteExtraProduct
186
+ const success = res?.success
187
+ const message = res?.message || ''
188
+
189
+ if (!success) {
190
+ return sendNotification({
191
+ title: 'Error',
192
+ description: message,
193
+ backgroundColor: 'error'
194
+ })
195
+ }
196
+
197
+ sendNotification({
198
+ title: 'Producto eliminado',
199
+ description: message,
200
+ backgroundColor: 'success'
201
+ })
202
+
203
+ cache.modify({
204
+ fields: {
205
+ ExtProductFoodsAll: (dataOld = []) => {
206
+ if (!Array.isArray(dataOld)) return dataOld
207
+
208
+ const transformedData = transformData(dataOld)
209
+ const Lines = transformedData.filter((_, index) => index !== i)
210
+ const newCache = dataOld.filter((_, index) => index !== i)
211
+
212
+ setLine(prev => ({
213
+ ...prev,
214
+ Lines
215
+ }))
216
+
217
+ return newCache
218
+ }
219
+ }
220
+ })
221
+ }
222
+ })
191
223
  } catch (error) {
224
+ console.log('🚀 ~ handleRemove ~ error:', error)
192
225
  sendNotification({
193
- title: 'error',
194
- description: 'Ocurrió un error',
226
+ title: 'Error',
227
+ description: 'Ocurrió un error al eliminar el producto',
195
228
  backgroundColor: 'error'
196
229
  })
197
230
  }
198
231
  }
232
+
199
233
  useEffect(() => {
200
234
  setLine(Array.isArray(dataExtra) && dataExtra.length > 0 ? { Lines: transformedData } : initialLineItems)
201
235
  }, [dataExtra.length])
@@ -219,36 +253,11 @@ export const useDessertWithPrice = ({
219
253
  return dataArr
220
254
  }, [LineItems])
221
255
 
222
- /**
223
- * Convierte un string con números y puntos en un número entero.
224
- * @param {string} str - El string a convertir.
225
- * @returns {number} El número entero resultante.
226
- */
227
- function stringToInt (str) {
228
- try {
229
- // Verifica si el string es válido
230
- if (!str || typeof str !== 'string') {
231
- throw new Error('Input must be a valid string.')
232
- }
233
-
234
- // Elimina los puntos y convierte a número
235
- const num = parseInt(str.replace(/\./g, ''), 10)
236
-
237
- // Verifica si el resultado es un número válido
238
- if (isNaN(num)) {
239
- throw new Error('The string must contain only numbers and dots.')
240
- }
241
-
242
- return num
243
- } catch (_error) {
244
- return 0
245
- }
246
- }
247
256
  const handleEdit = async (i, exPid) => {
248
257
  setSelected({ exPid: null, loading: true })
249
258
  const findOneExtra = LineItems?.Lines?.find((x, i) => { return x?.exPid === exPid })
250
259
  const { extraName, extraPrice: price } = findOneExtra || {}
251
- const extraPrice = stringToInt(price)
260
+ const extraPrice = price
252
261
  const { data } = await editExtraProductFoods({
253
262
  variables: {
254
263
  exPid,
@@ -281,6 +290,7 @@ export const useDessertWithPrice = ({
281
290
  })
282
291
  }
283
292
  }
293
+
284
294
  function filterItemsWithValidExPid (items, pId) {
285
295
  // Primero, filtrar los elementos basados en exPid
286
296
  const filteredItems = items.filter(({ exPid }) => {
@@ -308,7 +318,7 @@ export const useDessertWithPrice = ({
308
318
 
309
319
  if (!prepareAndValidateData(pId)) return
310
320
  const dataArr = LineItems?.Lines?.map(x => {
311
- const extraPrice = stringToInt(x.extraPrice)
321
+ const extraPrice = x.extraPrice
312
322
  const extraName = x.extraName
313
323
  return {
314
324
  extraPrice,
@@ -319,7 +329,7 @@ export const useDessertWithPrice = ({
319
329
  })
320
330
  const filteredItems = filterItemsWithValidExPid(LineItems?.Lines, pId)
321
331
 
322
- return updateMultipleExtProductFoods({
332
+ return updateMultipleExtProduct({
323
333
  variables: {
324
334
  inputLineItems: {
325
335
  setData: filteredItems
@@ -1,8 +1,8 @@
1
1
  import { gql } from '@apollo/client'
2
2
 
3
3
  export const DELETE_EXTRA_PRODUCTS = gql`
4
- mutation deleteextraproductfoods($id: ID, $state: Int){
5
- deleteextraproductfoods(id: $id, state: $state){
4
+ mutation deleteExtraProduct($id: ID, $state: Int){
5
+ deleteExtraProduct(id: $id, state: $state){
6
6
  success,
7
7
  message
8
8
  }
@@ -1,19 +1,28 @@
1
1
  import { gql } from '@apollo/client'
2
2
 
3
+ /**
4
+ * Query to fetch all device users with extended fields
5
+ */
3
6
  export const GET_ALL_DEVICES = gql`
4
- query getDeviceUsers {
5
- getDeviceUsers {
7
+ query getDeviceUsers {
8
+ getDeviceUsers {
6
9
  dId
7
- locationFormat
10
+ id
8
11
  deviceId
9
12
  deviceName
13
+ locationFormat
10
14
  type
11
- short_name
15
+ shortName
12
16
  platform
13
17
  version
18
+ family
19
+ os
20
+ model
21
+ ip
22
+ isBot
14
23
  dState
15
- DatCre
16
- DatMod
24
+ createdAt
25
+ updatedAt
26
+ }
17
27
  }
18
- }
19
28
  `
@@ -1,4 +1,3 @@
1
- import { useState, useEffect } from 'react'
2
1
  import { useQuery } from '@apollo/client'
3
2
  import { GET_ALL_DEVICES } from './queries'
4
3
  import { useFormatDate } from '../useFormatDate'
@@ -9,27 +8,21 @@ export const useDevices = () => {
9
8
  console.error(error)
10
9
  }
11
10
  })
12
- const [deviceId, setDeviceId] = useState(false)
13
- const [date, setDate] = useState('')
14
-
15
- useEffect(() => {
16
- if (window) {
17
- setDeviceId(window.localStorage.getItem('deviceid'))
18
- }
19
- }, [])
20
11
 
21
12
  // Función para formatear la fecha
22
- const formatDate = useFormatDate({ date })
13
+ const { formatDateInTimeZone } = useFormatDate({})
23
14
 
24
- const updateDate = (newDate) => {
25
- setDate(newDate)
26
- }
15
+ const listDevices = Array.isArray(data?.getDeviceUsers)
16
+ ? data?.getDeviceUsers.map((device) => {
17
+ // const formattedDate = formatDateInTimeZone(device.createdAt)
18
+ return {
19
+ ...device
20
+ // createdAt: formattedDate
21
+ }
22
+ })
23
+ : []
27
24
  return {
28
- data: data?.getDeviceUsers || [],
29
- date,
30
- deviceId,
31
- formatDate,
32
- loading,
33
- updateDate
25
+ data: listDevices,
26
+ loading
34
27
  }
35
28
  }
@@ -15,12 +15,12 @@ const REGISTER_DEVICE_USER = gql`
15
15
  deviceName
16
16
  locationFormat
17
17
  type
18
- short_name
18
+ shortName
19
19
  platform
20
20
  version
21
21
  dState
22
- DatCre
23
- DatMod
22
+ createdAt
23
+ dState
24
24
  }
25
25
  errors {
26
26
  path
@@ -0,0 +1,21 @@
1
+ export const downloadFileFromResponse = async (response, fileName) => {
2
+ try {
3
+ if (!response.ok) {
4
+ throw new Error(`Failed to download file: ${response.statusText}`)
5
+ }
6
+
7
+ const blob = await response.blob()
8
+ const url = window.URL.createObjectURL(blob)
9
+ const link = document.createElement('a')
10
+ link.href = url
11
+ link.setAttribute('download', fileName)
12
+ document.body.appendChild(link)
13
+ link.click()
14
+ document.body.removeChild(link)
15
+ window.URL.revokeObjectURL(url)
16
+ } catch (error) {
17
+ console.error('Error downloading file:', error)
18
+ throw error
19
+ }
20
+
21
+ }
@@ -0,0 +1,2 @@
1
+ export * from './useDownloadReportByDay'
2
+ export * from './useGetReportByDateRange'
@@ -0,0 +1,103 @@
1
+ import { useLazyQuery } from '@apollo/client'
2
+ import { gql } from '@apollo/client'
3
+ import { useState } from 'react'
4
+ import { downloadFileFromResponse } from '../helpers/downloadFileFromResponse'
5
+
6
+
7
+
8
+ /**
9
+ * GraphQL query to get the report for a specific day.
10
+ */
11
+ const GET_REPORT_DAY_NUMBER = gql`
12
+ query getReportDayNumber($day: Int!) {
13
+ getReportDayNumber(day: $day) {
14
+ success
15
+ message
16
+ errors {
17
+ path
18
+ message
19
+ type
20
+ }
21
+ data {
22
+ id
23
+ name
24
+ description
25
+ url
26
+ createdAt
27
+ }
28
+ }
29
+ }
30
+ `
31
+
32
+ /**
33
+ * Custom hook to trigger the report download when the GraphQL query resolves.
34
+ *
35
+ * @returns {{
36
+ * downloadReport: (day: number) => void,
37
+ * loading: boolean,
38
+ * error: Error | undefined
39
+ * }} Object containing the trigger function, loading state and error.
40
+ */
41
+ export const useDownloadReportByDay = ({
42
+ sendNotification = (
43
+ { description = '', title = '', backgroundColor = 'info' } = {}
44
+ ) => {
45
+ return {
46
+ description,
47
+ title,
48
+ backgroundColor
49
+ }
50
+ }
51
+ } = {}) => {
52
+ const [finished, setFinished] = useState(false)
53
+ const [fetchReport, { loading, error }] = useLazyQuery(GET_REPORT_DAY_NUMBER, {
54
+ fetchPolicy: 'network-only',
55
+ onCompleted: async ({ getReportDayNumber }) => {
56
+ setFinished(false)
57
+ try {
58
+ const {
59
+ success,
60
+ data,
61
+ message
62
+ } = getReportDayNumber || {}
63
+ if (!success || !data) {
64
+ setFinished(true)
65
+ return sendNotification({
66
+ description: message,
67
+ title: 'Error al descargar reporte',
68
+ backgroundColor: 'error'
69
+ })
70
+ }
71
+ const { url = '', name = '' } = data
72
+ const response = await fetch(`/api/files/${encodeURIComponent(url)}`)
73
+ await downloadFileFromResponse(response, name)
74
+ setFinished(true)
75
+ return sendNotification({
76
+ description: message ?? 'Reporte descargado exitosamente',
77
+ title: 'Reporte descargado',
78
+ backgroundColor: 'success'
79
+ })
80
+ } catch (e) {
81
+ setFinished(false)
82
+ }
83
+ },
84
+ onError: () => {
85
+ setFinished(true)
86
+ }
87
+ })
88
+
89
+ /**
90
+ * Triggers the report download process.
91
+ * @param {number} day - The report day number to fetch.
92
+ */
93
+ const downloadReport = (day: number) => {
94
+ setFinished(false)
95
+ if (!day || typeof day !== 'number') {
96
+ console.warn('Invalid day for report download')
97
+ return
98
+ }
99
+ fetchReport({ variables: { day } })
100
+ }
101
+
102
+ return [downloadReport, { loading, error, finished }] as const
103
+ }
@@ -0,0 +1,115 @@
1
+ import { useLazyQuery } from '@apollo/client'
2
+ import { gql } from '@apollo/client'
3
+ import { downloadFileFromResponse } from '../helpers/downloadFileFromResponse'
4
+ import { useState } from 'react'
5
+
6
+ /**
7
+ * GraphQL query to get report by date range
8
+ */
9
+ const GET_REPORT_BY_DATE_RANGE = gql`
10
+ query getReportByDateRange($startDate: DateTime!, $endDate: DateTime!) {
11
+ getReportBydateRange(startDate: $startDate, endDate: $endDate) {
12
+ success
13
+ message
14
+ errors {
15
+ path
16
+ message
17
+ type
18
+ }
19
+ data {
20
+ id
21
+ name
22
+ description
23
+ url
24
+ createdAt
25
+ }
26
+ }
27
+ }
28
+ `
29
+
30
+ /**
31
+ * Custom hook to fetch report by a date range
32
+ * @param {Object} options
33
+ * @param {Function} options.sendNotification - Function to notify user
34
+ * @returns {[Function, { loading: boolean, error: any, data: any }]}
35
+ */
36
+ export const useGetReportByDateRange = ({
37
+ sendNotification = ({ description = '', title = '', backgroundColor = 'info' } = {}) => {
38
+ return { description, title, backgroundColor }
39
+ }
40
+ } = {}) => {
41
+ const [loading, setLoading] = useState(false)
42
+ const [finished, setFinished] = useState(false)
43
+
44
+ const [getReportQuery, { data, error }] = useLazyQuery(GET_REPORT_BY_DATE_RANGE, {
45
+ onCompleted: () => {
46
+ setFinished(true)
47
+ }
48
+ })
49
+
50
+ /**
51
+ * Triggers the report generation and handles download
52
+ * @param {string} startDate - Start date in YYYY-MM-DD format
53
+ * @param {string} endDate - End date in YYYY-MM-DD format
54
+ * @returns {Promise<any>}
55
+ */
56
+ const getReport = async (startDate, endDate) => {
57
+ try {
58
+ setLoading(true)
59
+ const response = await getReportQuery({
60
+ variables: { startDate, endDate },
61
+ fetchPolicy: 'network-only'
62
+ })
63
+
64
+ const reportResult = response?.data?.getReportBydateRange ?? {
65
+ success: false,
66
+ message: 'No report data found',
67
+ data: null
68
+ }
69
+
70
+ if (!reportResult) {
71
+ setLoading(false)
72
+ return {
73
+ success: false,
74
+ message: 'No report data found',
75
+ data: null
76
+ }
77
+ }
78
+
79
+ const {
80
+ success,
81
+ message,
82
+ data
83
+ } = reportResult
84
+
85
+ sendNotification({
86
+ description: message,
87
+ title: success ? 'Success' : 'Error',
88
+ backgroundColor: success ? 'success' : 'error'
89
+ })
90
+
91
+ if (success && data?.url && data?.name) {
92
+ setLoading(true)
93
+ const res = await fetch(`/api/files/${encodeURIComponent(data.url)}`)
94
+ await downloadFileFromResponse(res, data.name)
95
+ setLoading(false)
96
+ }
97
+ return reportResult
98
+ } catch (err) {
99
+ setLoading(false)
100
+ sendNotification({
101
+ description: err.message || 'Unexpected error',
102
+ title: 'Error',
103
+ backgroundColor: 'error'
104
+ })
105
+ return { success: false, message: err.message, data: null }
106
+ }
107
+ }
108
+
109
+ return [getReport, {
110
+ loading,
111
+ error,
112
+ finished,
113
+ data: data?.getReportBydateRange
114
+ }]
115
+ }
@@ -1,4 +1,4 @@
1
- import { gql, useMutation } from '@apollo/client';
1
+ import { gql, useMutation } from '@apollo/client'
2
2
 
3
3
  const EDIT_CATEGORY_PRODUCT = gql`
4
4
  mutation EditOneCategoryProduct($pName: String!, $ProDescription: String, $carProId: ID!) {
@@ -7,35 +7,35 @@ const EDIT_CATEGORY_PRODUCT = gql`
7
7
  message
8
8
  }
9
9
  }
10
- `;
10
+ `
11
11
 
12
- export const useEditCategoryProduct = ({ sendNotification = () => { return } } = {}) => {
13
- const [editCategoryProductMutation] = useMutation(EDIT_CATEGORY_PRODUCT);
12
+ export const useEditCategoryProduct = ({ sendNotification = () => { } } = {}) => {
13
+ const [editCategoryProductMutation] = useMutation(EDIT_CATEGORY_PRODUCT)
14
14
 
15
15
  const editCategoryProduct = async (pName, ProDescription, carProId) => {
16
16
  try {
17
17
  const { data } = await editCategoryProductMutation({
18
18
  variables: { pName, ProDescription, carProId }
19
- });
19
+ })
20
20
 
21
21
  if (data.editOneCategoryProduct.success) {
22
22
  return {
23
23
  success: true,
24
24
  message: 'Categoría de producto editada correctamente'
25
- };
25
+ }
26
26
  } else {
27
27
  return {
28
28
  success: false,
29
29
  message: data.editOneCategoryProduct.message || 'Error al editar la categoría de producto'
30
- };
30
+ }
31
31
  }
32
32
  } catch (error) {
33
33
  return {
34
34
  success: false,
35
35
  message: error.message || 'Error al editar la categoría de producto'
36
- };
36
+ }
37
37
  }
38
- };
38
+ }
39
39
 
40
40
  return { editCategoryProduct }
41
- };
41
+ }
@@ -10,6 +10,7 @@ import { validationSubmitHooks } from '../../utils'
10
10
  * @return {Array} devuelve la función onChange a ejecutar y el estado de error de cada input
11
11
  */
12
12
  export const useFormTools = ({
13
+ initialValues = {},
13
14
  sendNotification = ({
14
15
  title = '',
15
16
  description = '',
@@ -17,7 +18,7 @@ export const useFormTools = ({
17
18
  }) => { }
18
19
  }
19
20
  = {}) => {
20
- const [dataForm, setDataForm] = useState({})
21
+ const [dataForm, setDataForm] = useState({ ...initialValues })
21
22
  const [errorForm, setErrorForm] = useState({})
22
23
  const [errorSubmit, setErrorSubmit] = useState(false)
23
24
  const [calledSubmit, setCalledSubmit] = useState(false)