ehsan-dashboards/dashboards/crm/components/Navbar.tsx

217 lines
8.2 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.

// components/Navbar.tsx
'use client';
import React from 'react';
import {
LayoutDashboard,
CalendarCheck,
GitPullRequest,
GraduationCap,
Settings,
Plus,
Download,
Upload,
Database,
Sparkles,
} from 'lucide-react';
interface NavbarProps {
activeTab: string;
setActiveTab: (tab: any) => void;
overdueCount?: number;
dueTodayCount?: number;
onOpenNewLead?: () => void;
onNewLead?: () => void;
onExportExcel?: () => void;
onImportExcel?: () => void;
onImportSuccess?: () => void;
}
export function Navbar({
activeTab,
setActiveTab,
overdueCount = 0,
dueTodayCount = 0,
onOpenNewLead,
onNewLead,
onExportExcel,
onImportExcel,
onImportSuccess,
}: NavbarProps) {
const fileInputRef = React.useRef<HTMLInputElement>(null);
const [isImporting, setIsImporting] = React.useState(false);
const handleUploadFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0];
if (!file) return;
const formData = new FormData();
formData.append('file', file);
setIsImporting(true);
try {
const res = await fetch('/api/import', {
method: 'POST',
body: formData,
});
if (res.ok) {
alert('فایل اکسل با موفقیت وارد و لیدها ثبت شدند.');
if (onImportSuccess) onImportSuccess();
} else {
const d = await res.json();
alert('خطا در ایمپورت اکسل: ' + (d.error || 'فرمت نامعتبر'));
}
} catch (err: any) {
alert('خطا در آپلود فایل: ' + err.message);
} finally {
setIsImporting(false);
if (e.target) e.target.value = '';
}
};
const handleOpenNewLead = onOpenNewLead || onNewLead || (() => {});
const handleOpenImport = () => {
if (fileInputRef.current) fileInputRef.current.click();
else if (onImportExcel) onImportExcel();
};
const navItems = [
{ id: 'dashboard', label: 'داشبورد مدیریتی', icon: LayoutDashboard },
{
id: 'today',
label: 'وظایف امروز',
icon: CalendarCheck,
badge: dueTodayCount,
isAlert: overdueCount > 0,
},
{ id: 'pipeline', label: 'پایپ‌لاین فروش', icon: GitPullRequest },
{ id: 'onboarding', label: 'آنبوردینگ مشتریان', icon: GraduationCap },
{ id: 'settings', label: 'تنظیمات و قوانین', icon: Settings },
];
return (
<header className="sticky top-0 z-40 bg-white/95 backdrop-blur-md border-b border-slate-200/80 shadow-xs">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-16 gap-4">
{/* Logo & Platform Info */}
<div className="flex items-center gap-3.5 shrink-0">
<div className="w-10 h-10 rounded-xl bg-gradient-to-br from-sky-600 via-sky-700 to-indigo-800 flex items-center justify-center text-white font-extrabold text-xl shadow-sm shadow-sky-500/20 ring-1 ring-sky-500/30">
E
</div>
<div>
<div className="flex items-center gap-2">
<span className="font-extrabold text-base sm:text-lg text-slate-900 tracking-tight">
اکیپا <span className="text-sky-600">CRM</span>
</span>
<span className="inline-flex items-center gap-1 text-[10px] font-bold bg-sky-50 text-sky-700 px-2 py-0.5 rounded-full border border-sky-200/70">
<span className="w-1.5 h-1.5 rounded-full bg-emerald-500 animate-pulse"></span>
اتاق‌های فرار
</span>
</div>
<p className="text-[11px] text-slate-500 hidden sm:flex items-center gap-1 font-medium">
سیستم جذب، فروش و آنبوردینگ
</p>
</div>
</div>
{/* Segmented Pill Tabs */}
<nav className="hidden md:flex items-center bg-slate-100/80 p-1 rounded-xl border border-slate-200/60">
{navItems.map((item) => {
const Icon = item.icon;
const isActive = activeTab === item.id;
return (
<button
key={item.id}
onClick={() => setActiveTab(item.id)}
className={`flex items-center gap-2 px-3 py-1.5 rounded-lg text-xs font-semibold transition-all duration-150 cursor-pointer ${
isActive
? 'bg-white text-sky-700 shadow-xs font-bold'
: 'text-slate-600 hover:text-slate-900 hover:bg-white/60'
}`}
>
<Icon className={`w-3.5 h-3.5 ${isActive ? 'text-sky-600' : 'text-slate-500'}`} />
<span>{item.label}</span>
{item.badge !== undefined && item.badge > 0 && (
<span
className={`text-[10px] font-bold px-1.5 py-0.2 rounded-full tabular-nums text-white ${
item.isAlert ? 'bg-rose-500 shadow-xs shadow-rose-500/30' : 'bg-amber-500'
}`}
>
{item.badge}
</span>
)}
</button>
);
})}
</nav>
{/* Action Toolbar */}
<div className="flex items-center gap-2 shrink-0">
<input
type="file"
ref={fileInputRef}
onChange={handleUploadFile}
accept=".xlsx,.xls"
className="hidden"
/>
<button
onClick={onExportExcel}
title="دریافت فایل اکسل لیدها"
className="hidden sm:inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-slate-700 bg-white hover:bg-slate-50 border border-slate-200 rounded-lg shadow-xs hover:border-slate-300 transition-all cursor-pointer"
>
<Download className="w-3.5 h-3.5 text-emerald-600" />
<span>خروجی اکسل</span>
</button>
<button
onClick={handleOpenImport}
disabled={isImporting}
title="بارگذاری فایل اکسل"
className="hidden sm:inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-slate-700 bg-white hover:bg-slate-50 border border-slate-200 rounded-lg shadow-xs hover:border-slate-300 transition-all cursor-pointer"
>
<Upload className="w-3.5 h-3.5 text-indigo-600" />
<span>{isImporting ? 'در حال ورود...' : 'ورودی اکسل'}</span>
</button>
<button
onClick={handleOpenNewLead}
className="inline-flex items-center gap-1.5 px-3.5 py-1.5 text-xs font-bold text-white bg-sky-600 hover:bg-sky-700 active:bg-sky-800 rounded-lg shadow-xs shadow-sky-600/20 hover:shadow-sm transition-all cursor-pointer"
>
<Plus className="w-4 h-4 stroke-[2.5]" />
<span>ثبت لید جدید</span>
</button>
</div>
</div>
{/* Mobile Subnav */}
<div className="flex md:hidden items-center justify-between py-2 border-t border-slate-100 overflow-x-auto gap-2">
{navItems.map((item) => {
const Icon = item.icon;
const isActive = activeTab === item.id;
return (
<button
key={item.id}
onClick={() => setActiveTab(item.id)}
className={`flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold whitespace-nowrap cursor-pointer transition-all ${
isActive
? 'bg-sky-50 text-sky-700 border border-sky-200'
: 'text-slate-600 hover:bg-slate-100'
}`}
>
<Icon className="w-3.5 h-3.5" />
<span>{item.label}</span>
{item.badge !== undefined && item.badge > 0 && (
<span className="text-[10px] font-bold px-1 rounded-full bg-rose-500 text-white tabular-nums">
{item.badge}
</span>
)}
</button>
);
})}
</div>
</div>
</header>
);
}