npm-pkg-hook 1.8.9 → 1.9.1
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 +2 -0
- package/src/hooks/useEmployee/queries.js +22 -0
- package/src/hooks/useEmployee/useCreateEmployee.js +44 -0
- package/src/hooks/useRoles/index.js +2 -0
- package/src/hooks/useRoles/queries.js +70 -0
- package/src/hooks/useRoles/useCreateRole.js +15 -0
- package/src/hooks/useRoles/useGetRoles.js +36 -0
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -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'
|
|
@@ -52,6 +53,7 @@ export * from './useRoads'
|
|
|
52
53
|
export * from './useCities'
|
|
53
54
|
export * from './useEditCategory'
|
|
54
55
|
export * from './useEmployee'
|
|
56
|
+
export * from './useEmployee/useCreateEmployee'
|
|
55
57
|
export * from './useCheckbox'
|
|
56
58
|
export * from './useRemoveExtraProductFoodsOptional'
|
|
57
59
|
export * from './useDeleteSubProductOptional'
|
|
@@ -33,3 +33,25 @@ query employees {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
`
|
|
36
|
+
/**
|
|
37
|
+
* GraphQL mutation for creating an employee, store, and user.
|
|
38
|
+
*/
|
|
39
|
+
export const CREATE_ONE_EMPLOYEE_STORE_AND_USER = gql`
|
|
40
|
+
mutation createOneEmployeeStoreAndUser($input: IEmployeeStore!) {
|
|
41
|
+
createOneEmployeeStoreAndUser(input: $input) {
|
|
42
|
+
success
|
|
43
|
+
message
|
|
44
|
+
errors {
|
|
45
|
+
path
|
|
46
|
+
message
|
|
47
|
+
type
|
|
48
|
+
context {
|
|
49
|
+
limit
|
|
50
|
+
value
|
|
51
|
+
label
|
|
52
|
+
key
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
`
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useMutation } from '@apollo/client'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
import { CREATE_ONE_EMPLOYEE_STORE_AND_USER } from './queries'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook to handle the createOneEmployeeStoreAndUser mutation.
|
|
7
|
+
*
|
|
8
|
+
* @returns {{
|
|
9
|
+
* createEmployeeStoreAndUser: (input: IEmployeeStore) => Promise<void>,
|
|
10
|
+
* loading: boolean,
|
|
11
|
+
* error: Error | null,
|
|
12
|
+
* data: Object | null
|
|
13
|
+
* }} An object containing the mutation function, loading status, error, and data.
|
|
14
|
+
*/
|
|
15
|
+
export const useCreateEmployeeStoreAndUser = () => {
|
|
16
|
+
const [createEmployeeStoreAndUserMutation, { loading, error, data }] = useMutation(CREATE_ONE_EMPLOYEE_STORE_AND_USER)
|
|
17
|
+
const [errors, setErrors] = useState([])
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Calls the createOneEmployeeStoreAndUser mutation.
|
|
21
|
+
*
|
|
22
|
+
* @param {Object} input - The input data for the mutation.
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
const createEmployeeStoreAndUser = async (input) => {
|
|
26
|
+
try {
|
|
27
|
+
const response = await createEmployeeStoreAndUserMutation({ variables: { input } })
|
|
28
|
+
if (response.data.createOneEmployeeStoreAndUser.errors) {
|
|
29
|
+
setErrors(response.data.createOneEmployeeStoreAndUser.errors)
|
|
30
|
+
} else {
|
|
31
|
+
setErrors([])
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
setErrors([{ message: err.message }])
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return [createEmployeeStoreAndUser, {
|
|
39
|
+
loading,
|
|
40
|
+
error,
|
|
41
|
+
data,
|
|
42
|
+
errors
|
|
43
|
+
}]
|
|
44
|
+
}
|
|
@@ -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
|
+
}
|