init project portal web
This commit is contained in:
28
lib/login/view-model/index.ts
Normal file
28
lib/login/view-model/index.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { loginRepository } from "../data/repository";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { toast } from "sonner";
|
||||
import loginStore from "../store";
|
||||
|
||||
|
||||
export const useLogin = () => {
|
||||
const router = useRouter()
|
||||
|
||||
const mutation = useMutation({
|
||||
mutationFn: () => loginRepository.login(loginStore.username, loginStore.password),
|
||||
onSuccess: () => {
|
||||
router.push("/")
|
||||
toast.success('Welcome to dashboard')
|
||||
},
|
||||
onError: ((error)=> {
|
||||
toast.error(error.message)
|
||||
})
|
||||
})
|
||||
|
||||
return {
|
||||
login: mutation.mutate,
|
||||
isLoading: mutation.isPending,
|
||||
isError: mutation.isError,
|
||||
error: mutation.error,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user