Spaces:
Running
Running
File size: 5,284 Bytes
53443e8 99e0d4e 53443e8 602c178 53443e8 99e0d4e cea13af 53443e8 cea13af 99e0d4e 33757b5 99e0d4e 53443e8 602c178 53443e8 602c178 53443e8 602c178 53443e8 208781e 1ba9153 e645f21 37bb3a7 602c178 b4da4fc 37bb3a7 dc9320a 99e0d4e dc9320a 37bb3a7 99e0d4e 37bb3a7 602c178 20f50ca 602c178 20f50ca 602c178 99aaaa2 208781e 99aaaa2 208781e 99aaaa2 602c178 37bb3a7 602c178 37bb3a7 602c178 37bb3a7 602c178 37bb3a7 53443e8 602c178 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 'use client'
import { useState, useEffect } from 'react'
import { useAuth } from '@/contexts/AuthContext'
import { LogOut } from 'lucide-react'
import { cn } from '@/lib/utils'
import { api } from '@/lib/api'
import Link from 'next/link'
import { useTranslation } from '@/lib/i18n'
export function Header() {
const { user, logout } = useAuth()
const { t } = useTranslation()
const [companyName, setCompanyName] = useState<string | null>(null)
const [mounted, setMounted] = useState(false)
useEffect(() => {
setMounted(true)
}, [])
useEffect(() => {
const loadTenant = async () => {
try {
const res = await api.get('/api/v1/tenants/me')
setCompanyName(res.data.company_name || null)
} catch (e) {
console.error('Failed to load tenant')
}
}
if (user) loadTenant()
}, [user])
const getInitials = (name?: string | null, email?: string) => {
if (name) return name.split(' ').map(n => n[0]).join('').toUpperCase().slice(0, 2)
if (email) return email.slice(0, 2).toUpperCase()
return 'U'
}
const getAvatarColor = (email?: string) => {
if (!email) return 'bg-indigo-600'
const colors = ['bg-indigo-600', 'bg-purple-600', 'bg-pink-600', 'bg-blue-600', 'bg-cyan-600', 'bg-teal-600', 'bg-emerald-600']
const charCode = email.length > 0 ? email.charCodeAt(0) : 0
return colors[charCode % colors.length]
}
if (!mounted) return <header className="hidden md:flex h-16 bg-[#0D0E18]/50" />
return (
<header className="hidden md:flex h-16 border-b border-white/5 bg-[#0a0a12]/90 backdrop-blur-xl backdrop-saturate-[1.8] items-center justify-between px-6 sticky top-0 z-30 overflow-hidden">
<div className="absolute inset-0 pointer-events-none overflow-hidden -z-10 bg-gradient-to-b from-white/5 to-transparent opacity-50" />
<div className="relative z-10 flex items-center justify-between w-full">
{/* Left: Logo (Mobile/Tablet Hidden sidebar view) */}
<div className="flex-1 items-center gap-2 lg:hidden flex">
<Link href="/settings/brain" className="flex items-center gap-2 group">
<div className="w-8 h-8 relative">
<img src="/logo-v2.png" alt="Logo" className="w-full h-full object-contain transition-transform group-hover:scale-110" />
</div>
<span className="font-bold text-lg text-white tracking-[0.2em] uppercase">
MICROFUNNEL
</span>
</Link>
</div>
<div className="flex-1" />
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
{/* Profile Link */}
<Link
href="/settings/account"
className="flex items-center gap-2 group p-1 pr-3 rounded-full hover:bg-white/5 transition-all border border-transparent hover:border-white/10"
>
<div className={cn(
"w-8 h-8 rounded-full flex items-center justify-center text-white font-bold text-xs border border-white/10 group-hover:scale-105 transition-transform shadow-lg overflow-hidden",
!user?.avatar_url && getAvatarColor(user?.email)
)}>
{user?.avatar_url ? (
<img src={user.avatar_url} alt="Avatar" className="w-full h-full object-cover" />
) : (
getInitials(user?.full_name, user?.email)
)}
</div>
<div className="hidden sm:block text-left">
<p className="text-xs font-bold text-white leading-none whitespace-nowrap">
{(user?.role === 'OWNER' || user?.role === 'ADMIN') ? (companyName || user?.full_name || 'User') : (user?.full_name || 'User')}
</p>
<p className="text-[10px] text-slate-500 mt-1 leading-none uppercase tracking-wider">
{user?.role === 'OWNER' ? 'Владелец' : user?.role === 'ADMIN' ? 'Администратор' : 'Менеджер'}
</p>
</div>
</Link>
{/* Separate Logout Button */}
<button
onClick={() => logout()}
className="p-2 text-slate-400 hover:text-red-400 transition-colors rounded-lg hover:bg-red-500/10 active:scale-95"
title={t('header.logout')}
>
<LogOut className="w-5 h-5" />
</button>
</div>
</div>
</div>
</header>
)
}
|