Update method for user pages and format code

This commit is contained in:
2023-11-19 12:52:07 +07:00
parent 9a9617bb16
commit ce81f7c7f3
36 changed files with 565 additions and 727 deletions
@@ -0,0 +1,29 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import toast from 'react-hot-toast';
// Services
import { createUser as createUserFn } from '@service/userServices';
// Constants
import { ADD_SUCCESS } from '@constant/messages';
/**
* Create user in database
* @returns The status of creating users and createUser function
*/
const useCreateUser = () => {
const queryClient = useQueryClient();
const { mutate: createUser, isPending: isCreating } = useMutation({
mutationFn: createUserFn,
onSuccess: () => {
toast.success(ADD_SUCCESS);
queryClient.invalidateQueries({ queryKey: ['users'] });
},
onError: (err) => toast.error(err.message),
});
return { isCreating, createUser };
};
export { useCreateUser };