npm-pkg-hook 1.10.9 → 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 CHANGED
@@ -47,5 +47,5 @@
47
47
  "rm": "rm -rf node_modules package-lock.json && npm i",
48
48
  "test": "echo \"Error: no test specified\" && exit 1"
49
49
  },
50
- "version": "1.10.9"
50
+ "version": "1.11.0"
51
51
  }
@@ -134,3 +134,5 @@ export * from './useWeeklyStockMovement'
134
134
  export * from './useSetImageProducts'
135
135
  export * from './useGetSalesAmountToday'
136
136
  export * from './useUpsertGoal'
137
+ export * from './useDashboardComponents'
138
+ export * from './useUpdateModuleOrder'
@@ -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
+ }
@@ -21,7 +21,10 @@ const GET_MODULES = gql`
21
21
  }
22
22
  `
23
23
 
24
- export const useModules = (dataUser = {}) => {
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
 
@@ -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
+ }
@@ -45,10 +45,10 @@ export const useUpsertGoal = ({
45
45
  cache.modify({
46
46
  fields: {
47
47
  getStore (dataOld = []) {
48
- return cache.writeQuery({
49
- query: GET_ONE_STORE,
50
- data: dataOld
51
- })
48
+ return {
49
+ ...dataOld,
50
+ dailyGoal: upsertGoal.data.dailyGoal
51
+ }
52
52
  }
53
53
  }
54
54
  })