From 4678f0b52176cd6b1d0fc97a83dc7a58704b6361 Mon Sep 17 00:00:00 2001 From: anthonyA1214 Date: Fri, 27 Nov 2026 17:37:32 +0800 Subject: [PATCH] feat(admin-panel): wire up sign out actions Replace the no-op click handlers on the sidebar menu button and the user nav "Sign out" item with the useLogout mutation. On success, clear the React Query cache and redirect to /auth/sign-in. --- src/components/admin-panel/menu.tsx | 16 ++++++++++++++-- src/components/admin-panel/user-nav.tsx | 14 +++++++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/admin-panel/menu.tsx b/src/components/admin-panel/menu.tsx index 7dd81d6..d83e8d7 100644 --- a/src/components/admin-panel/menu.tsx +++ b/src/components/admin-panel/menu.tsx @@ -8,8 +8,10 @@ import { TooltipTrigger, TooltipContent, } from "@/components/ui/tooltip" -import { Link, useLocation } from "@tanstack/react-router" +import { Link, useLocation, useNavigate } from "@tanstack/react-router" import { motion } from "motion/react" +import { useLogout } from "@/lib/auth" +import { useQueryClient } from "@tanstack/react-query" interface MenuProps { isOpen: boolean | undefined @@ -19,6 +21,16 @@ export function Menu({ isOpen }: MenuProps) { const pathname = useLocation({ select: (location) => location.pathname, }) + const navigate = useNavigate() + const queryClient = useQueryClient() + + const logout = useLogout({ + onSuccess: () => { + queryClient.clear() + navigate({ to: "/auth/sign-in" }) + }, + }) + const menuList = getMenuList(pathname) return ( @@ -138,7 +150,7 @@ export function Menu({ isOpen }: MenuProps) { {}} + onClick={() => logout.mutate({})} variant="outline" className="mt-5 h-10 w-full justify-center" > diff --git a/src/components/admin-panel/user-nav.tsx b/src/components/admin-panel/user-nav.tsx index f58197b..04a5eb9 100644 --- a/src/components/admin-panel/user-nav.tsx +++ b/src/components/admin-panel/user-nav.tsx @@ -17,6 +17,9 @@ import { } from "@/components/ui/dropdown-menu" import { Link, useLocation } from "@tanstack/react-router" import { cn } from "@/lib/utils" +import { useNavigate } from "@tanstack/react-router" +import { useLogout } from "@/lib/auth" +import { useQueryClient } from "@tanstack/react-query" const items = [ { to: "/settings/profile", label: "Profile", icon: User }, @@ -27,6 +30,15 @@ export function UserNav() { const pathname = useLocation({ select: (location) => location.pathname, }) + const navigate = useNavigate() + const queryClient = useQueryClient() + + const logout = useLogout({ + onSuccess: () => { + queryClient.clear() + navigate({ to: "/auth/sign-in" }) + }, + }) return ( @@ -103,7 +115,7 @@ export function UserNav() { {}} + onClick={() => logout.mutate({})} > Sign out