npm-pkg-hook 1.3.7 → 1.3.8

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 (95) hide show
  1. package/.eslintrc.js +38 -38
  2. package/.eslintrc.json +127 -127
  3. package/.github/pull_request_template.md +17 -17
  4. package/.github/workflows/pepeline.yaml +29 -29
  5. package/package.json +46 -46
  6. package/script.txt +6 -6
  7. package/src/config/client/index.js +1 -1
  8. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -7
  9. package/src/hooks/getCategoriesWithProduct/index.js +62 -62
  10. package/src/hooks/getSession/index.js +18 -18
  11. package/src/hooks/useAnimationFrame/index.js +45 -45
  12. package/src/hooks/useAsideCart/index.js +155 -155
  13. package/src/hooks/useAsideCart/queries.js +10 -10
  14. package/src/hooks/useCart/index.js +2 -2
  15. package/src/hooks/useCart/queries.js +164 -164
  16. package/src/hooks/useCart/useCart/helpers/index.js +75 -75
  17. package/src/hooks/useCart/useCart/index.js +410 -410
  18. package/src/hooks/useCart/useGetCart/index.js +31 -31
  19. package/src/hooks/useCatWithProductClient/index.js +56 -56
  20. package/src/hooks/useCatWithProductClient/queries.js +55 -55
  21. package/src/hooks/useCategoriesProduct/index.js +12 -12
  22. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  23. package/src/hooks/useCategoryInStore/queries.js +78 -78
  24. package/src/hooks/useChartData/useChartData/index.js +199 -199
  25. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  26. package/src/hooks/useCheckbox/index.js +115 -115
  27. package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/index.js +52 -0
  28. package/src/hooks/useCreateProduct/index.js +8 -3
  29. package/src/hooks/useDeleteSubProductOptional/index.js +30 -30
  30. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  31. package/src/hooks/useDessert/helpers/index.js +51 -51
  32. package/src/hooks/useDevices/index.js +35 -35
  33. package/src/hooks/useDevices/queries.js +19 -19
  34. package/src/hooks/useDropzone/index.js +94 -94
  35. package/src/hooks/useDynamicAuth/index.js +13 -13
  36. package/src/hooks/useDynamicAuth/queries.js +24 -24
  37. package/src/hooks/useEditSubProductOptional/queries.js +10 -10
  38. package/src/hooks/useEvent/index.js +33 -33
  39. package/src/hooks/useFavoriteStores/index.js +19 -19
  40. package/src/hooks/useFavoriteStores/queries.js +47 -47
  41. package/src/hooks/useFetchJson/index.js +25 -25
  42. package/src/hooks/useFingerprintjs/index.js +172 -172
  43. package/src/hooks/useFullScreenMode/index.js +65 -65
  44. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  45. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -14
  46. package/src/hooks/useGetFoodRecomended/index.js +32 -33
  47. package/src/hooks/useGetFoodRecomended/queries.js +47 -47
  48. package/src/hooks/useGetMinPrice/index.js +12 -12
  49. package/src/hooks/useGetMinPrice/queries.js +7 -7
  50. package/src/hooks/useGetOneStoreRating/index.js +40 -40
  51. package/src/hooks/useGetOneStoreRating/queries.js +18 -18
  52. package/src/hooks/useGoogleLogin/index.js +160 -160
  53. package/src/hooks/useGoogleLogin/loadScript.js +15 -15
  54. package/src/hooks/useGoogleLogin/removeScript.js +7 -7
  55. package/src/hooks/useHover/index.js +29 -29
  56. package/src/hooks/useImagesStore/index.js +5 -4
  57. package/src/hooks/useInnerHtml/index.js +39 -39
  58. package/src/hooks/useKeypress/index.js +28 -28
  59. package/src/hooks/useLocationNavigate/index.js +54 -54
  60. package/src/hooks/useLogout/index.js +29 -21
  61. package/src/hooks/useManageQueryParams/index.js +37 -36
  62. package/src/hooks/useMobile/index.js +39 -39
  63. package/src/hooks/useOrderClient/index.js +5 -5
  64. package/src/hooks/useProviders/index.js +3 -3
  65. package/src/hooks/useProviders/queries.js +31 -31
  66. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -12
  67. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  68. package/src/hooks/useProvidersStore/index.js +24 -24
  69. package/src/hooks/useProvidersStore/queries.js +31 -31
  70. package/src/hooks/useRatingArrayData/index.js +54 -54
  71. package/src/hooks/useRatingArrayData/queries.js +19 -19
  72. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  73. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  74. package/src/hooks/useRestaurant/index.js +19 -19
  75. package/src/hooks/useRestaurant/queries.js +80 -80
  76. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  77. package/src/hooks/useSchedule/index.js +72 -72
  78. package/src/hooks/useSchedule/index.jsx +22 -22
  79. package/src/hooks/useSchedule/queries.js +43 -43
  80. package/src/hooks/useScheduleData/index.js +123 -123
  81. package/src/hooks/useScroll/index.js +56 -56
  82. package/src/hooks/useScrollRotate/index.js +16 -16
  83. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -101
  84. package/src/hooks/useStatusOpenStore/index.js +172 -172
  85. package/src/hooks/useStatusOrdersClient/queries.js +80 -80
  86. package/src/hooks/useStore/queries.js +163 -163
  87. package/src/hooks/useStoreCalendar/index.js +5 -5
  88. package/src/hooks/useStoreContacts/queries.js +1 -1
  89. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  90. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -38
  91. package/src/hooks/useWindowSize/index.js +38 -38
  92. package/src/mock/dessert/index.js +16 -16
  93. package/src/mock/index.js +1 -1
  94. package/.vscode/extensions.json +0 -6
  95. package/.vscode/settings.json +0 -8
@@ -1,115 +1,115 @@
1
- import { useCallback, useState } from 'react'
2
-
3
- /**
4
- * Hook for managing multiple checkbox states
5
- *
6
- * @param {Array<String | Number>} elem - list of all elem
7
- * @param {Array<String | Number>} selectedIds - list of selected elem (optional)
8
- *
9
- * @returns {Object}
10
- * - checkboxStates (state object),
11
- * - numSelectedItems (number),
12
- * - handleChangeCheck (callback),
13
- * - toggleAll (callback),
14
- * - selectAll (callback),
15
- * - clearAll (callback)
16
- */
17
-
18
- export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], setArray = () => { return }) => {
19
- const numTotalItems = elem?.length
20
- const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
21
- const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
22
-
23
- const handleChangeCheck = useCallback((event, id) => {
24
- const target = event.target
25
- setCheckedItems(prevState => {
26
- const newState = new Set(prevState)
27
- if (target.checked) {
28
- newState.add(id)
29
- } else {
30
- newState.delete(id)
31
- }
32
- return newState
33
- })
34
- }, [])
35
-
36
- const setAll = useCallback(
37
- isChecked => {
38
- setCheckedItems(prevState => {
39
- const newState = new Set(prevState)
40
- for (const id of elem) {
41
- if (disabledItems.has(id)) {
42
- continue
43
- }
44
- if (isChecked) {
45
- newState.add(id)
46
- } else {
47
- newState.delete(id)
48
- }
49
- }
50
- return newState
51
- })
52
- },
53
- [elem, disabledItems]
54
- )
55
-
56
- const selectAll = useCallback(() => {
57
- if (checkedItems.size === numTotalItems) {
58
- return
59
- }
60
- setAll(true)
61
- }, [checkedItems, numTotalItems, setAll])
62
-
63
- const clearAll = useCallback(() => {
64
- if (checkedItems.size === 0) {
65
- return
66
- }
67
- setAll(false)
68
- }, [checkedItems, setAll])
69
-
70
- const toggleAll = useCallback(() => {
71
- const numDisabledAndChecked = [...disabledItems].reduce((count, id) => {
72
- if (checkedItems.has(id)) {
73
- return count + 1
74
- }
75
- return count
76
- }, 0)
77
- if (checkedItems.size - numDisabledAndChecked === 0) {
78
- selectAll()
79
- } else {
80
- clearAll()
81
- }
82
- }, [checkedItems, disabledItems, selectAll, clearAll])
83
-
84
- const enableCheckboxes = useCallback((...elem) => {
85
- setDisabledItems(prevState => {
86
- const newState = new Set(prevState)
87
- for (const id of elem) {
88
- newState.delete(id)
89
- }
90
- return newState
91
- })
92
- }, [])
93
-
94
- const disableCheckboxes = useCallback((...elem) => {
95
- setDisabledItems(prevState => {
96
- const newState = new Set(prevState)
97
- for (const id of elem) {
98
- newState.add(id)
99
- }
100
- return newState
101
- })
102
- }, [])
103
-
104
- return {
105
- checkedItems,
106
- disabledItems,
107
- handleChangeCheck,
108
- toggleAll,
109
- selectAll,
110
- clearAll,
111
- setCheckedItems,
112
- enableCheckboxes,
113
- disableCheckboxes
114
- }
115
- }
1
+ import { useCallback, useState } from 'react'
2
+
3
+ /**
4
+ * Hook for managing multiple checkbox states
5
+ *
6
+ * @param {Array<String | Number>} elem - list of all elem
7
+ * @param {Array<String | Number>} selectedIds - list of selected elem (optional)
8
+ *
9
+ * @returns {Object}
10
+ * - checkboxStates (state object),
11
+ * - numSelectedItems (number),
12
+ * - handleChangeCheck (callback),
13
+ * - toggleAll (callback),
14
+ * - selectAll (callback),
15
+ * - clearAll (callback)
16
+ */
17
+
18
+ export const useCheckboxState = (elem, selectedIds = [], disabledIds = [], setArray = () => { return }) => {
19
+ const numTotalItems = elem?.length
20
+ const [checkedItems, setCheckedItems] = useState(new Set(selectedIds))
21
+ const [disabledItems, setDisabledItems] = useState(new Set(disabledIds))
22
+
23
+ const handleChangeCheck = useCallback((event, id) => {
24
+ const target = event.target
25
+ setCheckedItems(prevState => {
26
+ const newState = new Set(prevState)
27
+ if (target.checked) {
28
+ newState.add(id)
29
+ } else {
30
+ newState.delete(id)
31
+ }
32
+ return newState
33
+ })
34
+ }, [])
35
+
36
+ const setAll = useCallback(
37
+ isChecked => {
38
+ setCheckedItems(prevState => {
39
+ const newState = new Set(prevState)
40
+ for (const id of elem) {
41
+ if (disabledItems.has(id)) {
42
+ continue
43
+ }
44
+ if (isChecked) {
45
+ newState.add(id)
46
+ } else {
47
+ newState.delete(id)
48
+ }
49
+ }
50
+ return newState
51
+ })
52
+ },
53
+ [elem, disabledItems]
54
+ )
55
+
56
+ const selectAll = useCallback(() => {
57
+ if (checkedItems.size === numTotalItems) {
58
+ return
59
+ }
60
+ setAll(true)
61
+ }, [checkedItems, numTotalItems, setAll])
62
+
63
+ const clearAll = useCallback(() => {
64
+ if (checkedItems.size === 0) {
65
+ return
66
+ }
67
+ setAll(false)
68
+ }, [checkedItems, setAll])
69
+
70
+ const toggleAll = useCallback(() => {
71
+ const numDisabledAndChecked = [...disabledItems].reduce((count, id) => {
72
+ if (checkedItems.has(id)) {
73
+ return count + 1
74
+ }
75
+ return count
76
+ }, 0)
77
+ if (checkedItems.size - numDisabledAndChecked === 0) {
78
+ selectAll()
79
+ } else {
80
+ clearAll()
81
+ }
82
+ }, [checkedItems, disabledItems, selectAll, clearAll])
83
+
84
+ const enableCheckboxes = useCallback((...elem) => {
85
+ setDisabledItems(prevState => {
86
+ const newState = new Set(prevState)
87
+ for (const id of elem) {
88
+ newState.delete(id)
89
+ }
90
+ return newState
91
+ })
92
+ }, [])
93
+
94
+ const disableCheckboxes = useCallback((...elem) => {
95
+ setDisabledItems(prevState => {
96
+ const newState = new Set(prevState)
97
+ for (const id of elem) {
98
+ newState.add(id)
99
+ }
100
+ return newState
101
+ })
102
+ }, [])
103
+
104
+ return {
105
+ checkedItems,
106
+ disabledItems,
107
+ handleChangeCheck,
108
+ toggleAll,
109
+ selectAll,
110
+ clearAll,
111
+ setCheckedItems,
112
+ enableCheckboxes,
113
+ disableCheckboxes
114
+ }
115
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Updates category and products data with a new product.
3
+ * @param {object} dataOld - The old data containing category and product information.
4
+ * @param {string} carProId - The ID of the product to update.
5
+ * @returns {object} Updated data with the new product added, or the original data if the product was not found.
6
+ */
7
+ export function getCatProductsWithProduct (dataOld = {}, carProId = '') {
8
+ try {
9
+ if (!carProId || !dataOld) return dataOld
10
+ // Make a copy of the old data to avoid modifying the original object directly
11
+ const copyDataOld = { ...dataOld }
12
+
13
+ // Get the category and products data from the old data or use an empty array if it's undefined
14
+ const catProductsWithProduct = copyDataOld?.catProductsWithProduct || []
15
+
16
+ // Find the index of the product to update
17
+ const indexToUpdate = catProductsWithProduct?.findIndex(product => product?.carProId === carProId)
18
+
19
+ if (indexToUpdate !== -1) {
20
+ // Create a new product
21
+ const newProduct = {
22
+ __typename: 'ProductFood',
23
+ carProId
24
+ }
25
+
26
+ // Update the productFoodsAll for the specified product
27
+ const newData = catProductsWithProduct?.map((catProduct) => {
28
+ if (catProduct?.carProId === carProId) {
29
+ const newProductFoodsAll = [...catProduct?.productFoodsAll, newProduct]
30
+ return {
31
+ ...catProduct,
32
+ productFoodsAll: newProductFoodsAll
33
+ }
34
+ }
35
+ return { ...catProduct }
36
+ })
37
+
38
+ // Return the updated data
39
+ return {
40
+ catProductsWithProduct: newData,
41
+ totalCount: copyDataOld.totalCount
42
+ }
43
+ }
44
+
45
+ // Return the original data if the product was not found
46
+ return copyDataOld
47
+ } catch (error) {
48
+ console.error('An error occurred while updating catProductsWithProduct:', error)
49
+ // Return the original data in case of an error
50
+ return dataOld
51
+ }
52
+ }
@@ -11,6 +11,7 @@ import {
11
11
  import { useStore } from '../useStore'
12
12
  import { useTagsProducts } from './../useProductsFood/usetagsProducts'
13
13
  import { useEditImageProduct } from './helpers/useEditImageProduct'
14
+ import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
14
15
 
15
16
  export const useCreateProduct = ({
16
17
  setAlertBox = () => { },
@@ -174,6 +175,10 @@ export const useCreateProduct = ({
174
175
  fields: {
175
176
  productFoodsAll (dataOld = []) {
176
177
  return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
178
+ },
179
+ getCatProductsWithProduct (dataOld = {}) {
180
+ const updatedData = getCatProductsWithProduct(data, carProId)
181
+ return updatedData
177
182
  }
178
183
  }
179
184
  })
@@ -203,7 +208,7 @@ export const useCreateProduct = ({
203
208
  pId
204
209
  }
205
210
  handleRegisterTags(objTag)
206
- // setValues({})
211
+ setValues({})
207
212
  }).catch(err => {
208
213
  return sendNotification({
209
214
  backgroundColor: 'error',
@@ -219,7 +224,7 @@ export const useCreateProduct = ({
219
224
  pCode
220
225
  }
221
226
  }
222
- }).then((response) => {
227
+ }).then(() => {
223
228
  }).catch(() => {
224
229
  sendNotification({
225
230
  backgroundColor: 'error',
@@ -229,7 +234,7 @@ export const useCreateProduct = ({
229
234
  })
230
235
  }
231
236
  } catch (error) {
232
- setAlertBox({ message: `${error.message}`, duration: 7000 })
237
+ setAlertBox({ message: 'Ha ocurrido un error', duration: 7000 })
233
238
  }
234
239
  }
235
240
 
@@ -1,30 +1,30 @@
1
- import { useMutation } from '@apollo/client'
2
- import { DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS } from './queries'
3
- import { updateCacheMod } from '../../utils'
4
- import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
5
-
6
- export const useDeleteSubProductOptional = ({ setAlertBox = () => { } } = {}) => {
7
- const [DeleteExtFoodSubsOptional, {
8
- loading,
9
- error,
10
- called
11
- }] = useMutation(DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS)
12
-
13
- const handleRemoveSubProductOptional = ({ state, opSubExPid }) => {
14
- DeleteExtFoodSubsOptional({
15
- variables: {
16
- state,
17
- opSubExPid
18
- },
19
- update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
20
- return updateCacheMod({
21
- cache,
22
- query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
23
- nameFun: 'ExtProductFoodsOptionalAll',
24
- dataNew: ExtProductFoodsOptionalAll
25
- })
26
- }
27
- }).then(res => { return setAlertBox({ message: res?.message?.DeleteExtFoodSubsOptional?.message }) })
28
- }
29
- return [DeleteExtFoodSubsOptional, handleRemoveSubProductOptional, { loading, error, called }]
30
- }
1
+ import { useMutation } from '@apollo/client'
2
+ import { DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS } from './queries'
3
+ import { updateCacheMod } from '../../utils'
4
+ import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsOptional/queries'
5
+
6
+ export const useDeleteSubProductOptional = ({ setAlertBox = () => { } } = {}) => {
7
+ const [DeleteExtFoodSubsOptional, {
8
+ loading,
9
+ error,
10
+ called
11
+ }] = useMutation(DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS)
12
+
13
+ const handleRemoveSubProductOptional = ({ state, opSubExPid }) => {
14
+ DeleteExtFoodSubsOptional({
15
+ variables: {
16
+ state,
17
+ opSubExPid
18
+ },
19
+ update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
20
+ return updateCacheMod({
21
+ cache,
22
+ query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
23
+ nameFun: 'ExtProductFoodsOptionalAll',
24
+ dataNew: ExtProductFoodsOptionalAll
25
+ })
26
+ }
27
+ }).then(res => { return setAlertBox({ message: res?.message?.DeleteExtFoodSubsOptional?.message }) })
28
+ }
29
+ return [DeleteExtFoodSubsOptional, handleRemoveSubProductOptional, { loading, error, called }]
30
+ }
@@ -1,10 +1,10 @@
1
- import { gql } from '@apollo/client'
2
-
3
- export const DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
4
- mutation DeleteExtFoodSubsOptional($opSubExPid: ID, $state: Int, $isCustomSubOpExPid: Boolean){
5
- DeleteExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state, isCustomSubOpExPid: $isCustomSubOpExPid){
6
- success,
7
- message
8
- }
9
- }
10
- `
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const DELETE_CAT_EXTRA_SUB_OPTIONAL_PRODUCTS = gql`
4
+ mutation DeleteExtFoodSubsOptional($opSubExPid: ID, $state: Int, $isCustomSubOpExPid: Boolean){
5
+ DeleteExtFoodSubsOptional(opSubExPid: $opSubExPid, state: $state, isCustomSubOpExPid: $isCustomSubOpExPid){
6
+ success,
7
+ message
8
+ }
9
+ }
10
+ `
@@ -1,51 +1,51 @@
1
- import { MockData } from '../../../mock'
2
-
3
- /**
4
- * Transforms an array of objects into a specific data format suitable for desserts.
5
- *
6
- * @param {Array<Object>} dataArray - The array of objects to transform.
7
- * @return {Object} The transformed data containing lists and listIds.
8
- * @throws {Error} If dataArray is not an array or if the objects lack required properties.
9
- */
10
- export const transformDataToDessert = (dataArray) => {
11
- try {
12
- if (!dataArray) {
13
- return MockData
14
- }
15
- if (!Array.isArray(dataArray)) {
16
- throw new Error('dataArray must be an array.')
17
- }
18
-
19
- const transformedData = {
20
- lists: {},
21
- listIds: []
22
- }
23
-
24
- dataArray.forEach((item) => {
25
- const listId = item.code
26
- transformedData.listIds.push(listId)
27
- transformedData.lists[listId] = {
28
- id: listId,
29
- title: item?.OptionalProName,
30
- numberLimit: item?.numbersOptionalOnly,
31
- required: item?.required,
32
- value: '',
33
- cards: item?.ExtProductFoodsSubOptionalAll?.length > 0
34
- ? item?.ExtProductFoodsSubOptionalAll?.map(subOptional => {
35
- return {
36
- id: subOptional?.exCode,
37
- title: subOptional?.OptionalSubProName,
38
- required: subOptional?.state,
39
- value: ''
40
- }
41
- })
42
- : []
43
- }
44
- })
45
-
46
- return transformedData
47
- } catch (error) {
48
- console.error(error.message)
49
- return MockData
50
- }
51
- }
1
+ import { MockData } from '../../../mock'
2
+
3
+ /**
4
+ * Transforms an array of objects into a specific data format suitable for desserts.
5
+ *
6
+ * @param {Array<Object>} dataArray - The array of objects to transform.
7
+ * @return {Object} The transformed data containing lists and listIds.
8
+ * @throws {Error} If dataArray is not an array or if the objects lack required properties.
9
+ */
10
+ export const transformDataToDessert = (dataArray) => {
11
+ try {
12
+ if (!dataArray) {
13
+ return MockData
14
+ }
15
+ if (!Array.isArray(dataArray)) {
16
+ throw new Error('dataArray must be an array.')
17
+ }
18
+
19
+ const transformedData = {
20
+ lists: {},
21
+ listIds: []
22
+ }
23
+
24
+ dataArray.forEach((item) => {
25
+ const listId = item.code
26
+ transformedData.listIds.push(listId)
27
+ transformedData.lists[listId] = {
28
+ id: listId,
29
+ title: item?.OptionalProName,
30
+ numberLimit: item?.numbersOptionalOnly,
31
+ required: item?.required,
32
+ value: '',
33
+ cards: item?.ExtProductFoodsSubOptionalAll?.length > 0
34
+ ? item?.ExtProductFoodsSubOptionalAll?.map(subOptional => {
35
+ return {
36
+ id: subOptional?.exCode,
37
+ title: subOptional?.OptionalSubProName,
38
+ required: subOptional?.state,
39
+ value: ''
40
+ }
41
+ })
42
+ : []
43
+ }
44
+ })
45
+
46
+ return transformedData
47
+ } catch (error) {
48
+ console.error(error.message)
49
+ return MockData
50
+ }
51
+ }
@@ -1,35 +1,35 @@
1
- import { useState, useEffect } from 'react'
2
- import { useQuery } from '@apollo/client'
3
- import { GET_ALL_DEVICES } from './queries'
4
- import { useFormatDate } from '../useFormatDate'
5
-
6
- export const useDevices = () => {
7
- const { data, loading } = useQuery(GET_ALL_DEVICES, {
8
- onError: (error) => {
9
- console.error(error)
10
- }
11
- })
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
-
21
- // Función para formatear la fecha
22
- const formatDate = useFormatDate({ date })
23
-
24
- const updateDate = (newDate) => {
25
- setDate(newDate)
26
- }
27
- return {
28
- data: data?.getDeviceUsers || [],
29
- date,
30
- deviceId,
31
- formatDate,
32
- loading,
33
- updateDate
34
- }
35
- }
1
+ import { useState, useEffect } from 'react'
2
+ import { useQuery } from '@apollo/client'
3
+ import { GET_ALL_DEVICES } from './queries'
4
+ import { useFormatDate } from '../useFormatDate'
5
+
6
+ export const useDevices = () => {
7
+ const { data, loading } = useQuery(GET_ALL_DEVICES, {
8
+ onError: (error) => {
9
+ console.error(error)
10
+ }
11
+ })
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
+
21
+ // Función para formatear la fecha
22
+ const formatDate = useFormatDate({ date })
23
+
24
+ const updateDate = (newDate) => {
25
+ setDate(newDate)
26
+ }
27
+ return {
28
+ data: data?.getDeviceUsers || [],
29
+ date,
30
+ deviceId,
31
+ formatDate,
32
+ loading,
33
+ updateDate
34
+ }
35
+ }
@@ -1,19 +1,19 @@
1
- import { gql } from '@apollo/client'
2
-
3
- export const GET_ALL_DEVICES = gql`
4
- query getDeviceUsers{
5
- getDeviceUsers{
6
- dId
7
- locationFormat
8
- deviceId
9
- deviceName
10
- type
11
- short_name
12
- platform
13
- version
14
- dState
15
- DatCre
16
- DatMod
17
- }
18
- }
19
- `
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ALL_DEVICES = gql`
4
+ query getDeviceUsers{
5
+ getDeviceUsers{
6
+ dId
7
+ locationFormat
8
+ deviceId
9
+ deviceName
10
+ type
11
+ short_name
12
+ platform
13
+ version
14
+ dState
15
+ DatCre
16
+ DatMod
17
+ }
18
+ }
19
+ `