npm-pkg-hook 1.1.5 → 1.1.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 (140) hide show
  1. package/.eslintrc.js +19 -113
  2. package/.eslintrc.json +127 -108
  3. package/next.config.js +2 -5
  4. package/package.json +27 -24
  5. package/src/config/client/errors.js +14 -14
  6. package/src/config/client/index.js +1 -1
  7. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
  8. package/src/hooks/getCategoriesWithProduct/index.js +62 -0
  9. package/src/hooks/getSession/index.js +18 -18
  10. package/src/hooks/index.js +13 -9
  11. package/src/hooks/useAcumulateDate/index.js +1 -1
  12. package/src/hooks/useAnimationFrame/index.js +45 -45
  13. package/src/hooks/useAsideCart/helpers/index.js +22 -0
  14. package/src/hooks/useAsideCart/index.js +156 -0
  15. package/src/hooks/useAsideCart/queries.js +10 -0
  16. package/src/hooks/useBanner/index.js +11 -11
  17. package/src/hooks/useCart/index.js +2 -0
  18. package/src/hooks/useCart/queries.js +164 -0
  19. package/src/hooks/useCart/useCart/helpers/index.js +75 -0
  20. package/src/hooks/useCart/useCart/index.js +411 -0
  21. package/src/hooks/useCart/useGetCart/index.js +31 -0
  22. package/src/hooks/useCatWithProduct/index.js +15 -15
  23. package/src/hooks/useCatWithProduct/queries.js +1 -1
  24. package/src/hooks/useCatWithProductClient/index.js +48 -0
  25. package/src/hooks/useCatWithProductClient/queries.js +55 -0
  26. package/src/hooks/useCategoriesProduct/index.js +12 -12
  27. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  28. package/src/hooks/useCategoryInStore/index.js +39 -36
  29. package/src/hooks/useCategoryInStore/queries.js +78 -78
  30. package/src/hooks/useCategoryStore/index.js +2 -2
  31. package/src/hooks/useChartData/index.js +159 -156
  32. package/src/hooks/useChartData/useChartData/index.js +199 -197
  33. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  34. package/src/hooks/useCheckbox/index.js +115 -115
  35. package/src/hooks/useClients/index.js +12 -14
  36. package/src/hooks/useClients/queries.js +1 -1
  37. package/src/hooks/useConnection/index.js +20 -21
  38. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
  39. package/src/hooks/useCreateProduct/index.js +22 -19
  40. package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
  41. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  42. package/src/hooks/useDessert/helpers/index.js +51 -51
  43. package/src/hooks/useDessert/index.js +56 -65
  44. package/src/hooks/useDevices/index.js +35 -36
  45. package/src/hooks/useDevices/queries.js +19 -19
  46. package/src/hooks/useDropzone/index.js +94 -79
  47. package/src/hooks/useDynamicAuth/index.js +13 -13
  48. package/src/hooks/useDynamicAuth/queries.js +24 -24
  49. package/src/hooks/useEmployee/queries.js +1 -1
  50. package/src/hooks/useEvent/index.js +33 -33
  51. package/src/hooks/useFavoriteStores/index.js +19 -0
  52. package/src/hooks/useFavoriteStores/queries.js +47 -0
  53. package/src/hooks/useFetchJson/index.js +25 -25
  54. package/src/hooks/useFingerprintjs/index.js +172 -176
  55. package/src/hooks/useFormTools/index.js +12 -11
  56. package/src/hooks/useFormatDate/index.js +20 -21
  57. package/src/hooks/useFormatNumberPhone/index.js +9 -9
  58. package/src/hooks/useFullScreenMode/index.js +65 -65
  59. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  60. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
  61. package/src/hooks/useGetFoodRecomended/index.js +33 -0
  62. package/src/hooks/useGetFoodRecomended/queries.js +47 -0
  63. package/src/hooks/useGetMinPrice/index.js +8 -0
  64. package/src/hooks/useGetMinPrice/queries.js +7 -0
  65. package/src/hooks/useGetOneStoreRating/index.js +40 -0
  66. package/src/hooks/useGetOneStoreRating/queries.js +18 -0
  67. package/src/hooks/useGoogleLogin/index.js +160 -161
  68. package/src/hooks/useHover/index.js +29 -29
  69. package/src/hooks/useImageOptimization/index.js +15 -15
  70. package/src/hooks/useImageWeight/index.js +18 -19
  71. package/src/hooks/useImagesStore/index.js +139 -140
  72. package/src/hooks/useImagesStore/queries.js +19 -18
  73. package/src/hooks/useInnerHtml/index.js +39 -38
  74. package/src/hooks/useIntersection/index.js +4 -4
  75. package/src/hooks/useKeypress/index.js +28 -28
  76. package/src/hooks/useLazyScript/index.js +35 -36
  77. package/src/hooks/useLocalSorage/index.js +2 -2
  78. package/src/hooks/useLogout/index.js +23 -23
  79. package/src/hooks/useManageQueryParams/index.js +36 -37
  80. package/src/hooks/useMobile/index.js +39 -38
  81. package/src/hooks/useMutateHeight/index.js +15 -16
  82. package/src/hooks/useOrderClient/index.js +5 -0
  83. package/src/hooks/useOrders/index.js +10 -16
  84. package/src/hooks/useOrders/queries.js +1 -1
  85. package/src/hooks/useProductsFood/index.js +32 -32
  86. package/src/hooks/useProductsFood/queriesStore.js +49 -48
  87. package/src/hooks/useProductsFood/useEditProduct.js +2 -4
  88. package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
  89. package/src/hooks/useProviders/index.js +3 -3
  90. package/src/hooks/useProviders/queries.js +31 -31
  91. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
  92. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  93. package/src/hooks/useProvidersStore/index.js +24 -24
  94. package/src/hooks/useProvidersStore/queries.js +31 -31
  95. package/src/hooks/useRatingArrayData/index.js +54 -0
  96. package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
  97. package/src/hooks/useReactToPrint/index.js +1120 -1098
  98. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  99. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  100. package/src/hooks/useReport/index.js +9 -9
  101. package/src/hooks/useReport/queries.js +1 -1
  102. package/src/hooks/useRestaurant/index.js +19 -19
  103. package/src/hooks/useRestaurant/queries.js +80 -80
  104. package/src/hooks/useSales/index.js +476 -451
  105. package/src/hooks/useSales/queries.js +14 -15
  106. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  107. package/src/hooks/useSales/useTotalSales.js +18 -18
  108. package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
  109. package/src/hooks/useSaveAvailableProduct/index.js +16 -16
  110. package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
  111. package/src/hooks/useSchedule/index.js +33 -36
  112. package/src/hooks/useSchedule/index.jsx +22 -22
  113. package/src/hooks/useSchedule/queries.js +34 -35
  114. package/src/hooks/useScheduleData/index.js +123 -171
  115. package/src/hooks/useScroll/index.js +56 -57
  116. package/src/hooks/useScrollRotate/index.js +16 -14
  117. package/src/hooks/useSetSession/index.js +16 -16
  118. package/src/hooks/useSetState/index.js +3 -3
  119. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
  120. package/src/hooks/useStatusOpenStore/index.js +172 -173
  121. package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
  122. package/src/hooks/useStatusOrdersClient/index.js +17 -0
  123. package/src/hooks/useStatusOrdersClient/queries.js +80 -0
  124. package/src/hooks/useStore/index.js +40 -25
  125. package/src/hooks/useStore/queries.js +162 -136
  126. package/src/hooks/useStoreCalendar/index.js +5 -7
  127. package/src/hooks/useStoreContacts/index.js +16 -16
  128. package/src/hooks/useStoreContacts/queries.js +1 -1
  129. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  130. package/src/hooks/useUpdateCart/index.js +34 -28
  131. package/src/hooks/useUpdateExistingOrders/index.js +35 -35
  132. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
  133. package/src/hooks/useUser/index.js +1 -1
  134. package/src/hooks/useUser/queries.js +1 -1
  135. package/src/hooks/useWindowSize/index.js +38 -38
  136. package/src/mock/dessert/index.js +16 -16
  137. package/src/mock/index.js +1 -2
  138. package/src/utils/index.js +42 -45
  139. package/src/hooks/useRatingData/index.js +0 -53
  140. package/src/hooks/useSalesClient/index.js +0 -1
@@ -31,7 +31,7 @@ export const useUpdateCart = () => {
31
31
  if (typeof cart === 'string' && cart !== 'undefined') {
32
32
  const cartData = JSON.parse(cart)
33
33
  const total = cartData.reduce(
34
- (total, item) => {return total + item.price * item.quantity},
34
+ (total, item) => { return total + item.price * item.quantity },
35
35
  0
36
36
  )
37
37
 
@@ -46,38 +46,42 @@ export const useUpdateCart = () => {
46
46
  const handleAdd = (item) => {
47
47
  // check for item already in cart
48
48
  // if not in cart, add item else if item is found increment quantity
49
- const itemExists = cart.items.find((i) => {return i.pId === item.pId})
49
+ const itemExists = cart.items.find((i) => { return i.pId === item.pId })
50
50
 
51
51
  if (!itemExists) {
52
- setCart((prevCart) => {return {
53
- items: [...prevCart.items, { ...item, quantity: 1 }],
54
- total: prevCart.total + item.price
55
- }})
52
+ setCart((prevCart) => {
53
+ return {
54
+ items: [...prevCart.items, { ...item, quantity: 1 }],
55
+ total: prevCart.total + item.price
56
+ }
57
+ })
56
58
 
57
59
  return
58
60
  }
59
61
 
60
- setCart((prevCart) => {return {
61
- items: prevCart.items.map((i) => {
62
- if (i.pId === item.pId) {
63
- return { ...i, quantity: i.quantity + 1 }
64
- }
62
+ setCart((prevCart) => {
63
+ return {
64
+ items: prevCart.items.map((i) => {
65
+ if (i.pId === item.pId) {
66
+ return { ...i, quantity: i.quantity + 1 }
67
+ }
65
68
 
66
- return i
67
- }),
68
- total: prevCart.total + item.price
69
- }})
69
+ return i
70
+ }),
71
+ total: prevCart.total + item.price
72
+ }
73
+ })
70
74
  updateCart(cart)
71
75
  }
72
76
 
73
77
  const deleteProductCart = (item) => {
74
78
  setCart((prevCart) => {
75
79
  const items = prevCart.items
76
- const index = items.findIndex((i) => {return i.pId === item.pId})
80
+ const index = items.findIndex((i) => { return i.pId === item.pId })
77
81
 
78
82
  items.splice(index, 1)
79
83
 
80
- const total = items.reduce((t, i) => {return t + i.quantity * i.price}, 0)
84
+ const total = items.reduce((t, i) => { return t + i.quantity * i.price }, 0)
81
85
 
82
86
  return { items, total }
83
87
  })
@@ -86,7 +90,7 @@ export const useUpdateCart = () => {
86
90
  const decreaseItemFromCart = (item) => {
87
91
  // check for item already in cart
88
92
  // if quantity is more then in cart, subtract item else remove item
89
- const itemInCart = cart.items.find((i) => {return i.pId === item.pId})
93
+ const itemInCart = cart.items.find((i) => { return i.pId === item.pId })
90
94
 
91
95
  if (!itemInCart) {
92
96
  return
@@ -98,16 +102,18 @@ export const useUpdateCart = () => {
98
102
  return
99
103
  }
100
104
 
101
- setCart((prevCart) => {return {
102
- items: prevCart.items.map((i) => {
103
- if (i.pId === item.pId) {
104
- return { ...i, quantity: item.quantity - 1 }
105
- }
106
-
107
- return i
108
- }),
109
- total: prevCart.total - item.price
110
- }})
105
+ setCart((prevCart) => {
106
+ return {
107
+ items: prevCart.items.map((i) => {
108
+ if (i.pId === item.pId) {
109
+ return { ...i, quantity: item.quantity - 1 }
110
+ }
111
+
112
+ return i
113
+ }),
114
+ total: prevCart.total - item.price
115
+ }
116
+ })
111
117
  }
112
118
 
113
119
  const clearCart = () => {
@@ -1,11 +1,11 @@
1
1
  export const isValidCodeRef = (codeRef) => {
2
- return typeof codeRef === "string" && codeRef.trim() !== "";
3
- };
2
+ return typeof codeRef === 'string' && codeRef.trim() !== ''
3
+ }
4
4
 
5
5
  export const isValidState = (state) => {
6
- const validStates = [0, 1, 2, 3, 4, 5];
7
- return validStates.includes(state);
8
- };
6
+ const validStates = [1, 2, 3, 4, 5]
7
+ return validStates.includes(state)
8
+ }
9
9
 
10
10
  export const updateExistingOrders = (
11
11
  existingOrders,
@@ -13,79 +13,79 @@ export const updateExistingOrders = (
13
13
  pSState,
14
14
  objectToAdd
15
15
  ) => {
16
- if (typeof existingOrders !== "object" || existingOrders === null) {
16
+ if (typeof existingOrders !== 'object' || existingOrders === null) {
17
17
  // existingOrders no es un objeto válido
18
- return existingOrders;
18
+ return existingOrders
19
19
  }
20
- if (typeof pCodeRef !== "string" || typeof pSState !== "number") {
20
+ if (typeof pCodeRef !== 'string' || typeof pSState !== 'number') {
21
21
  // Los tipos de datos de pCodeRef y pSState no son los esperados
22
- return existingOrders;
22
+ return existingOrders
23
23
  }
24
24
  if (!isValidCodeRef(pCodeRef) || !isValidState(pSState)) {
25
25
  // Valores de entrada no válidos, devuelve existingOrders sin cambios
26
- return existingOrders;
26
+ return existingOrders
27
27
  }
28
28
 
29
- const updatedExistingOrders = { ...existingOrders }; // Copiar el objeto existente
29
+ const updatedExistingOrders = { ...existingOrders } // Copiar el objeto existente
30
30
 
31
31
  const statusKeys = {
32
- 1: "ACEPTA",
33
- 2: "PROCESSING",
34
- 3: "READY",
35
- 4: "CONCLUDES",
36
- 5: "RECHAZADOS",
37
- };
38
- const targetArray = statusKeys[pSState];
32
+ 1: 'ACEPTA',
33
+ 2: 'PROCESSING',
34
+ 3: 'READY',
35
+ 4: 'CONCLUDES',
36
+ 5: 'RECHAZADOS'
37
+ }
38
+ const targetArray = statusKeys[pSState]
39
39
 
40
40
  if (!targetArray || !(targetArray in existingOrders)) {
41
41
  // El valor de pSState no está mapeado a ninguna propiedad existente en existingOrders
42
- return existingOrders;
42
+ return existingOrders
43
43
  }
44
44
 
45
45
  Object.keys(updatedExistingOrders).forEach((key) => {
46
46
  if (Array.isArray(updatedExistingOrders[key])) {
47
47
  const oneSale = updatedExistingOrders[key].find((order) => {
48
- return order.pCodeRef === pCodeRef;
49
- });
48
+ return order.pCodeRef === pCodeRef
49
+ })
50
50
 
51
51
  updatedExistingOrders[key] = updatedExistingOrders[key].filter(
52
52
  (order) => {
53
- return order.pCodeRef !== pCodeRef;
53
+ return order.pCodeRef !== pCodeRef
54
54
  }
55
- );
55
+ )
56
56
 
57
57
  if (oneSale !== undefined && oneSale !== null) {
58
- const updatedOneSale = { ...oneSale, pSState };
58
+ const updatedOneSale = { ...oneSale, pSState }
59
59
 
60
60
  if (!Array.isArray(updatedExistingOrders[targetArray])) {
61
- updatedExistingOrders[targetArray] = [];
61
+ updatedExistingOrders[targetArray] = []
62
62
  }
63
63
 
64
64
  updatedExistingOrders[targetArray] = [
65
65
  updatedOneSale,
66
- ...updatedExistingOrders[targetArray],
67
- ];
66
+ ...updatedExistingOrders[targetArray]
67
+ ]
68
68
  }
69
69
  }
70
- });
70
+ })
71
71
 
72
72
  if (objectToAdd && objectToAdd.pCodeRef === pCodeRef) {
73
73
  if (!Array.isArray(updatedExistingOrders[targetArray])) {
74
- updatedExistingOrders[targetArray] = [];
74
+ updatedExistingOrders[targetArray] = []
75
75
  }
76
76
 
77
77
  updatedExistingOrders[targetArray] = [
78
78
  objectToAdd,
79
- ...updatedExistingOrders[targetArray],
80
- ];
79
+ ...updatedExistingOrders[targetArray]
80
+ ]
81
81
  }
82
82
 
83
83
  // Asegurar que todas las propiedades estén presentes
84
84
  Object.keys(statusKeys).forEach((statusKey) => {
85
85
  if (!(statusKeys[statusKey] in updatedExistingOrders)) {
86
- updatedExistingOrders[statusKeys[statusKey]] = [];
86
+ updatedExistingOrders[statusKeys[statusKey]] = []
87
87
  }
88
- });
88
+ })
89
89
 
90
- return updatedExistingOrders;
91
- };
90
+ return updatedExistingOrders
91
+ }
@@ -1,37 +1,38 @@
1
- import { useMutation } from '@apollo/client'
2
- import { updateCacheMod } from '../../utils'
3
- import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL, GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL } from '../useProductsFood/queriesStore'
4
-
5
- export const useUpdateExtProductFoodsSubOptional = () => {
6
- const [updateExtProductFoodsSubOptional] = useMutation(GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL)
7
-
8
- const handleMutateExtProductFoodsSubOptional = ({
9
- pId,
10
- title,
11
- listId,
12
- id,
13
- state = 1,
14
- }) => {
15
- updateExtProductFoodsSubOptional({
16
- variables: {
17
- input: {
18
- pId,
19
- OptionalSubProName: title,
20
- exCodeOptionExtra: listId,
21
- exCode: id,
22
- state
23
- }
24
- }, update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
25
- return updateCacheMod({
26
- cache,
27
- query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
28
- nameFun: 'ExtProductFoodsOptionalAll',
29
- dataNew: ExtProductFoodsOptionalAll
30
- })
31
- }
32
- })
33
- }
34
- return {
35
- handleMutateExtProductFoodsSubOptional
36
- }
37
- }
1
+ import { useMutation } from '@apollo/client'
2
+ import { updateCacheMod } from '../../utils'
3
+ import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL, GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL } from '../useProductsFood/queriesStore'
4
+
5
+ export const useUpdateExtProductFoodsSubOptional = () => {
6
+ const [updateExtProductFoodsSubOptional] = useMutation(GET_EXTRAS_PRODUCT_FOOD_SUB_OPTIONAL)
7
+
8
+ const handleMutateExtProductFoodsSubOptional = ({
9
+ pId,
10
+ title,
11
+ listId,
12
+ id,
13
+ state = 1
14
+ }) => {
15
+ updateExtProductFoodsSubOptional({
16
+ variables: {
17
+ input: {
18
+ pId,
19
+ OptionalSubProName: title,
20
+ exCodeOptionExtra: listId,
21
+ exCode: id,
22
+ state
23
+ }
24
+ },
25
+ update: (cache, { data: { ExtProductFoodsOptionalAll } }) => {
26
+ return updateCacheMod({
27
+ cache,
28
+ query: GET_EXTRAS_PRODUCT_FOOD_OPTIONAL,
29
+ nameFun: 'ExtProductFoodsOptionalAll',
30
+ dataNew: ExtProductFoodsOptionalAll
31
+ })
32
+ }
33
+ })
34
+ }
35
+ return {
36
+ handleMutateExtProductFoodsSubOptional
37
+ }
38
+ }
@@ -14,4 +14,4 @@ export const useUserProfile = () => {
14
14
  export const useSetUserProfile = () => {
15
15
  const [setUserProfile, { loading, error }] = useMutation(SET_USER_PROFILE)
16
16
  return [setUserProfile, { loading, error }]
17
- }
17
+ }
@@ -124,4 +124,4 @@ export const SET_USER_PROFILE = gql`
124
124
  upZipCode
125
125
  }
126
126
  }
127
- `
127
+ `
@@ -1,38 +1,38 @@
1
- import { useState, useEffect } from 'react';
2
-
3
- export function useWindowSize() {
4
- // Initialize state with undefined width/height so server and client renders match
5
- // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
6
- const [windowSize, setWindowSize] = useState({
7
- width: undefined,
8
- height: undefined
9
- });
10
-
11
- useEffect(() => {
12
- // Handler to call on window resize
13
- function handleResize() {
14
- // Set window width/height to state
15
- setWindowSize({
16
- width: window.innerWidth,
17
- height: window.innerHeight
18
- });
19
- }
20
-
21
- // Add event listener
22
- window.addEventListener('resize', handleResize);
23
-
24
- // Call handler right away so state gets updated with initial window size
25
- handleResize();
26
-
27
- // Remove event listener on cleanup
28
- return () => window.removeEventListener('resize', handleResize);
29
- }, []); // Empty array ensures that effect is only run on mount
30
-
31
- return windowSize;
32
- }
33
- // Como se usa
34
-
35
- // 1 -const size = useWindowSize();
36
- // 2 <div>
37
- // {size.width}px / {size.height}px
38
- // </div>
1
+ import { useState, useEffect } from 'react'
2
+
3
+ export function useWindowSize () {
4
+ // Initialize state with undefined width/height so server and client renders match
5
+ // Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/
6
+ const [windowSize, setWindowSize] = useState({
7
+ width: undefined,
8
+ height: undefined
9
+ })
10
+
11
+ useEffect(() => {
12
+ // Handler to call on window resize
13
+ function handleResize () {
14
+ // Set window width/height to state
15
+ setWindowSize({
16
+ width: window.innerWidth,
17
+ height: window.innerHeight
18
+ })
19
+ }
20
+
21
+ // Add event listener
22
+ window.addEventListener('resize', handleResize)
23
+
24
+ // Call handler right away so state gets updated with initial window size
25
+ handleResize()
26
+
27
+ // Remove event listener on cleanup
28
+ return () => window.removeEventListener('resize', handleResize)
29
+ }, []) // Empty array ensures that effect is only run on mount
30
+
31
+ return windowSize
32
+ }
33
+ // Como se usa
34
+
35
+ // 1 -const size = useWindowSize();
36
+ // 2 <div>
37
+ // {size.width}px / {size.height}px
38
+ // </div>
@@ -1,16 +1,16 @@
1
- import { RandomCode } from '../../utils'
2
-
3
- export const MockData = {
4
- lists: {
5
- '01list': {
6
- id: RandomCode(9),
7
- title: 'Elige tu salsa favorita',
8
- numberLimit: 0,
9
- required: 0,
10
- value: '',
11
- cards: [
12
- ]
13
- }
14
- },
15
- listIds: ['01list']
16
- }
1
+ import { RandomCode } from '../../utils'
2
+
3
+ export const MockData = {
4
+ lists: {
5
+ '01list': {
6
+ id: RandomCode(9),
7
+ title: 'Elige tu salsa favorita',
8
+ numberLimit: 0,
9
+ required: 0,
10
+ value: '',
11
+ cards: [
12
+ ]
13
+ }
14
+ },
15
+ listIds: ['01list']
16
+ }
package/src/mock/index.js CHANGED
@@ -1,2 +1 @@
1
- export * from './dessert';
2
-
1
+ export * from './dessert'
@@ -11,47 +11,46 @@ const validTypes = {
11
11
  number: true,
12
12
  hidden: true,
13
13
  textarea: true
14
- };
14
+ }
15
15
 
16
16
  export const validationSubmitHooks = elements => {
17
- let errorForm = {};
17
+ let errorForm = {}
18
18
 
19
19
  for (const element of elements) {
20
20
  if (element.name) {
21
- const elementType = element.type || element.tagName.toLowerCase();
21
+ const elementType = element.type || element.tagName.toLowerCase()
22
22
  if (validTypes[elementType]) {
23
23
  if (element.dataset.required === 'true') {
24
24
  if (!element.value) {
25
- errorForm = { ...errorForm, [element.name]: true };
25
+ errorForm = { ...errorForm, [element.name]: true }
26
26
  } else {
27
- errorForm = { ...errorForm, [element.name]: false };
27
+ errorForm = { ...errorForm, [element.name]: false }
28
28
  }
29
29
  } else {
30
- errorForm = { ...errorForm, [element.name]: false };
30
+ errorForm = { ...errorForm, [element.name]: false }
31
31
  }
32
32
  }
33
33
  }
34
34
  }
35
35
 
36
- return errorForm;
37
- };
38
-
36
+ return errorForm
37
+ }
39
38
 
40
- export const getCurrentDomain = () => {
41
- return typeof window !== 'undefined' && window.location.hostname.split('.').slice(-2).join('.')
42
- }
39
+ export const getCurrentDomain = () => {
40
+ return typeof window !== 'undefined' && window.location.hostname.split('.').slice(-2).join('.')
41
+ }
43
42
 
44
- export function RandomCode(length) {
45
- let result = ''
46
- let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
47
- let charactersLength = characters.length
48
- for (let i = 0; i < length; i++) {
49
- result += characters.charAt(Math.floor(Math.random() *
43
+ export function RandomCode (length) {
44
+ let result = ''
45
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
46
+ const charactersLength = characters.length
47
+ for (let i = 0; i < length; i++) {
48
+ result += characters.charAt(Math.floor(Math.random() *
50
49
  charactersLength))
51
- }
52
- return result
53
50
  }
54
- /**
51
+ return result
52
+ }
53
+ /**
55
54
  * actualizar cache de apollo
56
55
  * @param {{ cache: object, query: object, nameFun: string, dataNew: object, type: number, id: string }} params Parámetros para actualizar el cachet de apollo
57
56
  * @returns {null} no hay retorno
@@ -59,7 +58,7 @@ export const validationSubmitHooks = elements => {
59
58
  export const updateCacheMod = async ({ cache, query, nameFun, dataNew, type, id }) => {
60
59
  return cache.modify({
61
60
  fields: {
62
- [nameFun](dataOld = []) {
61
+ [nameFun] (dataOld = []) {
63
62
  if (type === 1) return cache.writeQuery({ query, data: [...(dataOld || []), { ...(dataNew || {}) }] })
64
63
  if (type === 2) return cache.writeQuery({ query, data: { ...(dataOld || {}), ...(dataNew || {}) } })
65
64
  if (type === 3) return cache.writeQuery({ query, data: dataOld.filter(x => { return x === id }) })
@@ -67,12 +66,11 @@ export const updateCacheMod = async ({ cache, query, nameFun, dataNew, type, id
67
66
  }
68
67
  })
69
68
  }
69
+ const initialState = {}
70
70
  export const initializer = (initialValue = initialState) => { return JSON.parse(localStorage.getItem(process.env.LOCAL_SALES_STORE)) || initialValue }
71
71
 
72
-
73
72
  export const numberFormat = value => { return value ? (parseInt(value) ? new Intl.NumberFormat('de-DE').format(parseFloat(`${value}`.replace(/\./g, ''))) : value) : (value) }
74
73
 
75
-
76
74
  /**
77
75
  *
78
76
  * @param {Object} data objeto a filtrar
@@ -81,16 +79,16 @@ export const numberFormat = value => { return value ? (parseInt(value) ? new Int
81
79
  * @return {Object} devuelve un objeto con los datos filtrados
82
80
  */
83
81
  export const filterKeyObject = (data, filters, dataFilter) => {
84
- let values = {}, valuesFilter = {}
82
+ let values = {}; let valuesFilter = {}
85
83
  for (const elem in data) {
86
- let coincidence = false
87
- for (let i = 0; i < filters.length; i++) {
88
- if (elem === filters[i]) coincidence = true
89
- else valuesFilter = filters[i]
90
- }
84
+ let coincidence = false
85
+ for (let i = 0; i < filters.length; i++) {
86
+ if (elem === filters[i]) coincidence = true
87
+ else valuesFilter = filters[i]
88
+ }
91
89
 
92
- if (!coincidence) values = { ...values, [elem]: data[elem] }
93
- else valuesFilter = { ...valuesFilter, [elem]: data[elem] }
90
+ if (!coincidence) values = { ...values, [elem]: data[elem] }
91
+ else valuesFilter = { ...valuesFilter, [elem]: data[elem] }
94
92
  }
95
93
  if (!dataFilter) return values
96
94
  if (dataFilter) return { values, valuesFilter }
@@ -110,21 +108,20 @@ export const MONTHS = [
110
108
  'December'
111
109
  ]
112
110
  export const SPANISH_MONTHS = {
113
- 0:'Enero',
114
- 1:'Febrero',
115
- 2:'Marzo',
116
- 3:'Abril',
117
- 4:'Mayo',
118
- 5:'Junio',
119
- 6:'Julio',
120
- 7:'Augosto',
121
- 8:'Septiembre',
122
- 9:'Octubre',
123
- 10:'Noviembre ',
124
- 11:'Diciembre'
111
+ 0: 'Enero',
112
+ 1: 'Febrero',
113
+ 2: 'Marzo',
114
+ 3: 'Abril',
115
+ 4: 'Mayo',
116
+ 5: 'Junio',
117
+ 6: 'Julio',
118
+ 7: 'Augosto',
119
+ 8: 'Septiembre',
120
+ 9: 'Octubre',
121
+ 10: 'Noviembre ',
122
+ 11: 'Diciembre'
125
123
  }
126
124
 
127
-
128
125
  export const convertBase64 = file => {
129
126
  return new Promise((resolve, reject) => {
130
127
  const reader = new FileReader()
@@ -1,53 +0,0 @@
1
- import { useState, useEffect } from 'react';
2
- import { useQuery } from '@apollo/client';
3
- import { GET_All_RATING_STORE } from './queries';
4
-
5
- export const useRatingData = () => {
6
- const { data: dataRating } = useQuery(GET_All_RATING_STORE);
7
-
8
- const calculateTotalRatings = (ratings = []) => {
9
- return ratings.reduce(
10
- (total, rating) => ({
11
- rAppearance: total?.rAppearance + rating.rAppearance,
12
- rTasty: total?.rTasty + rating.rTasty,
13
- rGoodCondition: total?.rGoodCondition + rating.rGoodCondition,
14
- rGoodTemperature: total?.rGoodTemperature + rating.rGoodTemperature,
15
- }),
16
- {
17
- rAppearance: 0,
18
- rTasty: 0,
19
- rGoodCondition: 0,
20
- rGoodTemperature: 0,
21
- }
22
- );
23
- };
24
-
25
- const [totalRatings, setTotalRatings] = useState(
26
- calculateTotalRatings(dataRating?.getAllRating || [])
27
- );
28
-
29
- useEffect(() => {
30
- setTotalRatings(calculateTotalRatings(dataRating?.getAllRating || []));
31
- }, [dataRating]);
32
-
33
- const dataArr = [
34
- {
35
- name: 'Buena apariencia',
36
- value: totalRatings.rAppearance || 0,
37
- },
38
- {
39
- name: 'Es deliciosa',
40
- value: totalRatings.rTasty || 0,
41
- },
42
- {
43
- name: 'Buenas condiciones',
44
- value: totalRatings.rGoodCondition || 0,
45
- },
46
- {
47
- name: 'Buena temperatura',
48
- value: totalRatings.rGoodTemperature || 0,
49
- },
50
- ];
51
-
52
- return dataArr;
53
- };
@@ -1 +0,0 @@
1
- // Hola mundo