Files
parakasa/components/dashboard/user-nav.tsx
2026-01-10 21:04:58 +03:00

98 lines
3.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client"
import {
Avatar,
AvatarFallback,
AvatarImage,
} from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import Link from "next/link"
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"
import { supabase } from "@/lib/supabase"
import { useRouter } from "next/navigation"
import { useEffect, useState } from "react"
import { User } from "@supabase/supabase-js"
interface UserProfile {
full_name: string | null
email: string | null
role: string | null
}
interface UserNavProps {
user: {
email?: string | null
} | null
profile: {
full_name?: string | null
role?: string | null
} | null
}
export function UserNav({ user, profile }: UserNavProps) {
const router = useRouter()
const handleSignOut = async () => {
await supabase.auth.signOut()
router.push("/login")
router.refresh()
}
const getInitials = (name: string) => {
return name
.split(' ')
.map((n) => n[0])
.join('')
.toUpperCase()
.substring(0, 2)
}
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="relative h-8 w-8 rounded-full">
<Avatar className="h-8 w-8">
<AvatarImage src="/avatars/01.png" alt={profile?.full_name || "@parakasa"} />
<AvatarFallback>{profile?.full_name ? getInitials(profile.full_name) : 'PK'}</AvatarFallback>
</Avatar>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56" align="end">
<DropdownMenuLabel className="font-normal">
<div className="flex flex-col space-y-1">
<p className="text-sm font-medium leading-none">{profile?.full_name || 'Kullanıcı'}</p>
<p className="text-xs leading-none text-muted-foreground">
{user?.email}
</p>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuGroup>
<Link href="/dashboard/profile">
<DropdownMenuItem className="cursor-pointer">
Profil Bilgileri
</DropdownMenuItem>
</Link>
<Link href="/dashboard/profile/password">
<DropdownMenuItem className="cursor-pointer">
Şifre Değiştir
</DropdownMenuItem>
</Link>
</DropdownMenuGroup>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleSignOut} className="cursor-pointer text-red-600 focus:text-red-600">
Çıkış
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}