generated from fahricansecer/boilerplate-fe
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
|
||||
import { usePathname } from "next/navigation";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { Home, FolderOpen, LayoutGrid, Settings, Sparkles, AtSign, ShieldCheck } from "lucide-react";
|
||||
import { Home, FolderOpen, LayoutGrid, Settings, Sparkles, AtSign, ShieldCheck, LogOut } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useCreditBalance, useCurrentUser } from "@/hooks/use-api";
|
||||
import { NotificationsDropdown } from "./notifications-dropdown";
|
||||
import { signOut } from "next-auth/react";
|
||||
|
||||
const navItems = [
|
||||
{ href: "/dashboard", icon: Home, label: "Ana Sayfa" },
|
||||
@@ -66,13 +67,13 @@ export function MobileNav() {
|
||||
function CreditCard() {
|
||||
const { data, isLoading } = useCreditBalance();
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const remaining = (data as any)?.data?.remaining ?? (data as any)?.remaining ?? 0;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const total = (data as any)?.data?.total ?? (data as any)?.total ?? 50;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const planName = (data as any)?.data?.plan ?? (data as any)?.plan ?? "Free";
|
||||
const pct = total > 0 ? Math.round((remaining / total) * 100) : 0;
|
||||
// Axios interceptor unwrap sonrası data doğrudan backend yanıtı
|
||||
const creditData = data as any;
|
||||
const isAdmin = creditData?.isAdmin === true;
|
||||
const remaining = creditData?.remaining ?? creditData?.balance ?? 0;
|
||||
const total = creditData?.total ?? creditData?.monthlyLimit ?? 50;
|
||||
const planName = creditData?.plan ?? "Free";
|
||||
const pct = isAdmin ? 100 : (total > 0 ? Math.round((remaining / total) * 100) : 0);
|
||||
|
||||
return (
|
||||
<div className="mx-3 mb-4 p-4 rounded-xl bg-gradient-to-br from-violet-500/8 to-cyan-400/5 border border-[var(--color-border-faint)]">
|
||||
@@ -81,7 +82,7 @@ function CreditCard() {
|
||||
<span className="badge badge-violet">{planName}</span>
|
||||
</div>
|
||||
<div className="text-2xl font-bold font-[family-name:var(--font-display)] text-[var(--color-text-primary)]">
|
||||
{isLoading ? "..." : remaining}
|
||||
{isLoading ? "..." : isAdmin ? "∞" : remaining}
|
||||
</div>
|
||||
<div className="progress-bar mt-2">
|
||||
<div
|
||||
@@ -90,7 +91,7 @@ function CreditCard() {
|
||||
/>
|
||||
</div>
|
||||
<p className="text-[10px] text-[var(--color-text-ghost)] mt-1.5">
|
||||
{total} kredilik planınızın {remaining}'{remaining === 1 ? "i" : "si"} kaldı
|
||||
{isAdmin ? "Sınırsız admin erişimi" : `${total} kredilik planınızın ${remaining}'${remaining === 1 ? "i" : "si"} kaldı`}
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
@@ -106,6 +107,10 @@ export function DesktopSidebar() {
|
||||
const roles: string[] = (user?.roles ?? []).map((r: any) => r?.role?.name ?? r?.name ?? "");
|
||||
const isAdmin = roles.includes("admin") || roles.includes("superadmin");
|
||||
|
||||
const handleLogout = () => {
|
||||
signOut({ redirect: true, callbackUrl: "/signin" });
|
||||
};
|
||||
|
||||
return (
|
||||
<aside className="hidden md:flex md:w-64 lg:w-72 flex-col h-screen sticky top-0 border-r border-[var(--color-border-faint)] bg-[var(--color-bg-deep)]">
|
||||
{/* Logo */}
|
||||
@@ -176,6 +181,17 @@ export function DesktopSidebar() {
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Çıkış Butonu */}
|
||||
<div className="px-3 pb-4">
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="w-full flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium text-[var(--color-text-muted)] hover:text-red-400 hover:bg-red-500/8 transition-all duration-200"
|
||||
>
|
||||
<LogOut size={18} strokeWidth={1.6} />
|
||||
<span>Çıkış Yap</span>
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user