npm-pkg-hook 1.8.9 → 1.9.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.8.9"
50
+ "version": "1.9.0"
51
51
  }
@@ -12,6 +12,7 @@ export * from './useUpdateMultipleProducts'
12
12
  export * from './useTokenCards'
13
13
  export * from './useSubscriptionValidation'
14
14
  export * from './convertToMilitaryTime'
15
+ export * from './useRoles'
15
16
  export * from './statusOpenStores'
16
17
  export * from './completeSchedules'
17
18
  export * from './useLogout/helpers/BroadcastChannel'
@@ -0,0 +1,2 @@
1
+ export * from './useCreateRole'
2
+ export * from './useGetRoles'
@@ -0,0 +1,70 @@
1
+ import { gql } from '@apollo/client'
2
+
3
+ export const GET_ALL_ROLES = gql`
4
+ query getRoles($idStore: ID, $search: String, $min: Int, $max: Int, $fromDate: DateTime, $toDate: DateTime, $page: Int) {
5
+ getRoles(idStore: $idStore, search: $search, min: $min, max: $max, fromDate: $fromDate, toDate: $toDate, page: $page) {
6
+ success
7
+ message
8
+ errors {
9
+ path
10
+ message
11
+ type
12
+ context {
13
+ limit
14
+ value
15
+ label
16
+ key
17
+ }
18
+ __typename
19
+ }
20
+ pagination {
21
+ totalRecords
22
+ totalPages
23
+ currentPage
24
+ __typename
25
+ }
26
+ data {
27
+ idRole
28
+ name
29
+ priority
30
+ description
31
+ permissions
32
+ createdAt
33
+ updatedAt
34
+ }
35
+ }
36
+ }
37
+ `
38
+
39
+ /**
40
+ * Mutación para crear un nuevo rol
41
+ */
42
+ export const CREATE_ROLE_MUTATION = gql`
43
+ mutation createRoleMutation($input: IRole!) {
44
+ createRoleMutation(input: $input) {
45
+ success
46
+ message
47
+ errors {
48
+ path
49
+ message
50
+ type
51
+ context {
52
+ limit
53
+ value
54
+ label
55
+ key
56
+ }
57
+ __typename
58
+ }
59
+ data {
60
+ idRole
61
+ name
62
+ priority
63
+ description
64
+ permissions
65
+ createdAt
66
+ updatedAt
67
+ }
68
+ }
69
+ }
70
+ `
@@ -0,0 +1,15 @@
1
+ import { useMutation } from '@apollo/client'
2
+ import { CREATE_ROLE_MUTATION } from './queries'
3
+ /**
4
+ * Custom hook para crear un nuevo rol
5
+ * @returns {Object} - Estado de la mutación, incluyendo loading, error, data y la función createRoleMutation
6
+ */
7
+ export const useCreateRole = () => {
8
+ const [createRoleMutation, { loading, error, data }] = useMutation(CREATE_ROLE_MUTATION)
9
+
10
+ return [createRoleMutation, {
11
+ loading,
12
+ error,
13
+ data: data?.createRoleMutation ?? null
14
+ }]
15
+ }
@@ -0,0 +1,36 @@
1
+ import { useQuery } from '@apollo/client'
2
+ import { GET_ALL_ROLES } from './queries'
3
+
4
+ export const useGetRoles = ({
5
+ max,
6
+ order = 'DESC',
7
+ search,
8
+ sendNotification = () => { }
9
+ } = {}) => {
10
+ const {
11
+ loading,
12
+ error,
13
+ called,
14
+ data,
15
+ refetch
16
+ } = useQuery(GET_ALL_ROLES, {
17
+ onError: () => {
18
+ sendNotification({
19
+ title: 'Error',
20
+ description: 'Algo salió mal',
21
+ backgroundColor: 'error'
22
+ })
23
+ },
24
+ variables: {
25
+ search,
26
+ max: max || 100,
27
+ order
28
+ }
29
+ })
30
+ return [data?.getRoles, {
31
+ loading: called ? false : loading,
32
+ buttonLoading: loading,
33
+ error,
34
+ refetch
35
+ }]
36
+ }