36 lines
984 B
TypeScript
36 lines
984 B
TypeScript
"use client";
|
||
import { handleAxiosError } from "@/core/utils";
|
||
import { useLogout } from "@/services/hooks/auth.hook";
|
||
import { Logout } from "@mui/icons-material";
|
||
import { Button } from "@mui/material";
|
||
import { useRouter } from "next/navigation";
|
||
import { toast } from "react-toastify";
|
||
|
||
export default function LogoutButton() {
|
||
const { mutateAsync, isPending } = useLogout();
|
||
const router = useRouter();
|
||
const handleLogout = async () => {
|
||
try {
|
||
const { message } = await mutateAsync();
|
||
toast.success(message);
|
||
router.push("/");
|
||
} catch (error) {
|
||
toast.error(handleAxiosError(error));
|
||
}
|
||
};
|
||
return (
|
||
<>
|
||
<Button
|
||
className="flex items-center text-[#2a5298] w-full justify-start gap-x-4 hover:cursor-pointer transition-all duration-300
|
||
"
|
||
onClick={handleLogout}
|
||
>
|
||
<span>
|
||
<Logout />
|
||
</span>
|
||
<span> خروج از حساب</span>
|
||
</Button>
|
||
</>
|
||
);
|
||
}
|