Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/components/admin-panel/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 (
Expand Down Expand Up @@ -138,7 +150,7 @@ export function Menu({ isOpen }: MenuProps) {
<TooltipTrigger
render={
<Button
onClick={() => {}}
onClick={() => logout.mutate({})}
variant="outline"
className="mt-5 h-10 w-full justify-center"
>
Expand Down
14 changes: 13 additions & 1 deletion src/components/admin-panel/user-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 (
<DropdownMenu>
Expand Down Expand Up @@ -103,7 +115,7 @@ export function UserNav() {
<DropdownMenuItem
variant="destructive"
className="hover:cursor-pointer"
onClick={() => {}}
onClick={() => logout.mutate({})}
>
<LogOut className="mr-3 h-4 w-4 text-muted-foreground" />
Sign out
Expand Down