npm-pkg-hook 1.9.0 → 1.9.2
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 +1 -0
- package/src/hooks/useCart/useCart/index.js +1 -1
- package/src/hooks/useCatWithProductClient/index.js +17 -17
- package/src/hooks/useEmployee/index.js +1 -1
- 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/useRemoveRoles.js +40 -0
- package/src/hooks/useRoles/useUpdateRolesPriority.js +44 -0
- package/src/hooks/useStore/index.js +7 -2
package/package.json
CHANGED
package/src/hooks/index.js
CHANGED
|
@@ -53,6 +53,7 @@ export * from './useRoads'
|
|
|
53
53
|
export * from './useCities'
|
|
54
54
|
export * from './useEditCategory'
|
|
55
55
|
export * from './useEmployee'
|
|
56
|
+
export * from './useEmployee/useCreateEmployee'
|
|
56
57
|
export * from './useCheckbox'
|
|
57
58
|
export * from './useRemoveExtraProductFoodsOptional'
|
|
58
59
|
export * from './useDeleteSubProductOptional'
|
|
@@ -60,7 +60,7 @@ export const useCart = ({
|
|
|
60
60
|
if (!pId) return {}
|
|
61
61
|
setOpenModalProduct(true)
|
|
62
62
|
const product = await handleGetOneProduct({ variables: { pId } })
|
|
63
|
-
const productFoodsOne = product
|
|
63
|
+
const productFoodsOne = product?.data?.productFoodsOne || {}
|
|
64
64
|
setDataOneProduct(productFoodsOne)
|
|
65
65
|
|
|
66
66
|
const matchingItemInShoppingCart = dataShoppingCard?.find((item) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useQuery } from '@apollo/client'
|
|
3
|
+
import { GET_ALL_CATEGORIES_WITH_PRODUCT_CLIENTS } from './queries'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Custom hook to fetch categories with product data.
|
|
@@ -17,9 +17,9 @@ export const useCatWithProductClient = (idStore) => {
|
|
|
17
17
|
search: '',
|
|
18
18
|
gender: [],
|
|
19
19
|
desc: [],
|
|
20
|
-
categories: []
|
|
21
|
-
}
|
|
22
|
-
})
|
|
20
|
+
categories: []
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
23
|
|
|
24
24
|
const fetchCategories = () => {
|
|
25
25
|
fetchMore({
|
|
@@ -29,28 +29,28 @@ export const useCatWithProductClient = (idStore) => {
|
|
|
29
29
|
search: '',
|
|
30
30
|
gender: [],
|
|
31
31
|
desc: [],
|
|
32
|
-
categories: []
|
|
32
|
+
categories: []
|
|
33
33
|
},
|
|
34
34
|
updateQuery: (prev, { fetchMoreResult }) => {
|
|
35
|
-
if (!fetchMoreResult) return prev
|
|
35
|
+
if (!fetchMoreResult) return prev
|
|
36
36
|
return {
|
|
37
37
|
...prev,
|
|
38
|
-
getCatProductsWithProductClient: fetchMoreResult.getCatProductsWithProductClient
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
}
|
|
38
|
+
getCatProductsWithProductClient: fetchMoreResult.getCatProductsWithProductClient
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
// Utiliza useMemo para memorizar el resultado filtrado
|
|
45
45
|
const filteredData = useMemo(() => {
|
|
46
46
|
return data?.getCatProductsWithProductClient?.filter(
|
|
47
47
|
(category) => category?.productFoodsAll?.length > 0
|
|
48
|
-
) || []
|
|
49
|
-
}, [data])
|
|
48
|
+
) || []
|
|
49
|
+
}, [data])
|
|
50
50
|
|
|
51
51
|
return [filteredData, {
|
|
52
52
|
loading,
|
|
53
53
|
error,
|
|
54
|
-
fetchCategories
|
|
54
|
+
fetchCategories
|
|
55
55
|
}]
|
|
56
|
-
}
|
|
56
|
+
}
|
|
@@ -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,40 @@
|
|
|
1
|
+
import { useMutation, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
// Define the GraphQL mutation
|
|
4
|
+
const REMOVE_ROLES_MUTATION = gql`
|
|
5
|
+
mutation removeRoles($roleIds: [ID!]!) {
|
|
6
|
+
removeRoles(roleIds: $roleIds) {
|
|
7
|
+
success
|
|
8
|
+
message
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook to call removeRoles mutation.
|
|
15
|
+
*
|
|
16
|
+
* @returns {Object} An object containing the mutation function and the loading/error state.
|
|
17
|
+
*/
|
|
18
|
+
export function useRemoveRoles () {
|
|
19
|
+
const [removeRoles, { loading, error, data }] = useMutation(REMOVE_ROLES_MUTATION, {
|
|
20
|
+
onError: (err) => {
|
|
21
|
+
console.error('Error removing roles:', err)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const removeRolesHandler = async ({ roleIds = [] }) => {
|
|
26
|
+
try {
|
|
27
|
+
const { data } = await removeRoles({ variables: { roleIds } })
|
|
28
|
+
return data.removeRoles
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error('Error removing roles:', err)
|
|
31
|
+
throw err
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return [removeRolesHandler, {
|
|
36
|
+
loading,
|
|
37
|
+
error,
|
|
38
|
+
data
|
|
39
|
+
}]
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useMutation, gql } from '@apollo/client'
|
|
2
|
+
|
|
3
|
+
// Define the mutation
|
|
4
|
+
const UPDATE_ROLES_PRIORITY = gql`
|
|
5
|
+
mutation updateRolesPriority($roles: [IParamsPriority]!) {
|
|
6
|
+
updateRolesPriority(roles: $roles) {
|
|
7
|
+
success
|
|
8
|
+
message
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
`
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Custom hook to update roles priority
|
|
15
|
+
* @returns {Object} - Returns the mutation function and the mutation state
|
|
16
|
+
*/
|
|
17
|
+
export const useUpdateRolesPriority = () => {
|
|
18
|
+
const [updateRolesPriority, { data, loading, error }] = useMutation(UPDATE_ROLES_PRIORITY)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Function to update the priority of roles
|
|
22
|
+
* @param {Array} roles - The array of roles with their priorities to be updated
|
|
23
|
+
* @returns {Promise<void>}
|
|
24
|
+
*/
|
|
25
|
+
const handleUpdateRolesPriority = async (roles) => {
|
|
26
|
+
try {
|
|
27
|
+
const response = await updateRolesPriority({
|
|
28
|
+
variables: { roles }
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// You can handle the response or any additional logic here
|
|
32
|
+
return response
|
|
33
|
+
} catch (err) {
|
|
34
|
+
// Handle the error as needed
|
|
35
|
+
console.error('Error updating roles priority:', err)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return [handleUpdateRolesPriority, {
|
|
40
|
+
data,
|
|
41
|
+
loading,
|
|
42
|
+
error
|
|
43
|
+
}]
|
|
44
|
+
}
|
|
@@ -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 =
|
|
7
|
+
export const useStore = ({ isClient = false, idStore = null } = {}) => {
|
|
8
8
|
const client = useApolloClient()
|
|
9
9
|
const [onClickLogout, { loading: load }] = useLogout()
|
|
10
10
|
|
|
@@ -27,7 +27,12 @@ export const useStore = ({ isClient = false, idStore = '' } = {}) => {
|
|
|
27
27
|
}, [cachedData, store])
|
|
28
28
|
|
|
29
29
|
if (isClient && !!idStore) {
|
|
30
|
-
const {
|
|
30
|
+
const {
|
|
31
|
+
data,
|
|
32
|
+
refetch,
|
|
33
|
+
loading: loadingClient,
|
|
34
|
+
error: errorStoreClient
|
|
35
|
+
} = useQuery(GET_ONE_STORE_BY_ID, {
|
|
31
36
|
skip: !isClient,
|
|
32
37
|
variables: {
|
|
33
38
|
idStore
|