npm-pkg-hook 1.9.0 → 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 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.9.0"
50
+ "version": "1.9.1"
51
51
  }
@@ -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'
@@ -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
+ }