npm-pkg-hook 1.10.7 → 1.10.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.
- package/package.json +1 -1
- package/src/hooks/index.js +4 -0
- package/src/hooks/useAsideCart/index.js +0 -1
- package/src/hooks/useConnection/index.js +10 -8
- package/src/hooks/useCreateProduct/index.js +14 -15
- package/src/hooks/useDessert/index.js +1 -1
- package/src/hooks/useGetSalesAmountToday/index.js +31 -0
- package/src/hooks/useLocalBackendIp/index.js +34 -0
- package/src/hooks/useMouse/index.ts +8 -9
- package/src/hooks/useProductsFood/index.js +3 -3
- package/src/hooks/useSales/index.js +0 -1
- package/src/hooks/useSetImageProducts/index.js +1 -3
- package/src/hooks/useStore/index.js +2 -1
- package/src/hooks/useStore/queries.js +1 -1
- package/src/hooks/useUpsertGoal/index.js +68 -0
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -14,6 +14,7 @@ export * from './useStoreTable/index'
|
|
|
14
14
|
export * from './useSubscriptionValidation'
|
|
15
15
|
export * from './convertToMilitaryTime'
|
|
16
16
|
export * from './useRoles'
|
|
17
|
+
export * from './useLocalBackendIp'
|
|
17
18
|
export * from './statusOpenStores'
|
|
18
19
|
export * from './completeSchedules'
|
|
19
20
|
export * from './useLogout/helpers/BroadcastChannel'
|
|
@@ -130,3 +131,6 @@ export * from './useTotalProductsInStock/index'
|
|
|
130
131
|
export * from './useTotalAllSales/index'
|
|
131
132
|
export * from './useTotalProductsSolded'
|
|
132
133
|
export * from './useWeeklyStockMovement'
|
|
134
|
+
export * from './useSetImageProducts'
|
|
135
|
+
export * from './useGetSalesAmountToday'
|
|
136
|
+
export * from './useUpsertGoal'
|
|
@@ -9,7 +9,6 @@ import { useCart, useGetCart } from '../useCart'
|
|
|
9
9
|
import { useManageQueryParams } from '../useManageQueryParams'
|
|
10
10
|
import { calculateTotalPrice } from './helpers'
|
|
11
11
|
import { statusOpenStores } from '../statusOpenStores'
|
|
12
|
-
export * from './helpers'
|
|
13
12
|
|
|
14
13
|
export const useAsideCart = ({
|
|
15
14
|
openModalProduct = false,
|
|
@@ -10,13 +10,15 @@ export const useConnection = ({ setConnectionStatus }) => {
|
|
|
10
10
|
// Attaching event handler for the load event
|
|
11
11
|
// window.addEventListener('load', updateConnectionStatus);
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (typeof window !== 'undefined') {
|
|
14
|
+
// Attaching event handler for the online event
|
|
15
|
+
window.addEventListener('online', function () {
|
|
16
|
+
updateConnectionStatus()
|
|
17
|
+
})
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
// Attaching event handler for the offline event
|
|
20
|
+
window.addEventListener('offline', function () {
|
|
21
|
+
updateConnectionStatus()
|
|
22
|
+
})
|
|
23
|
+
}
|
|
22
24
|
}
|
|
@@ -13,8 +13,7 @@ import { useEditImageProduct } from './helpers/useEditImageProduct'
|
|
|
13
13
|
import { getCatProductsWithProduct } from './helpers/manageCacheDataCatProduct'
|
|
14
14
|
import { assignWith } from 'lodash'
|
|
15
15
|
import { UPDATE_IMAGE_PRODUCT_FOOD } from '../useSetImageProducts/queries'
|
|
16
|
-
import useSetImageProducts from '../useSetImageProducts'
|
|
17
|
-
export * from './helpers'
|
|
16
|
+
import { useSetImageProducts } from '../useSetImageProducts'
|
|
18
17
|
|
|
19
18
|
export const useCreateProduct = ({
|
|
20
19
|
router,
|
|
@@ -216,19 +215,19 @@ export const useCreateProduct = ({
|
|
|
216
215
|
ProDelivery: check?.desc ? 1 : 0
|
|
217
216
|
}
|
|
218
217
|
},
|
|
219
|
-
update (cache) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
218
|
+
// update (cache) {
|
|
219
|
+
// cache.modify({
|
|
220
|
+
// fields: {
|
|
221
|
+
// productFoodsAll (dataOld = []) {
|
|
222
|
+
// return cache.writeQuery({ query: GET_ALL_FOOD_PRODUCTS, data: dataOld })
|
|
223
|
+
// }
|
|
224
|
+
// // getCatProductsWithProduct () {
|
|
225
|
+
// // const updatedData = getCatProductsWithProduct(data, carProId)
|
|
226
|
+
// // return updatedData
|
|
227
|
+
// // }
|
|
228
|
+
// }
|
|
229
|
+
// })
|
|
230
|
+
// }
|
|
232
231
|
}).finally(() => {
|
|
233
232
|
setValues({
|
|
234
233
|
ProPrice: 0,
|
|
@@ -11,7 +11,7 @@ import { GET_EXTRAS_PRODUCT_FOOD_OPTIONAL } from '../useRemoveExtraProductFoodsO
|
|
|
11
11
|
import { transformDataToDessert } from './helpers'
|
|
12
12
|
import { useDeleteSubProductOptional } from '../useDeleteSubProductOptional'
|
|
13
13
|
import { useEditSubProductOptional } from '../useEditSubProductOptional'
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
export const useDessert = ({
|
|
16
16
|
pId = null,
|
|
17
17
|
initialData = null,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { gql, useQuery } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to get today's total sales amount.
|
|
5
|
+
*/
|
|
6
|
+
const GET_SALES_AMOUNT_TODAY = gql`
|
|
7
|
+
query GetSalesAmountToday {
|
|
8
|
+
getSalesAmountToday {
|
|
9
|
+
success
|
|
10
|
+
message
|
|
11
|
+
total
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Custom hook to fetch today's sales amount.
|
|
18
|
+
* @returns {{
|
|
19
|
+
* data: { success: boolean, message: string, total: number } | undefined,
|
|
20
|
+
* loading: boolean,
|
|
21
|
+
* error: any,
|
|
22
|
+
* refetch: () => void
|
|
23
|
+
* }}
|
|
24
|
+
*/
|
|
25
|
+
export const useGetSalesAmountToday = () => {
|
|
26
|
+
const { data, loading, error, refetch } = useQuery(GET_SALES_AMOUNT_TODAY, {
|
|
27
|
+
fetchPolicy: 'network-only'
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return [data?.getSalesAmountToday, { loading, error, refetch }]
|
|
31
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to get the local IP of the backend server.
|
|
5
|
+
*/
|
|
6
|
+
const GET_LOCAL_BACKEND_IP = gql`
|
|
7
|
+
query GetLocalBackendIp {
|
|
8
|
+
getLocalBackendIp
|
|
9
|
+
}
|
|
10
|
+
`
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Custom hook to fetch the local IP address of the backend server.
|
|
14
|
+
*
|
|
15
|
+
* @returns {Object} - Contains the IP string, loading state, and error.
|
|
16
|
+
*/
|
|
17
|
+
export const useLocalBackendIp = () => {
|
|
18
|
+
const {
|
|
19
|
+
data,
|
|
20
|
+
loading,
|
|
21
|
+
error
|
|
22
|
+
} = useQuery(GET_LOCAL_BACKEND_IP)
|
|
23
|
+
const port = process.env.URL_ADMIN_SERVER?.split(':')?.[2]
|
|
24
|
+
const buildUrlBackend = data?.getLocalBackendIp
|
|
25
|
+
? `http://${data.getLocalBackendIp}:${port}`
|
|
26
|
+
: null
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
urlBackend: buildUrlBackend,
|
|
30
|
+
ip: data?.getLocalBackendIp || null,
|
|
31
|
+
loading,
|
|
32
|
+
error
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from "react";
|
|
2
|
-
import type { MouseEvent } from "react";
|
|
3
2
|
|
|
4
|
-
export function useMouse
|
|
5
|
-
options: { resetOnExit
|
|
3
|
+
export function useMouse(
|
|
4
|
+
options: { resetOnExit } = { resetOnExit: false }
|
|
6
5
|
) {
|
|
7
6
|
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
8
7
|
|
|
9
|
-
const ref = useRef
|
|
8
|
+
const ref = useRef();
|
|
10
9
|
|
|
11
|
-
const setMousePosition = (event
|
|
10
|
+
const setMousePosition = (event) => {
|
|
12
11
|
if (ref.current) {
|
|
13
12
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
14
13
|
|
|
@@ -36,14 +35,14 @@ export function useMouse<T extends HTMLElement = any>(
|
|
|
36
35
|
|
|
37
36
|
useEffect(() => {
|
|
38
37
|
const element = ref?.current ? ref.current : document;
|
|
39
|
-
element.addEventListener("mousemove", setMousePosition
|
|
38
|
+
element.addEventListener("mousemove", setMousePosition);
|
|
40
39
|
if (options.resetOnExit)
|
|
41
|
-
element.addEventListener("mouseleave", resetMousePosition
|
|
40
|
+
element.addEventListener("mouseleave", resetMousePosition);
|
|
42
41
|
|
|
43
42
|
return () => {
|
|
44
|
-
element.removeEventListener("mousemove", setMousePosition
|
|
43
|
+
element.removeEventListener("mousemove", setMousePosition);
|
|
45
44
|
if (options.resetOnExit)
|
|
46
|
-
element.removeEventListener("mouseleave", resetMousePosition
|
|
45
|
+
element.removeEventListener("mouseleave", resetMousePosition);
|
|
47
46
|
};
|
|
48
47
|
}, [ref.current]);
|
|
49
48
|
|
|
@@ -65,9 +65,9 @@ export const useProductsFood = ({
|
|
|
65
65
|
|
|
66
66
|
const updatedProductsFood = productsFood.map(product => ({
|
|
67
67
|
...product,
|
|
68
|
-
existsInSale: dataSale.some(item => item.pId === product.pId)
|
|
69
|
-
}))
|
|
70
|
-
|
|
68
|
+
existsInSale: Array.isArray(dataSale) && dataSale.some(item => item.pId === product.pId)
|
|
69
|
+
}))
|
|
70
|
+
|
|
71
71
|
return [
|
|
72
72
|
updatedProductsFood, {
|
|
73
73
|
pagination: data?.productFoodsAll?.pagination || {},
|
|
@@ -30,7 +30,6 @@ import { useCatWithProduct } from './../useCatWithProduct/index'
|
|
|
30
30
|
import { useLogout } from '../useLogout'
|
|
31
31
|
import { filterProductsByCarProId, removeFunc } from './helpers'
|
|
32
32
|
export * from './useGetAllSales'
|
|
33
|
-
export * from './helpers'
|
|
34
33
|
|
|
35
34
|
export { GET_ALL_COUNT_SALES } from './queries'
|
|
36
35
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useMutation } from '@apollo/client'
|
|
2
2
|
import { UPDATE_IMAGE_PRODUCT_FOOD } from './queries'
|
|
3
3
|
|
|
4
|
-
const useSetImageProducts = () => {
|
|
4
|
+
export const useSetImageProducts = () => {
|
|
5
5
|
const [setImageProducts, { data, loading, error }] = useMutation(UPDATE_IMAGE_PRODUCT_FOOD)
|
|
6
6
|
|
|
7
7
|
const updateImageProducts = async (variables) => {
|
|
@@ -26,5 +26,3 @@ const useSetImageProducts = () => {
|
|
|
26
26
|
error
|
|
27
27
|
}]
|
|
28
28
|
}
|
|
29
|
-
|
|
30
|
-
export default useSetImageProducts
|
|
@@ -4,7 +4,7 @@ import { GET_ONE_STORE, GET_ONE_STORE_BY_ID } from './queries' // Reemplaza con
|
|
|
4
4
|
import { errorHandler } from '../../config/client'
|
|
5
5
|
import { useLogout } from '../useLogout'
|
|
6
6
|
|
|
7
|
-
export const useStore = ({ isClient = false, idStore = null } = {}) => {
|
|
7
|
+
export const useStore = ({ isClient = false, idStore = null, callback = () => {} } = {}) => {
|
|
8
8
|
const client = useApolloClient()
|
|
9
9
|
const [onClickLogout, { loading: load }] = useLogout()
|
|
10
10
|
|
|
@@ -24,6 +24,7 @@ export const useStore = ({ isClient = false, idStore = null } = {}) => {
|
|
|
24
24
|
setStore(cachedData.getStore)
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
+
callback(store)
|
|
27
28
|
}, [cachedData, store])
|
|
28
29
|
|
|
29
30
|
if (isClient && !!idStore) {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { gql, useMutation } from '@apollo/client'
|
|
2
|
+
import { GET_ONE_STORE } from '../useStore/queries'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* GraphQL mutation to upsert (create or update) the daily goal.
|
|
6
|
+
*/
|
|
7
|
+
const UPSERT_GOAL = gql`
|
|
8
|
+
mutation UpsertGoal($input: CreateGoalInput!) {
|
|
9
|
+
upsertGoal(input: $input) {
|
|
10
|
+
success
|
|
11
|
+
message
|
|
12
|
+
data {
|
|
13
|
+
idStore
|
|
14
|
+
dailyGoal
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Custom hook to handle the upsert of the daily goal.
|
|
22
|
+
* @param {Object} input - The goal data (e.g. dailyGoal).
|
|
23
|
+
* @returns {{
|
|
24
|
+
* upsertGoal: (input: { dailyGoal: number }) => void,
|
|
25
|
+
* data: { success: boolean, message: string, dailyGoal: number } | undefined,
|
|
26
|
+
* loading: boolean,
|
|
27
|
+
* error: any
|
|
28
|
+
* }}
|
|
29
|
+
*/
|
|
30
|
+
export const useUpsertGoal = ({
|
|
31
|
+
sendNotification = () => {}
|
|
32
|
+
} = {}) => {
|
|
33
|
+
const [upsertGoalMutation, { data, loading, error }] = useMutation(UPSERT_GOAL, {
|
|
34
|
+
onCompleted (data) {
|
|
35
|
+
const { upsertGoal } = data || {}
|
|
36
|
+
sendNotification({
|
|
37
|
+
title: upsertGoal.success ? 'Exito' : 'Error',
|
|
38
|
+
description: upsertGoal?.message || 'Meta actualizada correctamente',
|
|
39
|
+
backgroundColor: upsertGoal.success ? 'success' : 'warning'
|
|
40
|
+
})
|
|
41
|
+
},
|
|
42
|
+
update (cache, { data: { upsertGoal } }) {
|
|
43
|
+
if (!upsertGoal?.success) return
|
|
44
|
+
|
|
45
|
+
cache.modify({
|
|
46
|
+
fields: {
|
|
47
|
+
getStore (dataOld = []) {
|
|
48
|
+
return cache.writeQuery({
|
|
49
|
+
query: GET_ONE_STORE,
|
|
50
|
+
data: dataOld
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
const upsertGoal = (input) => {
|
|
58
|
+
upsertGoalMutation({
|
|
59
|
+
variables: { input }
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return [upsertGoal, {
|
|
64
|
+
data: data?.upsertGoal,
|
|
65
|
+
loading,
|
|
66
|
+
error
|
|
67
|
+
}]
|
|
68
|
+
}
|