npm-pkg-hook 1.10.8 → 1.11.0
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 +5 -0
- package/src/hooks/useAsideCart/index.js +0 -1
- package/src/hooks/useCreateProduct/index.js +14 -15
- package/src/hooks/useDashboardComponents/index.js +50 -0
- package/src/hooks/useDessert/index.js +1 -1
- package/src/hooks/useGetSalesAmountToday/index.js +31 -0
- package/src/hooks/useLocalBackendIp/index.js +10 -1
- package/src/hooks/useModules/index.js +15 -2
- 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/useUpdateModuleOrder/index.js +37 -0
- package/src/hooks/useUpsertGoal/index.js +68 -0
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -131,3 +131,8 @@ export * from './useTotalProductsInStock/index'
|
|
|
131
131
|
export * from './useTotalAllSales/index'
|
|
132
132
|
export * from './useTotalProductsSolded'
|
|
133
133
|
export * from './useWeeklyStockMovement'
|
|
134
|
+
export * from './useSetImageProducts'
|
|
135
|
+
export * from './useGetSalesAmountToday'
|
|
136
|
+
export * from './useUpsertGoal'
|
|
137
|
+
export * from './useDashboardComponents'
|
|
138
|
+
export * from './useUpdateModuleOrder'
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useQuery, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL query to fetch dashboard components
|
|
5
|
+
*/
|
|
6
|
+
const GET_DASHBOARD_COMPONENTS = gql`
|
|
7
|
+
query dashboardComponents {
|
|
8
|
+
dashboardComponents {
|
|
9
|
+
id
|
|
10
|
+
idStore
|
|
11
|
+
idUser
|
|
12
|
+
coordinates
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
`
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Custom hook to fetch dashboard components
|
|
19
|
+
* @returns {{
|
|
20
|
+
* data: Array,
|
|
21
|
+
* loading: boolean,
|
|
22
|
+
* error: any,
|
|
23
|
+
* refetch: () => void
|
|
24
|
+
* }}
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
export const useDashboardComponents = ({ callback = () => {} }) => {
|
|
28
|
+
const {
|
|
29
|
+
data,
|
|
30
|
+
loading,
|
|
31
|
+
error,
|
|
32
|
+
refetch
|
|
33
|
+
} = useQuery(GET_DASHBOARD_COMPONENTS, {
|
|
34
|
+
fetchPolicy: 'cache-and-network',
|
|
35
|
+
onCompleted: (data) => {
|
|
36
|
+
if (Array.isArray(data?.dashboardComponents)) {
|
|
37
|
+
try {
|
|
38
|
+
callback(data.dashboardComponents ?? [])
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error('Error executing callback:', err)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
onError: (err) => {
|
|
45
|
+
console.error('Error fetching dashboard components:', err)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return { data: data?.dashboardComponents ?? [], loading, error, refetch }
|
|
50
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -15,9 +15,18 @@ const GET_LOCAL_BACKEND_IP = gql`
|
|
|
15
15
|
* @returns {Object} - Contains the IP string, loading state, and error.
|
|
16
16
|
*/
|
|
17
17
|
export const useLocalBackendIp = () => {
|
|
18
|
-
const {
|
|
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
|
|
19
27
|
|
|
20
28
|
return {
|
|
29
|
+
urlBackend: buildUrlBackend,
|
|
21
30
|
ip: data?.getLocalBackendIp || null,
|
|
22
31
|
loading,
|
|
23
32
|
error
|
|
@@ -21,7 +21,10 @@ const GET_MODULES = gql`
|
|
|
21
21
|
}
|
|
22
22
|
`
|
|
23
23
|
|
|
24
|
-
export const useModules = (
|
|
24
|
+
export const useModules = ({
|
|
25
|
+
dataUser = {},
|
|
26
|
+
callback = () => {}
|
|
27
|
+
}) => {
|
|
25
28
|
const { role } = dataUser ?? {
|
|
26
29
|
role: {
|
|
27
30
|
permissions: {}
|
|
@@ -31,7 +34,17 @@ export const useModules = (dataUser = {}) => {
|
|
|
31
34
|
loading,
|
|
32
35
|
error,
|
|
33
36
|
data
|
|
34
|
-
} = useQuery(GET_MODULES
|
|
37
|
+
} = useQuery(GET_MODULES, {
|
|
38
|
+
fetchPolicy: 'cache-and-network',
|
|
39
|
+
onCompleted: (data) => {
|
|
40
|
+
if (Array.isArray(data?.modules)) {
|
|
41
|
+
callback(data.modules)
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
onError: (error) => {
|
|
45
|
+
console.error('Error fetching modules:', error)
|
|
46
|
+
}
|
|
47
|
+
})
|
|
35
48
|
|
|
36
49
|
const permissions = role?.permissions ?? {}
|
|
37
50
|
|
|
@@ -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,37 @@
|
|
|
1
|
+
import { useCallback } from 'react'
|
|
2
|
+
import { gql, useMutation } from '@apollo/client'
|
|
3
|
+
|
|
4
|
+
const UPDATE_MODULE_ORDER = gql`
|
|
5
|
+
mutation UpdateModuleOrder($input: [UpdateModuleOrderInput]!) {
|
|
6
|
+
updateModuleOrder(input: $input) {
|
|
7
|
+
success
|
|
8
|
+
message
|
|
9
|
+
modules {
|
|
10
|
+
mId
|
|
11
|
+
mPriority
|
|
12
|
+
}
|
|
13
|
+
errors {
|
|
14
|
+
path
|
|
15
|
+
message
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
`
|
|
20
|
+
|
|
21
|
+
export const useUpdateModuleOrder = () => {
|
|
22
|
+
const [updateModuleOrderMutation] = useMutation(UPDATE_MODULE_ORDER)
|
|
23
|
+
|
|
24
|
+
const updateModulesOrder = useCallback(async (newOrder) => {
|
|
25
|
+
// Enviar la actualización a la API (GraphQL)
|
|
26
|
+
try {
|
|
27
|
+
await updateModuleOrderMutation({
|
|
28
|
+
variables: { input: newOrder.map(({ mId, mPriority }) => ({ mId, mPriority })) }
|
|
29
|
+
})
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error('Error updating module order:', error)
|
|
32
|
+
throw new Error('Failed to update module order')
|
|
33
|
+
}
|
|
34
|
+
}, [updateModuleOrderMutation])
|
|
35
|
+
|
|
36
|
+
return [updateModulesOrder]
|
|
37
|
+
}
|
|
@@ -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 {
|
|
49
|
+
...dataOld,
|
|
50
|
+
dailyGoal: upsertGoal.data.dailyGoal
|
|
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
|
+
}
|