-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HRIS-250 [FE] Integrate Add New Employee Functionality
- Loading branch information
Showing
13 changed files
with
261 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { gql } from 'graphql-request' | ||
|
||
export const CREATE_NEW_EMPLOYEE_MUTATION = gql` | ||
mutation ($request: AddNewEmployeeRequestInput!) { | ||
addNewEmployee(request: $request) | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { gql } from 'graphql-request' | ||
|
||
export const GET_ALL_POSITION_QUERY = gql` | ||
query { | ||
allPositions { | ||
id | ||
name | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { gql } from 'graphql-request' | ||
|
||
export const GET_ALL_ROLE_QUERY = gql` | ||
query { | ||
allRoles { | ||
id | ||
name | ||
} | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import toast from 'react-hot-toast' | ||
import { useMutation, UseMutationResult } from '@tanstack/react-query' | ||
|
||
import { client } from '~/utils/shared/client' | ||
import { IEmployeeInput } from '~/utils/interfaces/employeeInterface' | ||
import { CREATE_NEW_EMPLOYEE_MUTATION } from '~/graphql/mutations/employeeMutation' | ||
|
||
type EmployeeFuncReturnType = UseMutationResult<any, Error, IEmployeeInput, unknown> | ||
|
||
type HookReturnType = { | ||
handleAddNewEmployeeMutation: () => UseMutationResult<any, Error, IEmployeeInput, unknown> | ||
} | ||
|
||
const useEmployee = (): HookReturnType => { | ||
const handleAddNewEmployeeMutation = (): EmployeeFuncReturnType => | ||
useMutation({ | ||
mutationFn: async (request: IEmployeeInput) => { | ||
return await client.request(CREATE_NEW_EMPLOYEE_MUTATION, { request }) | ||
}, | ||
onError: async (err: Error) => { | ||
const [errorMessage] = err.message.split(/:\s/, 2) | ||
toast.error(errorMessage) | ||
} | ||
}) | ||
|
||
return { | ||
handleAddNewEmployeeMutation | ||
} | ||
} | ||
|
||
export default useEmployee |
Oops, something went wrong.