diff --git a/apps/nextjs/src/components/user-avatar-menu.tsx b/apps/nextjs/src/components/user-avatar-menu.tsx index a71efb16c..a8bb39d27 100644 --- a/apps/nextjs/src/components/user-avatar-menu.tsx +++ b/apps/nextjs/src/components/user-avatar-menu.tsx @@ -1,16 +1,29 @@ "use client"; import type { ReactNode } from "react"; +import { useCallback, useEffect } from "react"; import Link from "next/link"; -import { Menu, useMantineColorScheme } from "@mantine/core"; +import { useRouter } from "next/navigation"; import { + Center, + Menu, + Stack, + Text, + useMantineColorScheme, +} from "@mantine/core"; +import { useTimeout } from "@mantine/hooks"; +import { + IconCheck, IconDashboard, + IconLogin, IconLogout, IconMoon, IconSun, IconTool, } from "@tabler/icons-react"; +import { signOut, useSession } from "@homarr/auth/client"; +import { createModal, useModalAction } from "@homarr/modals"; import { useScopedI18n } from "@homarr/translation/client"; interface UserAvatarMenuProps { @@ -26,6 +39,22 @@ export const UserAvatarMenu = ({ children }: UserAvatarMenuProps) => { const colorSchemeText = colorScheme === "dark" ? t("switchToLightMode") : t("switchToDarkMode"); + const session = useSession(); + const router = useRouter(); + + const { openModal } = useModalAction(LogoutModal); + + const handleSignout = useCallback(async () => { + await signOut({ + redirect: false, + }); + openModal({ + onTimeout: () => { + router.refresh(); + }, + }); + }, [openModal, router]); + return (
); }; + +const LogoutModal = createModal<{ onTimeout: () => void }>( + ({ actions, innerProps }) => { + const t = useScopedI18n("common.userAvatar.menu"); + const { start } = useTimeout(() => { + actions.closeModal(); + innerProps.onTimeout(); + }, 1500); + + useEffect(() => { + start(); + }, []); + + return ( +