import { Button, Code, Paper, Text } from "@mantine/core"; import { notifications } from "@mantine/notifications"; import { useMutation } from "@tanstack/react-query"; import axios from "axios"; import { useUserContext } from "../context/user-context"; import { Navigate } from "react-router"; import { Layout } from "../components/layouts/layout"; import { capitalize } from "../utils/utils"; import { useAppContext } from "../context/app-context"; import { Trans, useTranslation } from "react-i18next"; export const LogoutPage = () => { const { isLoggedIn, username, oauth, provider } = useUserContext(); const { genericName } = useAppContext(); const { t } = useTranslation(); if (!isLoggedIn) { return ; } const logoutMutation = useMutation({ mutationFn: () => { return axios.post("/api/logout"); }, onError: () => { notifications.show({ title: t("logoutFailTitle"), message: t("logoutFailSubtitle"), color: "red", }); }, onSuccess: () => { notifications.show({ title: t("logoutSuccessTitle"), message: t("logoutSuccessSubtitle"), color: "green", }); setTimeout(() => { window.location.replace("/login"); }, 500); }, }); return ( {t("logoutTitle")} {oauth ? ( }} values={{ provider: provider === "generic" ? genericName : capitalize(provider), username: username, }} /> ) : ( }} values={{ username: username, }} /> )} ); };