73 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2024-05-17 22:25:55 -07:00
"use client";
2024-04-18 15:07:15 -04:00
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
2024-05-17 22:25:55 -07:00
} from "@/components/ui/dropdown-menu";
import { User } from "@/lib/types";
import { useClerk } from "@clerk/nextjs";
import { LogOut, Pencil, Sparkles } from "lucide-react";
import { useRouter } from "next/navigation";
2024-04-18 15:07:15 -04:00
2024-04-18 15:32:27 -04:00
export default function UserButton({ userData }: { userData: User }) {
2024-05-17 22:25:55 -07:00
if (!userData) return null;
2024-04-28 01:17:39 -04:00
2024-05-17 22:25:55 -07:00
const { signOut } = useClerk();
const router = useRouter();
2024-04-28 01:17:39 -04:00
2024-04-18 15:07:15 -04:00
return (
<DropdownMenu>
<DropdownMenuTrigger>
2024-04-18 15:25:20 -04:00
<div className="w-9 h-9 font-mono rounded-full overflow-hidden bg-gradient-to-t from-neutral-800 to-neutral-600 flex items-center justify-center text-sm font-medium">
2024-05-17 22:25:55 -07:00
{userData.name &&
userData.name
.split(" ")
.slice(0, 2)
.map((name) => name[0].toUpperCase())}
2024-04-18 15:25:20 -04:00
</div>
2024-04-18 15:07:15 -04:00
</DropdownMenuTrigger>
<DropdownMenuContent className="w-48" align="end">
2024-05-04 23:31:35 -07:00
<div className="py-1.5 px-2 w-full">
<div className="font-medium">{userData.name}</div>
<div className="text-sm w-full overflow-hidden text-ellipsis whitespace-nowrap text-muted-foreground">
{userData.email}
</div>
</div>
<DropdownMenuSeparator />
<div className="py-1.5 px-2 w-full flex flex-col items-start text-sm">
<div className="flex items-center">
<Sparkles className={`h-4 w-4 mr-2 text-indigo-500`} />
2024-05-17 22:25:55 -07:00
AI Usage: {userData.generations}/10
</div>
<div className="rounded-full w-full mt-2 h-2 overflow-hidden bg-secondary">
<div
className="h-full bg-indigo-500 rounded-full"
style={{
2024-05-17 22:25:55 -07:00
width: `${(userData.generations * 100) / 10}%`,
}}
/>
</div>
</div>
2024-05-04 23:31:35 -07:00
<DropdownMenuSeparator />
2024-05-17 23:54:34 -07:00
{/* <DropdownMenuItem className="cursor-pointer">
2024-04-18 15:07:15 -04:00
<Pencil className="mr-2 h-4 w-4" />
<span>Edit Profile</span>
2024-05-17 23:54:34 -07:00
</DropdownMenuItem> */}
2024-04-28 01:17:39 -04:00
<DropdownMenuItem
onClick={() => signOut(() => router.push("/"))}
className="!text-destructive cursor-pointer"
>
2024-04-18 15:07:15 -04:00
<LogOut className="mr-2 h-4 w-4" />
<span>Log Out</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
2024-05-17 22:25:55 -07:00
);
2024-04-18 15:07:15 -04:00
}