npm-pkg-hook 1.1.5 → 1.1.9

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 (144) hide show
  1. package/.eslintrc.js +19 -113
  2. package/.eslintrc.json +127 -108
  3. package/.github/pull_request_template.md +17 -17
  4. package/.github/workflows/pepeline.yaml +29 -29
  5. package/next.config.js +2 -5
  6. package/package.json +27 -24
  7. package/script.txt +6 -6
  8. package/src/config/client/errors.js +14 -14
  9. package/src/config/client/index.js +1 -1
  10. package/src/hooks/getCategoriesWithProduct/helpers/index.js +7 -0
  11. package/src/hooks/getCategoriesWithProduct/index.js +62 -0
  12. package/src/hooks/getSession/index.js +18 -18
  13. package/src/hooks/index.js +13 -9
  14. package/src/hooks/useAcumulateDate/index.js +1 -1
  15. package/src/hooks/useAnimationFrame/index.js +45 -45
  16. package/src/hooks/useAsideCart/helpers/index.js +22 -0
  17. package/src/hooks/useAsideCart/index.js +156 -0
  18. package/src/hooks/useAsideCart/queries.js +10 -0
  19. package/src/hooks/useBanner/index.js +11 -11
  20. package/src/hooks/useCart/index.js +2 -0
  21. package/src/hooks/useCart/queries.js +164 -0
  22. package/src/hooks/useCart/useCart/helpers/index.js +75 -0
  23. package/src/hooks/useCart/useCart/index.js +411 -0
  24. package/src/hooks/useCart/useGetCart/index.js +31 -0
  25. package/src/hooks/useCatWithProduct/index.js +15 -15
  26. package/src/hooks/useCatWithProduct/queries.js +1 -1
  27. package/src/hooks/useCatWithProductClient/index.js +48 -0
  28. package/src/hooks/useCatWithProductClient/queries.js +55 -0
  29. package/src/hooks/useCategoriesProduct/index.js +12 -12
  30. package/src/hooks/useCategoriesProduct/queries.js +16 -16
  31. package/src/hooks/useCategoryInStore/index.js +39 -36
  32. package/src/hooks/useCategoryInStore/queries.js +78 -78
  33. package/src/hooks/useCategoryStore/index.js +2 -2
  34. package/src/hooks/useChartData/index.js +159 -156
  35. package/src/hooks/useChartData/useChartData/index.js +199 -197
  36. package/src/hooks/useChartData/useChartDataAllOrders/index.js +94 -94
  37. package/src/hooks/useCheckbox/index.js +115 -115
  38. package/src/hooks/useClients/index.js +12 -14
  39. package/src/hooks/useClients/queries.js +1 -1
  40. package/src/hooks/useConnection/index.js +20 -21
  41. package/src/hooks/useCreateProduct/helpers/useEditImageProduct/index.js +6 -2
  42. package/src/hooks/useCreateProduct/index.js +22 -19
  43. package/src/hooks/useDeleteSubProductOptional/index.js +31 -30
  44. package/src/hooks/useDeleteSubProductOptional/queries.js +10 -10
  45. package/src/hooks/useDessert/helpers/index.js +51 -51
  46. package/src/hooks/useDessert/index.js +56 -65
  47. package/src/hooks/useDevices/index.js +35 -36
  48. package/src/hooks/useDevices/queries.js +19 -19
  49. package/src/hooks/useDropzone/index.js +94 -79
  50. package/src/hooks/useDynamicAuth/index.js +13 -13
  51. package/src/hooks/useDynamicAuth/queries.js +24 -24
  52. package/src/hooks/useEmployee/queries.js +1 -1
  53. package/src/hooks/useEvent/index.js +33 -33
  54. package/src/hooks/useFavoriteStores/index.js +19 -0
  55. package/src/hooks/useFavoriteStores/queries.js +47 -0
  56. package/src/hooks/useFetchJson/index.js +25 -25
  57. package/src/hooks/useFingerprintjs/index.js +172 -176
  58. package/src/hooks/useFormTools/index.js +12 -11
  59. package/src/hooks/useFormatDate/index.js +20 -21
  60. package/src/hooks/useFormatNumberPhone/index.js +9 -9
  61. package/src/hooks/useFullScreenMode/index.js +65 -65
  62. package/src/hooks/useGenerateNumberArray/index.js +17 -17
  63. package/src/hooks/useGetExtProductFoodsSubOptionalAll/index.js +14 -0
  64. package/src/hooks/useGetFoodRecomended/index.js +33 -0
  65. package/src/hooks/useGetFoodRecomended/queries.js +47 -0
  66. package/src/hooks/useGetMinPrice/index.js +8 -0
  67. package/src/hooks/useGetMinPrice/queries.js +7 -0
  68. package/src/hooks/useGetOneStoreRating/index.js +40 -0
  69. package/src/hooks/useGetOneStoreRating/queries.js +18 -0
  70. package/src/hooks/useGoogleLogin/index.js +160 -161
  71. package/src/hooks/useHover/index.js +29 -29
  72. package/src/hooks/useImageOptimization/index.js +15 -15
  73. package/src/hooks/useImageWeight/index.js +18 -19
  74. package/src/hooks/useImagesStore/index.js +139 -140
  75. package/src/hooks/useImagesStore/queries.js +19 -18
  76. package/src/hooks/useInnerHtml/index.js +39 -38
  77. package/src/hooks/useIntersection/index.js +4 -4
  78. package/src/hooks/useKeypress/index.js +28 -28
  79. package/src/hooks/useLazyScript/index.js +35 -36
  80. package/src/hooks/useLocalSorage/index.js +2 -2
  81. package/src/hooks/useLocationNavigate/index.js +54 -54
  82. package/src/hooks/useLogout/index.js +24 -24
  83. package/src/hooks/useManageQueryParams/index.js +36 -37
  84. package/src/hooks/useMobile/index.js +39 -38
  85. package/src/hooks/useMutateHeight/index.js +15 -16
  86. package/src/hooks/useOrderClient/index.js +5 -0
  87. package/src/hooks/useOrders/index.js +10 -16
  88. package/src/hooks/useOrders/queries.js +1 -1
  89. package/src/hooks/useProductsFood/index.js +32 -32
  90. package/src/hooks/useProductsFood/queriesStore.js +49 -48
  91. package/src/hooks/useProductsFood/useEditProduct.js +2 -4
  92. package/src/hooks/useProductsFood/usetagsProducts.js +83 -83
  93. package/src/hooks/useProviders/index.js +3 -3
  94. package/src/hooks/useProviders/queries.js +31 -31
  95. package/src/hooks/useProviders/useProvidersCreateStore/index.js +12 -13
  96. package/src/hooks/useProviders/useProvidersDataStore/index.js +24 -24
  97. package/src/hooks/useProvidersStore/index.js +24 -24
  98. package/src/hooks/useProvidersStore/queries.js +31 -31
  99. package/src/hooks/useRatingArrayData/index.js +54 -0
  100. package/src/hooks/{useRatingData → useRatingArrayData}/queries.js +19 -18
  101. package/src/hooks/useReactToPrint/index.js +1120 -1098
  102. package/src/hooks/useRemoveExtraProductFoodsOptional/index.js +23 -23
  103. package/src/hooks/useRemoveExtraProductFoodsOptional/queries.js +48 -48
  104. package/src/hooks/useReport/index.js +9 -9
  105. package/src/hooks/useReport/queries.js +1 -1
  106. package/src/hooks/useRestaurant/index.js +19 -19
  107. package/src/hooks/useRestaurant/queries.js +80 -80
  108. package/src/hooks/useSales/index.js +476 -451
  109. package/src/hooks/useSales/queries.js +14 -15
  110. package/src/hooks/useSales/useGetAllSales/index.js +25 -25
  111. package/src/hooks/useSales/useTotalSales.js +18 -18
  112. package/src/hooks/useSaveAvailableProduct/helpers/index.js +29 -29
  113. package/src/hooks/useSaveAvailableProduct/index.js +16 -16
  114. package/src/hooks/useSaveAvailableProduct/queries.js +1 -1
  115. package/src/hooks/useSchedule/index.js +33 -36
  116. package/src/hooks/useSchedule/index.jsx +22 -22
  117. package/src/hooks/useSchedule/queries.js +34 -35
  118. package/src/hooks/useScheduleData/index.js +123 -171
  119. package/src/hooks/useScroll/index.js +56 -57
  120. package/src/hooks/useScrollRotate/index.js +16 -14
  121. package/src/hooks/useSetSession/index.js +16 -16
  122. package/src/hooks/useSetState/index.js +3 -3
  123. package/src/hooks/useStatusOpenStore/helpers/index.js +101 -102
  124. package/src/hooks/useStatusOpenStore/index.js +172 -173
  125. package/src/hooks/useStatusOrdersClient/helpers/index.js +14 -0
  126. package/src/hooks/useStatusOrdersClient/index.js +17 -0
  127. package/src/hooks/useStatusOrdersClient/queries.js +80 -0
  128. package/src/hooks/useStore/index.js +40 -25
  129. package/src/hooks/useStore/queries.js +162 -136
  130. package/src/hooks/useStoreCalendar/index.js +5 -7
  131. package/src/hooks/useStoreContacts/index.js +16 -16
  132. package/src/hooks/useStoreContacts/queries.js +1 -1
  133. package/src/hooks/useTimeAgo/useTimeAgo.js +39 -39
  134. package/src/hooks/useUpdateCart/index.js +34 -28
  135. package/src/hooks/useUpdateExistingOrders/index.js +35 -35
  136. package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +38 -37
  137. package/src/hooks/useUser/index.js +1 -1
  138. package/src/hooks/useUser/queries.js +1 -1
  139. package/src/hooks/useWindowSize/index.js +38 -38
  140. package/src/mock/dessert/index.js +16 -16
  141. package/src/mock/index.js +1 -2
  142. package/src/utils/index.js +42 -45
  143. package/src/hooks/useRatingData/index.js +0 -53
  144. package/src/hooks/useSalesClient/index.js +0 -1
@@ -0,0 +1,62 @@
1
+ import { jaccardSimilarity } from './helpers'
2
+
3
+ /**
4
+ * Get categories that contain products with names similar to the given product name.
5
+ * Uses the Jaccard similarity coefficient for string comparison.
6
+ * @param {Array} data - The array of categories with product information.
7
+ * @param {string} productName - The name of the product to search for.
8
+ * @param {number} similarityThreshold - The minimum similarity threshold for products (0.0 to 1.0).
9
+ * @returns {Array} - An array of categories containing similar products.
10
+ */
11
+ export const getCategoriesWithProduct = (
12
+ data = [],
13
+ productName = '',
14
+ similarityThreshold = 0.0) => {
15
+ // Validate input data
16
+ if (!data || !Array.isArray(data)) {
17
+ return data || []
18
+ }
19
+
20
+ if (typeof productName !== 'string' || productName.trim() === '') {
21
+ return data
22
+ }
23
+
24
+ // Convert product name to lowercase for case-insensitive comparison
25
+ const productNameLower = productName.toLowerCase()
26
+
27
+ // Use a Set to store unique product names for better performance
28
+ const uniqueProductNames = new Set()
29
+
30
+ // Store unique product names in the Set
31
+ data.forEach(category => {
32
+ if (category?.productFoodsAll && Array.isArray(category.productFoodsAll)) {
33
+ category.productFoodsAll.forEach(product => {
34
+ const productLower = product.pName.toLowerCase()
35
+ uniqueProductNames.add(productLower)
36
+ })
37
+ }
38
+ })
39
+
40
+ // Filter categories that contain products with names similar to the given product name
41
+ const matchingCategories = data.filter(category => {
42
+ if (category?.productFoodsAll && Array.isArray(category.productFoodsAll)) {
43
+ const products = category.productFoodsAll.some(product => {
44
+ const productLower = product?.pName?.toLowerCase()
45
+ return jaccardSimilarity(productNameLower, productLower) >= similarityThreshold
46
+ })
47
+ return products
48
+ }
49
+ return false
50
+ })
51
+
52
+ // Find similar products in each matching category
53
+ const findProduct = matchingCategories?.map(categories => {
54
+ const similarProducts = categories.productFoodsAll.filter(product => {
55
+ const productLower = product?.pName?.toLowerCase()
56
+ return productLower.includes(productNameLower)
57
+ })
58
+ return similarProducts.length > 0 ? { ...categories, productFoodsAll: similarProducts } : null
59
+ }).filter(Boolean)
60
+
61
+ return findProduct
62
+ }
@@ -1,18 +1,18 @@
1
- export const getSession = async () => {
2
- try {
3
- const res = await fetch(`${process.env.URL_BASE}api/auth/getAuth`,
4
- { method: 'GET', headers: { 'Content-Type': 'application/json' } })
5
- const data = await res.json()
6
- const { ok, ok: { user }, isSession } = data || {}
7
- const { deviceid, token } = user || {}
8
- return {
9
- user,
10
- ok,
11
- isSession,
12
- deviceid,
13
- token
14
- }
15
- } catch (e) {
16
- return e
17
- }
18
- }
1
+ export const getSession = async () => {
2
+ try {
3
+ const res = await fetch(`${process.env.URL_BASE}/api/auth/getAuth`,
4
+ { method: 'GET', headers: { 'Content-Type': 'application/json' } })
5
+ const data = await res.json()
6
+ const { ok, ok: { user }, isSession } = data || {}
7
+ const { deviceid, token } = user || {}
8
+ return {
9
+ user,
10
+ ok,
11
+ isSession,
12
+ deviceid,
13
+ token
14
+ }
15
+ } catch (e) {
16
+ return e
17
+ }
18
+ }
@@ -6,24 +6,24 @@ export * from './useCategoryStore'
6
6
  export * from './useCatWithProduct'
7
7
  export * from './useManageQueryParams'
8
8
  export * from './useCategoriesProduct'
9
- export * from './useChartData'
10
9
  export * from './useLogout'
11
10
  export * from './useStatusOpenStore'
12
- export * from './useSchedule'
13
11
  export * from './useScheduleData'
14
- export * from './useImagesStore'
12
+ export * from './useOrders'
15
13
  export * from './useFingerprintjs'
16
14
  export * from './useEmployee'
17
15
  export * from './useCheckbox'
18
16
  export * from './useRemoveExtraProductFoodsOptional'
19
17
  export * from './useDeleteSubProductOptional'
20
- export * from './useRatingData'
18
+ export * from './useGetOneStoreRating'
19
+ export * from './useFavoriteStores'
20
+ export * from './useAsideCart'
21
+ export * from './useRatingArrayData'
21
22
  export * from './useChartData'
22
23
  export * from './useDevices'
23
- export * from './useSales'
24
24
  export * from './useClients'
25
25
  export * from './useScroll'
26
- export * from './useOrders'
26
+ export * from './useStatusOrdersClient'
27
27
  export * from './useUpdateExistingOrders'
28
28
  export * from './useConnection'
29
29
  export * from './useCreateProduct'
@@ -51,19 +51,23 @@ export * from './useProductsFood'
51
51
  export * from './useProductsFood/usetagsProducts'
52
52
  export * from './useReactToPrint'
53
53
  export * from './useReport'
54
- // hola
54
+ export * from './useSales/useTotalSales'
55
+ export * from './useOrderClient'
55
56
  export * from './useStoreContacts'
56
57
  export * from './useRestaurant'
57
58
  export * from './useSales'
58
59
  export * from './useSales/useGetSale'
59
- export * from './useSales/useTotalSales'
60
+ export * from './useGetMinPrice'
61
+ export * from './useCatWithProductClient'
62
+ export * from './useGetFoodRecomended'
60
63
  export * from './useSaveAvailableProduct'
61
64
  export * from './useSchedule'
62
65
  export * from './useSetState'
63
66
  export * from './useStore'
64
67
  export * from './useStoreCalendar'
68
+ export * from './getCategoriesWithProduct'
65
69
  export * from './useTimeAgo/useTimeAgo'
66
70
  export * from './useUpdateCart'
67
71
  export * from './useUpdateExtProductFoodsSubOptional'
68
72
  export * from './useUser'
69
-
73
+ export * from './useCart'
@@ -1,4 +1,3 @@
1
-
2
1
  const data = [
3
2
  { x: '2021-10-17T14:38:45.540Z', y: 2 }
4
3
  ]
@@ -13,4 +12,5 @@ export function groupDates (arr) {
13
12
  }, 0)
14
13
  return total
15
14
  }
15
+ // eslint-disable-next-line no-unused-vars
16
16
  const result = groupDates(data)
@@ -1,45 +1,45 @@
1
- import { useEffect, useRef } from "react"
2
-
3
- export const useAnimationFrame = (callback, start, end, duration = 1000) => {
4
- const functionRef = useRef()
5
- const delta = Math.abs(start - end)
6
- const frameCount = Math.ceil(60 * (duration / 1000))
7
- const iteration = useRef(frameCount)
8
- useEffect(() => {
9
- const animate = (rafId) => {
10
- if (iteration.current <= 0) {
11
- cancelAnimationFrame(rafId)
12
- iteration.current = frameCount
13
- }
14
-
15
- callback(Math.max(delta / iteration.current, 1))
16
- iteration.current--
17
- }
18
-
19
- if (delta > 0) functionRef.current = requestAnimationFrame(animate)
20
-
21
- return () => {return cancelAnimationFrame(functionRef.current)}
22
- }, [callback, delta, frameCount, iteration])
23
- }
24
-
25
- // const Counter = ({ numeral = 0 }) => {
26
- // const [currentValue, setCurrentValue] = useState(0)
27
- // const fxOperator = currentValue > numeral ? 'subtraction' : 'addition'
28
-
29
- // useAnimationFrame(
30
- // (diffValue) => {
31
- // // Pass on a function to the setter of the state
32
- // // to make sure we always have the latest state
33
- // setCurrentValue((prevCount) => {
34
- // return fxOperator === 'addition'
35
- // ? prevCount + diffValue
36
- // : prevCount - diffValue
37
- // }
38
- // )
39
- // },
40
- // currentValue,
41
- // numeral,
42
- // 300
43
- // )
44
- // return <>{new Intl.NumberFormat().format(Math.round(currentValue))}</>
45
- // }
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export const useAnimationFrame = (callback, start, end, duration = 1000) => {
4
+ const functionRef = useRef()
5
+ const delta = Math.abs(start - end)
6
+ const frameCount = Math.ceil(60 * (duration / 1000))
7
+ const iteration = useRef(frameCount)
8
+ useEffect(() => {
9
+ const animate = (rafId) => {
10
+ if (iteration.current <= 0) {
11
+ cancelAnimationFrame(rafId)
12
+ iteration.current = frameCount
13
+ }
14
+
15
+ callback(Math.max(delta / iteration.current, 1))
16
+ iteration.current--
17
+ }
18
+
19
+ if (delta > 0) functionRef.current = requestAnimationFrame(animate)
20
+
21
+ return () => { return cancelAnimationFrame(functionRef.current) }
22
+ }, [callback, delta, frameCount, iteration])
23
+ }
24
+
25
+ // const Counter = ({ numeral = 0 }) => {
26
+ // const [currentValue, setCurrentValue] = useState(0)
27
+ // const fxOperator = currentValue > numeral ? 'subtraction' : 'addition'
28
+
29
+ // useAnimationFrame(
30
+ // (diffValue) => {
31
+ // // Pass on a function to the setter of the state
32
+ // // to make sure we always have the latest state
33
+ // setCurrentValue((prevCount) => {
34
+ // return fxOperator === 'addition'
35
+ // ? prevCount + diffValue
36
+ // : prevCount - diffValue
37
+ // }
38
+ // )
39
+ // },
40
+ // currentValue,
41
+ // numeral,
42
+ // 300
43
+ // )
44
+ // return <>{new Intl.NumberFormat().format(Math.round(currentValue))}</>
45
+ // }
@@ -0,0 +1,22 @@
1
+ export const calculateTotalPrice = (shoppingCardData) => {
2
+ if (Array.isArray(shoppingCardData) && shoppingCardData.length) {
3
+ return shoppingCardData.reduce((accumulator, currentItem) => {
4
+ const { productFood = {}, cantProducts } = currentItem || {}
5
+ const { ProPrice = 0, ValueDelivery = 0 } = productFood || {}
6
+
7
+ const pricePerProduct = ProPrice * cantProducts
8
+ const deliveryCost = ValueDelivery || 0
9
+ const ExtProductFoodsAll = currentItem.ExtProductFoodsAll || []
10
+
11
+ const extraPriceSum = ExtProductFoodsAll.reduce((extraAccumulator, extraFood) => {
12
+ if (Number.isInteger(extraFood.newExtraPrice)) {
13
+ return extraAccumulator + extraFood.newExtraPrice
14
+ }
15
+ return extraAccumulator
16
+ }, 0)
17
+
18
+ return accumulator + pricePerProduct + deliveryCost + extraPriceSum
19
+ }, 0)
20
+ }
21
+ return 0
22
+ }
@@ -0,0 +1,156 @@
1
+ import {
2
+ useState,
3
+ useEffect,
4
+ useMemo
5
+ } from 'react'
6
+ import { useMutation } from '@apollo/client'
7
+ import { DELETE_ONE_ITEM_SHOPPING_PRODUCT } from './queries'
8
+ import { useCart, useGetCart } from '../useCart'
9
+ import { useManageQueryParams } from '../useManageQueryParams'
10
+ import { calculateTotalPrice } from './helpers'
11
+ export * from './helpers'
12
+ /**
13
+ * Custom hook for managing the shopping cart functionality.
14
+ * @param {Object} props - Props to control various UI elements.
15
+ * @param {function} props.setCountItemProduct - Function to set the count of items in the cart.
16
+ * @param {function} props.setAlertBox - Function to set an alert message.
17
+ * @param {function} props.handleMenu - Function to handle cart menu visibility.
18
+ * @returns {Object} An object with various shopping cart-related functions and data.
19
+ */
20
+ export const useAsideCart = ({
21
+ openModalProduct = false,
22
+ setCountItemProduct = () => { },
23
+ setAlertBox = () => { },
24
+ setOpenModalProduct = () => { },
25
+ handleMenu = () => { }
26
+ } = {}) => {
27
+ const { getOneProduct } = useCart({
28
+ handleMenu,
29
+ openModalProduct,
30
+ setOpenModalProduct
31
+ })
32
+
33
+ const { handleQuery } = useManageQueryParams()
34
+
35
+ const [totalProductPrice, setTotalProductPrice] = useState(0)
36
+
37
+ const [dataShoppingCard, { loading }] = useGetCart({ setCountItemProduct })
38
+ console.log({ dataShoppingCard })
39
+
40
+ // Lógica de transformación de los datos
41
+ const result2 = useMemo(() => {
42
+ if (!loading && dataShoppingCard) {
43
+ return dataShoppingCard.reduce((r, a) => {
44
+ const storeName = a.getStore?.storeName
45
+ if (storeName) {
46
+ r[storeName] = r[storeName] || []
47
+ r[storeName].push(a)
48
+ }
49
+ return r
50
+ }, {})
51
+ }
52
+ return {}
53
+ }, [loading, dataShoppingCard])
54
+
55
+ // Obtener dataProduct2 directamente
56
+ const key = useMemo(() => {
57
+ return Object.keys(result2)
58
+ }, [result2])
59
+
60
+ useEffect(() => {
61
+ const totalPrice = calculateTotalPrice(dataShoppingCard)
62
+ setTotalProductPrice(Math.abs(totalPrice))
63
+ }, [dataShoppingCard])
64
+
65
+ console.log(dataShoppingCard)
66
+ const [deleteOneItem] = useMutation(DELETE_ONE_ITEM_SHOPPING_PRODUCT, {
67
+ onCompleted: data => {
68
+ setAlertBox({ message: data?.deleteOneItem?.message })
69
+
70
+ if (dataShoppingCard?.length === 1 && data?.deleteOneItem?.success) {
71
+ setAlertBox({ message: 'Tu carrito está vacío' }) // Ajusta el mensaje en español
72
+ handleMenu(false) // Oculta el menú del carrito
73
+ }
74
+ }
75
+ })
76
+
77
+ const handleEditProduct = async (item) => {
78
+ const pId = item?.pId || null
79
+ if (pId) handleQuery('plato', pId)
80
+ if (pId) {
81
+ const product = { pId, intoCart: true }
82
+ getOneProduct(product)
83
+ }
84
+ }
85
+ /**
86
+ * Handle the deletion of a shopping cart item.
87
+ * @param {Object} item - The item to be deleted from the shopping cart.
88
+ */
89
+ const handleDeleteItemShopping = async (item) => {
90
+ try {
91
+ const { cState, ShoppingCard } = item
92
+ await deleteOneItem({
93
+ variables: {
94
+ cState,
95
+ ShoppingCard
96
+ },
97
+ update: (cache, { data }) => {
98
+ const success = data?.deleteOneItem?.success
99
+ if (success && ShoppingCard) {
100
+ cache.modify({
101
+ fields: {
102
+ getAllShoppingCard (existingCart, { readField }) {
103
+ if (Array.isArray(existingCart) && existingCart) {
104
+ if (existingCart.length === 1) {
105
+ setCountItemProduct(0)
106
+ }
107
+ const updatedCart = {
108
+ ...existingCart,
109
+ ...existingCart?.filter(product =>
110
+ readField('ShoppingCard', product) !== ShoppingCard
111
+ )
112
+ }
113
+ if (typeof updatedCart === 'object' && updatedCart !== null) {
114
+ const newLength = Object.keys(updatedCart)
115
+ if (updatedCart && newLength) {
116
+ setCountItemProduct(Object.keys(updatedCart).length)
117
+ }
118
+ }
119
+ return updatedCart
120
+ } else {
121
+ return []
122
+ }
123
+ }
124
+ }
125
+ })
126
+ }
127
+ }
128
+ })
129
+ } catch (error) {
130
+ setAlertBox({ message: 'Error borranto el item. Por favor intenta nuevamente.', color: 'error' })
131
+ }
132
+ }
133
+ /**
134
+ * Calculate the total price of a product.
135
+ * @param {number} ProPrice - The price of the product.
136
+ * @param {number} ProDelivery - The delivery cost of the product.
137
+ * @param {number} cant - The quantity of the product.
138
+ * @returns {number} The calculated total price.
139
+ */
140
+ const sumProduct = (ProPrice, ProDelivery, cant) => {
141
+ const price = parseInt(ProPrice)
142
+ const priceFinal = cant * price
143
+ const delivery = parseInt(ProDelivery || 0)
144
+ return delivery ? priceFinal + delivery : priceFinal
145
+ }
146
+
147
+ return {
148
+ key,
149
+ totalProductPrice,
150
+ result2,
151
+ dataShoppingCard,
152
+ handleDeleteItemShopping,
153
+ handleEditProduct,
154
+ sumProduct
155
+ }
156
+ }
@@ -0,0 +1,10 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const DELETE_ONE_ITEM_SHOPPING_PRODUCT = gql`
4
+ mutation deleteOneItem($cState: Int, $ShoppingCard: ID) {
5
+ deleteOneItem(cState: $cState, ShoppingCard: $ShoppingCard){
6
+ success
7
+ message
8
+ }
9
+ }
10
+ `
@@ -5,15 +5,15 @@ import { useStore } from '../useStore'
5
5
  export const useBanner = () => {
6
6
  const [store, { loading: loaStore }] = useStore()
7
7
 
8
- const {
9
- data,
10
- loading,
11
- error
12
- } = useQuery(GET_ONE_BANNER_STORE, {
13
- context: { clientName: 'admin-server' },
14
- variables: {
15
- idStore: !loaStore && ''
16
- }
17
- })
18
- return [data?.getOneBanners, { loading, error }]
8
+ const {
9
+ data,
10
+ loading,
11
+ error
12
+ } = useQuery(GET_ONE_BANNER_STORE, {
13
+ context: { clientName: 'admin-server' },
14
+ variables: {
15
+ idStore: !loaStore && store?.idStore
16
+ }
17
+ })
18
+ return [data?.getOneBanners, { loading, error }]
19
19
  }
@@ -0,0 +1,2 @@
1
+ export * from './useCart'
2
+ export * from './useGetCart'
@@ -0,0 +1,164 @@
1
+ import { gql } from '@apollo/client';
2
+
3
+ export const CREATE_SHOPPING_CARD = gql`
4
+ mutation registerShoppingCard(
5
+ $input: IShoppingCard
6
+ $idSubArray: IID_SUB_ITEMS
7
+ ) {
8
+ registerShoppingCard(input: $input, idSubArray: $idSubArray) {
9
+ ShoppingCard
10
+ id
11
+ pId
12
+ subProductsId
13
+ ShoppingCardRefCode
14
+ uuid
15
+ discountCardProduct
16
+ idUser
17
+ cName
18
+ idStore
19
+ cState
20
+ cDatCre
21
+ cDatMod
22
+ csDescription
23
+ cantProducts
24
+ comments
25
+ }
26
+ }
27
+ `
28
+
29
+ export const GET_ALL_SHOPPING_CARD = gql`
30
+ query getAllShoppingCard {
31
+ getAllShoppingCard {
32
+ ShoppingCard
33
+ cState
34
+ idStore
35
+ refCodePid
36
+ pId
37
+ comments
38
+ salesExtProductFoodOptional {
39
+ pId
40
+ opExPid
41
+ OptionalProName
42
+ state
43
+ code
44
+ required
45
+ numbersOptionalOnly
46
+ pDatCre
47
+ pDatMod
48
+ saleExtProductFoodsSubOptionalAll {
49
+ pId
50
+ opExPid
51
+ idStore
52
+ opSubExPid
53
+ OptionalSubProName
54
+ exCodeOptionExtra
55
+ exCode
56
+ state
57
+ pDatCre
58
+ pDatMod
59
+ }
60
+ }
61
+ ExtProductFoodsAll {
62
+ pId
63
+ exPid
64
+ exState
65
+ extraName
66
+ extraPrice
67
+ quantity
68
+ newExtraPrice
69
+ state
70
+ pDatCre
71
+ pDatMod
72
+ }
73
+ productFood {
74
+ pId
75
+ carProId
76
+ sizeId
77
+ colorId
78
+ idStore
79
+ cId
80
+ caId
81
+ dId
82
+ ctId
83
+ tpId
84
+ fId
85
+ pName
86
+ ProPrice
87
+ ProDescuento
88
+ ProUniDisponibles
89
+ ProDescription
90
+ ValueDelivery
91
+ ProProtegido
92
+ ProAssurance
93
+ ProImage
94
+ ProStar
95
+ ProWidth
96
+ ProHeight
97
+ ProLength
98
+ ProWeight
99
+ ProQuantity
100
+ ProOutstanding
101
+ ProDelivery
102
+ ProVoltaje
103
+ pState
104
+ sTateLogistic
105
+ pDatCre
106
+ pDatMod
107
+ }
108
+ cantProducts
109
+ getStore {
110
+ idStore
111
+ cId
112
+ id
113
+ dId
114
+ ctId
115
+ catStore
116
+ neighborhoodStore
117
+ Viaprincipal
118
+ storeOwner
119
+ storeName
120
+ emailStore
121
+ storePhone
122
+ socialRaz
123
+ Image
124
+ banner
125
+ documentIdentifier
126
+ uPhoNum
127
+ ULocation
128
+ upLat
129
+ upLon
130
+ uState
131
+ siteWeb
132
+ description
133
+ NitStore
134
+ typeRegiments
135
+ typeContribute
136
+ secVia
137
+ addressStore
138
+ createdAt
139
+ pais {
140
+ cId
141
+ cName
142
+ cCalCod
143
+ cState
144
+ cDatCre
145
+ cDatMod
146
+ }
147
+ city {
148
+ ctId
149
+ dId
150
+ cName
151
+ cState
152
+ }
153
+ department {
154
+ dId
155
+ cId
156
+ dName
157
+ dState
158
+ dDatCre
159
+ dDatMod
160
+ }
161
+ }
162
+ }
163
+ }
164
+ `