forked from admin/zeropost-tool
1cce478f27
- Header: Coins badge с кредитами, ссылка на /billing - app/billing/page.js: баланс, план, стоимость операций, история транзакций - app/api/billing/balance/route.js, transactions/route.js — прокси к engine - lib/engine.js: getBillingBalance, getTransactions, getBillingPlans, adminCreditUser
67 lines
2.7 KiB
JavaScript
67 lines
2.7 KiB
JavaScript
'use client';
|
|
import Link from 'next/link';
|
|
import { useRouter } from 'next/navigation';
|
|
import { useEffect, useState } from 'react';
|
|
import { Sparkles, LogOut, Settings2, CalendarDays, TrendingUp, Coins } from 'lucide-react';
|
|
import ThemeToggle from './ThemeToggle';
|
|
|
|
export default function Header({ user }) {
|
|
const router = useRouter();
|
|
const [credits, setCredits] = useState(null);
|
|
|
|
useEffect(() => {
|
|
if (!user) return;
|
|
fetch('/api/billing/balance')
|
|
.then(r => r.json())
|
|
.then(d => setCredits(d.isUnlimited ? '∞' : d.credits))
|
|
.catch(() => {});
|
|
}, [user?.id]);
|
|
|
|
async function logout() {
|
|
await fetch('/api/auth/logout', { method: 'POST' });
|
|
router.push('/login');
|
|
}
|
|
return (
|
|
<header className="border-b border-border bg-bg/80 backdrop-blur sticky top-0 z-10">
|
|
<div className="max-w-6xl mx-auto px-4 py-3 flex items-center justify-between">
|
|
<Link href="/" className="flex items-center gap-2 hover:opacity-80">
|
|
<Sparkles className="w-5 h-5 text-accent" />
|
|
<span className="font-bold">ZeroPost</span>
|
|
</Link>
|
|
<nav className="hidden sm:flex items-center gap-1">
|
|
<Link href="/calendar" className="btn-ghost px-3 py-1.5 text-sm flex items-center gap-1.5">
|
|
<CalendarDays className="w-4 h-4" />
|
|
<span>Календарь</span>
|
|
</Link>
|
|
{user?.isAdmin && (
|
|
<Link href="/spending" className="btn-ghost px-3 py-1.5 text-sm flex items-center gap-1.5">
|
|
<TrendingUp className="w-4 h-4" />
|
|
<span>Расходы</span>
|
|
</Link>
|
|
)}
|
|
</nav>
|
|
<div className="flex items-center gap-2">
|
|
{/* Баланс кредитов */}
|
|
{credits !== null && (
|
|
<Link href="/billing" className="flex items-center gap-1.5 px-2.5 py-1 rounded-lg bg-accent/10 hover:bg-accent/20 transition-colors text-sm font-medium text-accent">
|
|
<Coins className="w-3.5 h-3.5" />
|
|
<span>{credits} кр</span>
|
|
</Link>
|
|
)}
|
|
{user?.isAdmin && (
|
|
<Link href="/system" className="btn-ghost p-2 text-sm hidden sm:inline-flex" title="Системные настройки">
|
|
<Settings2 className="w-4 h-4" />
|
|
<span className="hidden md:inline">Система</span>
|
|
</Link>
|
|
)}
|
|
<span className="text-sm text-gray-500 hidden sm:inline mr-2">{user?.email}</span>
|
|
<ThemeToggle />
|
|
<button onClick={logout} className="btn-ghost p-2" title="Выйти">
|
|
<LogOut className="w-4 h-4" />
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
);
|
|
}
|