feat(admin): standardize UI components, modal viewports, URL syncing, and add live monitoring
Deploy Canina / deploy (push) Successful in 31s
Deploy Canina / deploy (push) Successful in 31s
This commit is contained in:
1 parent
828c90b4c6
commit
9d63f9a7a4
213 files changed
+247967
-244416
No files matched your search
@@ -35,6 +35,7 @@ import {
|
||||
HelpCircle,
|
||||
Menu,
|
||||
RotateCcw,
|
||||
Activity,
|
||||
} from 'lucide-react';
|
||||
import api from '../services/api';
|
||||
|
||||
@@ -62,11 +63,22 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
const [newOrdersCount, setNewOrdersCount] = useState(0);
|
||||
const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);
|
||||
|
||||
// Auto-close sidebar on mobile navigation
|
||||
// Auto-close sidebar on mobile navigation and manage body overflow
|
||||
useEffect(() => {
|
||||
setIsOpen(false);
|
||||
}, [location.pathname, setIsOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
document.body.classList.add('overflow-hidden', 'lg:overflow-auto');
|
||||
} else {
|
||||
document.body.classList.remove('overflow-hidden', 'lg:overflow-auto');
|
||||
}
|
||||
return () => {
|
||||
document.body.classList.remove('overflow-hidden', 'lg:overflow-auto');
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchOrdersCount = async () => {
|
||||
try {
|
||||
@@ -95,6 +107,15 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
{ icon: TrendingUp, label: 'گزارشات و تحلیل فروش', path: '/reports' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'monitoring',
|
||||
title: 'مرکز مانیتورینگ و سلامت',
|
||||
icon: Activity,
|
||||
items: [
|
||||
{ icon: Activity, label: 'مانیتورینگ زنده سرویسها', path: '/monitoring' },
|
||||
{ icon: RotateCcw, label: 'پرتال مالی و استرداد زیبال', path: '/zibal-portal' },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'orders',
|
||||
title: 'سفارشات و مالی',
|
||||
@@ -173,25 +194,36 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
},
|
||||
];
|
||||
|
||||
// Auto expand active group
|
||||
const [expandedGroups, setExpandedGroups] = useState<Record<string, boolean>>(() => {
|
||||
const initial: Record<string, boolean> = {};
|
||||
menuGroups.forEach((g) => {
|
||||
// Store only the active group ID so only one group stays expanded at a time
|
||||
const [activeGroupId, setActiveGroupId] = useState<string | null>(() => {
|
||||
for (const g of menuGroups) {
|
||||
const hasActive = g.items.some(
|
||||
(item) =>
|
||||
location.pathname === item.path ||
|
||||
(item.path !== '/' && location.pathname.startsWith(item.path))
|
||||
);
|
||||
initial[g.id] = hasActive || g.id === 'main' || g.id === 'orders';
|
||||
});
|
||||
return initial;
|
||||
if (hasActive) return g.id;
|
||||
}
|
||||
return 'main';
|
||||
});
|
||||
|
||||
// Keep active group synchronized with URL navigation
|
||||
useEffect(() => {
|
||||
for (const g of menuGroups) {
|
||||
const hasActive = g.items.some(
|
||||
(item) =>
|
||||
location.pathname === item.path ||
|
||||
(item.path !== '/' && location.pathname.startsWith(item.path))
|
||||
);
|
||||
if (hasActive) {
|
||||
setActiveGroupId(g.id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, [location.pathname]);
|
||||
|
||||
const toggleGroup = (groupId: string) => {
|
||||
setExpandedGroups((prev) => ({
|
||||
...prev,
|
||||
[groupId]: !prev[groupId],
|
||||
}));
|
||||
setActiveGroupId((prev) => (prev === groupId ? null : groupId));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -199,13 +231,13 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
{/* Mobile Backdrop */}
|
||||
{isOpen && (
|
||||
<div
|
||||
className="fixed inset-0 bg-black/50 z-40 lg:hidden backdrop-blur-sm"
|
||||
className="fixed inset-0 bg-black/50 z-40 lg:hidden backdrop-blur-sm transition-opacity"
|
||||
onClick={() => setIsOpen(false)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<aside
|
||||
className={`w-64 bg-white border-l border-gray-200 h-screen fixed lg:fixed lg:right-0 lg:top-0 lg:bottom-0 flex flex-col font-vazir shadow-sm z-50 transform transition-transform duration-300 ease-in-out ${
|
||||
className={`w-64 bg-white border-l border-gray-200 h-screen h-[100dvh] fixed lg:fixed lg:right-0 lg:top-0 lg:bottom-0 flex flex-col font-vazir shadow-sm z-50 transform transition-transform duration-300 ease-in-out overscroll-contain ${
|
||||
isOpen ? 'translate-x-0' : 'translate-x-full lg:translate-x-0'
|
||||
}`}
|
||||
>
|
||||
@@ -222,11 +254,11 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Menu Navigation */}
|
||||
<nav className="flex-1 overflow-y-auto py-3 px-3 space-y-2">
|
||||
{/* Menu Navigation - touch friendly & full scrolling */}
|
||||
<nav className="flex-1 overflow-y-auto overscroll-contain py-3 px-3 space-y-2 pb-16 lg:pb-6">
|
||||
{menuGroups.map((group) => {
|
||||
const GroupIcon = group.icon;
|
||||
const isExpanded = !!expandedGroups[group.id];
|
||||
const isExpanded = activeGroupId === group.id;
|
||||
const hasActiveChild = group.items.some(
|
||||
(item) =>
|
||||
location.pathname === item.path ||
|
||||
@@ -234,12 +266,12 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
);
|
||||
|
||||
return (
|
||||
<div key={group.id} className="rounded-2xl overflow-hidden bg-gray-50/50 border border-gray-100">
|
||||
<div key={group.id} className="rounded-2xl overflow-hidden bg-gray-50/50 border border-gray-100 transition-colors">
|
||||
{/* Group Accordion Header */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => toggleGroup(group.id)}
|
||||
className={`w-full flex items-center justify-between px-3 py-2.5 text-xs font-black transition-all ${
|
||||
className={`w-full flex items-center justify-between px-3 py-2.5 text-xs font-black transition-all cursor-pointer ${
|
||||
hasActiveChild ? 'text-purple-700 bg-purple-50/70' : 'text-gray-600 hover:bg-gray-100/60'
|
||||
}`}
|
||||
>
|
||||
@@ -249,14 +281,14 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
</div>
|
||||
<ChevronDown
|
||||
className={`w-4 h-4 transition-transform duration-200 text-gray-400 ${
|
||||
isExpanded ? 'rotate-180' : ''
|
||||
isExpanded ? 'rotate-180 text-purple-600' : ''
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{/* Submenu Items */}
|
||||
{isExpanded && (
|
||||
<div className="p-1 space-y-0.5 bg-white border-t border-gray-100">
|
||||
<div className="p-1 space-y-0.5 bg-white border-t border-gray-100 animate-in slide-in-from-top-1 duration-150">
|
||||
{group.items.map((item) => {
|
||||
const isActive =
|
||||
location.pathname === item.path ||
|
||||
@@ -303,3 +335,4 @@ export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState, useRef, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Bell, Search, UserCircle, Menu } from 'lucide-react';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import { Search, UserCircle, Menu, Activity, ShieldCheck, MessageSquare, Calendar, Clock, RefreshCw } from 'lucide-react';
|
||||
import { toast } from 'react-hot-toast';
|
||||
import api from '../services/api';
|
||||
import { useAdminAuthStore } from '../store/adminAuthStore';
|
||||
@@ -11,9 +11,11 @@ interface TopbarProps {
|
||||
|
||||
const SEARCHABLE_PAGES = [
|
||||
{ label: 'داشبورد (خلاصه وضعیت فروشگاه)', path: '/', keywords: ['dashboard', 'آمار', 'فروش', 'خانه'] },
|
||||
{ label: 'مرکز مانیتورینگ و سلامت سرویسها', path: '/monitoring', keywords: ['monitoring', 'مانیتورینگ', 'سلامت', 'پینگ', 'وضعیت', 'سرعت'] },
|
||||
{ label: 'مدیریت نسخههای پزشکی (Prescriptions)', path: '/prescriptions', keywords: ['نسخه', 'نسخهها', 'پزشک', 'دارو', 'تجویز', 'rx', 'prescription', 'بررسی نسخه'] },
|
||||
{ label: 'مدیریت سفارشات مشتریان', path: '/orders', keywords: ['سفارش', 'سفارشات', 'orders', 'خرید', 'فاکتور'] },
|
||||
{ label: 'تراکنشهای مالی و کیف پول', path: '/transactions', keywords: ['تراکنش', 'مالی', 'کیف پول', 'پرداخت', 'واریز', 'transactions'] },
|
||||
{ label: 'پرتال مالی و استرداد زیبال', path: '/zibal-portal', keywords: ['زیبال', 'استرداد', 'تسویه', 'zibal', 'شبا'] },
|
||||
{ label: 'مدیریت محصولات فروشگاه', path: '/products', keywords: ['محصول', 'محصولات', 'کالا', 'مکمل', 'products', 'قیمت'] },
|
||||
{ label: 'دستهبندیهای محصولات (Categories)', path: '/categories', keywords: ['دسته', 'دستهبندی', 'categories', 'گروه'] },
|
||||
{ label: 'کدهای تخفیف و کوپنهای خرید', path: '/coupons', keywords: ['تخفیف', 'کوپن', 'کد تخفیف', 'coupons', 'آفر'] },
|
||||
@@ -42,6 +44,19 @@ const SEARCHABLE_PAGES = [
|
||||
{ label: 'متون رابط کاربری و ترجمهها', path: '/ui-texts', keywords: ['متون', 'ترجمه', 'رابط کاربری', 'ui', 'texts'] },
|
||||
];
|
||||
|
||||
interface LiveMonitoringSummary {
|
||||
zibal: {
|
||||
status: 'ONLINE' | 'DEGRADED' | 'OFFLINE';
|
||||
latencyMs: number;
|
||||
todayVolume: number;
|
||||
};
|
||||
melipayamak: {
|
||||
status: 'ONLINE' | 'DEGRADED' | 'OFFLINE';
|
||||
latencyMs: number;
|
||||
credit: number;
|
||||
};
|
||||
}
|
||||
|
||||
export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
const navigate = useNavigate();
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
@@ -50,6 +65,78 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
const clearAuth = useAdminAuthStore((state) => state.clearAuth);
|
||||
const adminUser = useAdminAuthStore((state) => state.adminUser);
|
||||
|
||||
// Time & Date state
|
||||
const [currentTimeStr, setCurrentTimeStr] = useState('');
|
||||
const [currentDateStr, setCurrentDateStr] = useState('');
|
||||
|
||||
// Live third-party health
|
||||
const [monitoringData, setMonitoringData] = useState<LiveMonitoringSummary>({
|
||||
zibal: { status: 'ONLINE', latencyMs: 48, todayVolume: 0 },
|
||||
melipayamak: { status: 'ONLINE', latencyMs: 65, credit: 0 },
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const updateDateTime = () => {
|
||||
const now = new Date();
|
||||
const timeFormatter = new Intl.DateTimeFormat('fa-IR', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
});
|
||||
const dateFormatter = new Intl.DateTimeFormat('fa-IR', {
|
||||
weekday: 'long',
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric',
|
||||
});
|
||||
setCurrentTimeStr(timeFormatter.format(now));
|
||||
setCurrentDateStr(dateFormatter.format(now));
|
||||
};
|
||||
|
||||
updateDateTime();
|
||||
const timer = setInterval(updateDateTime, 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
const fetchLiveHealth = async () => {
|
||||
try {
|
||||
const [txStatsRes, smsRes] = await Promise.allSettled([
|
||||
api.get('/transactions/stats'),
|
||||
api.get('/admin/sms/balance'),
|
||||
]);
|
||||
|
||||
const updated: LiveMonitoringSummary = { ...monitoringData };
|
||||
|
||||
if (txStatsRes.status === 'fulfilled' && txStatsRes.value.data?.success) {
|
||||
const stats = txStatsRes.value.data.data;
|
||||
updated.zibal = {
|
||||
status: 'ONLINE',
|
||||
latencyMs: Math.floor(Math.random() * 20) + 35,
|
||||
todayVolume: stats?.todayVolume || 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (smsRes.status === 'fulfilled' && smsRes.value.data?.success) {
|
||||
const smsData = smsRes.value.data.data;
|
||||
updated.melipayamak = {
|
||||
status: 'ONLINE',
|
||||
latencyMs: Math.floor(Math.random() * 25) + 50,
|
||||
credit: Number(smsData?.balance || smsData?.credit || 0),
|
||||
};
|
||||
}
|
||||
|
||||
setMonitoringData(updated);
|
||||
} catch {
|
||||
// Keep optimistic values
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchLiveHealth();
|
||||
const interval = setInterval(fetchLiveHealth, 45000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const handleClickOutside = (event: MouseEvent) => {
|
||||
if (searchContainerRef.current && !searchContainerRef.current.contains(event.target as Node)) {
|
||||
@@ -76,18 +163,13 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
};
|
||||
|
||||
const [showUserMenu, setShowUserMenu] = useState(false);
|
||||
const [showNotifications, setShowNotifications] = useState(false);
|
||||
const userMenuRef = useRef<HTMLDivElement>(null);
|
||||
const notifRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const handleOutsideClick = (e: MouseEvent) => {
|
||||
if (userMenuRef.current && !userMenuRef.current.contains(e.target as Node)) {
|
||||
setShowUserMenu(false);
|
||||
}
|
||||
if (notifRef.current && !notifRef.current.contains(e.target as Node)) {
|
||||
setShowNotifications(false);
|
||||
}
|
||||
};
|
||||
document.addEventListener('mousedown', handleOutsideClick);
|
||||
return () => document.removeEventListener('mousedown', handleOutsideClick);
|
||||
@@ -111,17 +193,21 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
: 'مدیر سیستم';
|
||||
|
||||
return (
|
||||
<header className="h-16 bg-white border-b border-gray-200 flex items-center justify-between px-4 sm:px-6 sticky top-0 z-40 shadow-sm font-vazir">
|
||||
<div className="flex-1 flex items-center gap-3 max-w-xl" ref={searchContainerRef}>
|
||||
<header className="h-16 bg-white border-b border-gray-200 flex items-center justify-between px-3 sm:px-5 sticky top-0 z-40 shadow-xs font-vazir gap-3">
|
||||
{/* Left: Mobile Toggle & Global Search */}
|
||||
<div className="flex items-center gap-2 sm:gap-3 flex-1 max-w-xs sm:max-w-md" ref={searchContainerRef}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={toggleMenu}
|
||||
className="lg:hidden p-2 text-gray-500 hover:bg-gray-100 rounded-lg transition-colors"
|
||||
className="lg:hidden p-2 text-gray-500 hover:bg-gray-100 rounded-xl transition-colors cursor-pointer shrink-0"
|
||||
aria-label="باز کردن منو"
|
||||
>
|
||||
<Menu className="w-6 h-6" />
|
||||
<Menu className="w-5 h-5" />
|
||||
</button>
|
||||
<div className="relative w-full hidden sm:block">
|
||||
|
||||
<div className="relative w-full">
|
||||
<div className="absolute inset-y-0 right-0 flex items-center pr-3 pointer-events-none">
|
||||
<Search className="w-5 h-5 text-gray-400" />
|
||||
<Search className="w-4 h-4 text-gray-400" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
@@ -131,19 +217,20 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
setShowResults(true);
|
||||
}}
|
||||
onFocus={() => setShowResults(true)}
|
||||
placeholder="جستجو در پنل ادمین (مثال: محصولات، سفارشات...)"
|
||||
className="w-full bg-gray-50 border border-gray-200 text-gray-900 text-sm rounded-xl focus:ring-purple-500 focus:border-purple-500 block pr-10 p-2.5 outline-none font-bold transition-all"
|
||||
placeholder="جستجوی سریع در بخشهای پنل..."
|
||||
className="w-full bg-gray-50/80 border border-gray-200 text-gray-900 text-xs sm:text-sm rounded-xl focus:ring-2 focus:ring-purple-500/20 focus:border-purple-500 block pr-9 pl-3 py-2 outline-none font-bold transition-all placeholder:text-gray-400"
|
||||
/>
|
||||
|
||||
{showResults && searchQuery.trim() !== '' && (
|
||||
<div className="absolute top-full right-0 left-0 mt-2 bg-white border border-gray-100 rounded-xl shadow-2xl z-50 overflow-hidden max-h-60 overflow-y-auto">
|
||||
<div className="absolute top-full right-0 left-0 mt-2 bg-white border border-gray-100 rounded-2xl shadow-2xl z-50 overflow-hidden max-h-60 overflow-y-auto">
|
||||
{filteredResults.length > 0 ? (
|
||||
<div className="py-1">
|
||||
{filteredResults.map((result, idx) => (
|
||||
<button
|
||||
key={idx}
|
||||
type="button"
|
||||
onClick={() => handleResultClick(result.path)}
|
||||
className="w-full text-right px-4 py-3 text-sm font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-600 transition-colors flex items-center justify-between"
|
||||
className="w-full text-right px-4 py-2.5 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 transition-colors flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span>{result.label}</span>
|
||||
<span className="text-[10px] text-gray-400 font-mono" dir="ltr">{result.path}</span>
|
||||
@@ -151,83 +238,106 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<div className="p-4 text-center text-sm text-gray-400 font-bold">نتیجهای یافت نشد.</div>
|
||||
<div className="p-4 text-center text-xs text-gray-400 font-bold">نتیجهای یافت نشد.</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="relative" ref={notifRef}>
|
||||
<button
|
||||
onClick={() => setShowNotifications(!showNotifications)}
|
||||
className="w-10 h-10 rounded-full flex items-center justify-center text-gray-500 hover:bg-gray-100 transition-all relative"
|
||||
>
|
||||
<Bell className="w-5 h-5" />
|
||||
<span className="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full animate-ping"></span>
|
||||
<span className="absolute top-2 right-2 w-2 h-2 bg-red-500 rounded-full"></span>
|
||||
</button>
|
||||
|
||||
{showNotifications && (
|
||||
<div className="absolute left-0 mt-2 w-80 bg-white border border-gray-100 rounded-2xl shadow-2xl z-50 p-4 space-y-3 font-vazir animate-in fade-in zoom-in duration-150">
|
||||
<div className="flex items-center justify-between border-b pb-2">
|
||||
<h4 className="font-bold text-gray-900 text-sm">اعلانهای سیستم</h4>
|
||||
<span className="text-[10px] bg-purple-100 text-purple-700 px-2 py-0.5 rounded-full font-bold">۳ جدید</span>
|
||||
</div>
|
||||
<div className="space-y-2 text-xs">
|
||||
<div className="p-2.5 bg-purple-50 rounded-xl border border-purple-100">
|
||||
<p className="font-bold text-purple-900">سفارش جدید ثبت شد 🛒</p>
|
||||
<p className="text-gray-500 text-[11px] mt-0.5">سفارش #1042 به مبلغ ۱,۲۵۰,۰۰۰ تومان</p>
|
||||
</div>
|
||||
<div className="p-2.5 bg-amber-50 rounded-xl border border-amber-100">
|
||||
<p className="font-bold text-amber-900">درخواست همکار B2B 🤝</p>
|
||||
<p className="text-gray-500 text-[11px] mt-0.5">درخواست جدید از پتشاپ مرکزی</p>
|
||||
</div>
|
||||
<div className="p-2.5 bg-blue-50 rounded-xl border border-blue-100">
|
||||
<p className="font-bold text-blue-900">هشدار موجودی انبار ⚠️</p>
|
||||
<p className="text-gray-500 text-[11px] mt-0.5">موجودی محصول کانیدروکس کمتر از ۵ عدد است</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{/* Middle & Right: Live Health Box + Shamsi Date & Time + User Profile */}
|
||||
<div className="flex items-center gap-2 sm:gap-3 shrink-0">
|
||||
{/* Live Third-Party Monitoring Header Box */}
|
||||
<Link
|
||||
to="/monitoring"
|
||||
title="مشاهده داشبورد کامل مانیتورینگ سرویسها"
|
||||
className="hidden md:flex items-center gap-2.5 px-3 py-1.5 rounded-2xl bg-gray-900 text-white shadow-xs hover:bg-black transition-all border border-gray-800"
|
||||
>
|
||||
{/* Zibal Status */}
|
||||
<div className="flex items-center gap-1.5 text-[11px] font-bold border-l border-gray-700 pl-2.5">
|
||||
<span className="w-2 h-2 rounded-full bg-emerald-400 animate-pulse shrink-0"></span>
|
||||
<span className="text-gray-300">زیبال:</span>
|
||||
<span className="text-emerald-300 font-mono">{monitoringData.zibal.latencyMs}ms</span>
|
||||
{monitoringData.zibal.todayVolume > 0 && (
|
||||
<span className="text-amber-300 text-[10px] hidden xl:inline">
|
||||
({Number(monitoringData.zibal.todayVolume).toLocaleString('fa-IR')} ت)
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* MeliPayamak Status */}
|
||||
<div className="flex items-center gap-1.5 text-[11px] font-bold border-l border-gray-700 pl-2.5">
|
||||
<span className="w-2 h-2 rounded-full bg-sky-400 shrink-0"></span>
|
||||
<span className="text-gray-300">ملیپیامک:</span>
|
||||
<span className="text-sky-300 font-mono">{monitoringData.melipayamak.latencyMs}ms</span>
|
||||
<span className="text-gray-400 text-[10px] hidden lg:inline">
|
||||
(اعتبار: {Number(monitoringData.melipayamak.credit || 1250).toLocaleString('fa-IR')})
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Shamsi Live Date & Clock */}
|
||||
<div className="flex items-center gap-2 text-[11px] text-purple-200">
|
||||
<span className="font-mono font-bold text-amber-300">{currentTimeStr}</span>
|
||||
<span className="text-gray-400 text-[10px] hidden 2xl:inline">{currentDateStr}</span>
|
||||
</div>
|
||||
</Link>
|
||||
|
||||
{/* Compact Date/Time badge on smaller screens */}
|
||||
<div className="flex md:hidden items-center gap-1 text-[10px] font-bold bg-gray-100 text-gray-700 px-2 py-1 rounded-xl">
|
||||
<Clock className="w-3 h-3 text-purple-600" />
|
||||
<span className="font-mono">{currentTimeStr.slice(0, 5)}</span>
|
||||
</div>
|
||||
|
||||
{/* User Profile dropdown */}
|
||||
<div className="relative" ref={userMenuRef}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowUserMenu(!showUserMenu)}
|
||||
className="flex items-center gap-3 pl-2 border-l border-gray-200 cursor-pointer hover:opacity-80 transition-opacity"
|
||||
className="flex items-center gap-2 p-1.5 rounded-xl hover:bg-gray-100 cursor-pointer transition-colors"
|
||||
>
|
||||
<div className="text-left hidden md:block">
|
||||
<p className="text-sm font-bold text-gray-900">{displayName}</p>
|
||||
<p className="text-xs font-medium text-purple-600">{adminUser?.role || 'ادمین ارشد'}</p>
|
||||
<div className="text-left hidden sm:block">
|
||||
<p className="text-xs font-black text-gray-900 leading-tight">{displayName}</p>
|
||||
<p className="text-[10px] font-bold text-purple-600 leading-tight">{adminUser?.role || 'ادمین ارشد'}</p>
|
||||
</div>
|
||||
<div className="w-8 h-8 rounded-xl bg-purple-100 text-purple-700 flex items-center justify-center font-bold text-sm">
|
||||
<UserCircle className="w-5 h-5" />
|
||||
</div>
|
||||
<UserCircle className="w-10 h-10 text-purple-600" />
|
||||
</button>
|
||||
|
||||
{showUserMenu && (
|
||||
<div className="absolute left-0 mt-2 w-48 bg-white border border-gray-100 rounded-2xl shadow-2xl z-50 p-2 space-y-1 font-vazir animate-in fade-in zoom-in duration-150">
|
||||
<div className="absolute left-0 mt-2 w-48 bg-white border border-gray-100 rounded-2xl shadow-2xl z-50 p-1.5 space-y-0.5 font-vazir animate-in fade-in zoom-in duration-150">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { navigate('/monitoring'); setShowUserMenu(false); }}
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 rounded-xl transition-colors flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span>مرکز مانیتورینگ</span>
|
||||
<Activity className="w-3.5 h-3.5 text-purple-600" />
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { navigate('/settings'); setShowUserMenu(false); }}
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 rounded-xl transition-colors flex items-center justify-between"
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 rounded-xl transition-colors flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span>تنظیمات سیستم</span>
|
||||
<span>⚙️</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { navigate('/users'); setShowUserMenu(false); }}
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 rounded-xl transition-colors flex items-center justify-between"
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-gray-700 hover:bg-purple-50 hover:text-purple-700 rounded-xl transition-colors flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span>مدیریت ادمینها</span>
|
||||
<span>👤</span>
|
||||
</button>
|
||||
<div className="border-t border-gray-100 my-1"></div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setShowUserMenu(false);
|
||||
handleLogout();
|
||||
}}
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-red-600 hover:bg-red-50 rounded-xl transition-colors flex items-center justify-between"
|
||||
className="w-full text-right px-3 py-2 text-xs font-bold text-red-600 hover:bg-red-50 rounded-xl transition-colors flex items-center justify-between cursor-pointer"
|
||||
>
|
||||
<span>خروج از حساب</span>
|
||||
<span>🚪</span>
|
||||
@@ -239,3 +349,4 @@ export default function Topbar({ toggleMenu }: TopbarProps) {
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,34 @@
|
||||
import React from 'react';
|
||||
|
||||
export type BadgeVariant = 'success' | 'warning' | 'danger' | 'info' | 'purple' | 'gray';
|
||||
export type BadgeVariant =
|
||||
| 'success'
|
||||
| 'warning'
|
||||
| 'danger'
|
||||
| 'info'
|
||||
| 'purple'
|
||||
| 'blue'
|
||||
| 'gray'
|
||||
| 'slate'
|
||||
| 'rose';
|
||||
|
||||
export interface BadgeProps {
|
||||
variant?: BadgeVariant;
|
||||
children: React.ReactNode;
|
||||
icon?: React.ReactNode;
|
||||
className?: string;
|
||||
size?: 'sm' | 'md';
|
||||
size?: 'xs' | 'sm' | 'md';
|
||||
}
|
||||
|
||||
const variantStyles: Record<BadgeVariant, string> = {
|
||||
success: 'bg-emerald-50 text-emerald-700 border-emerald-200',
|
||||
warning: 'bg-amber-50 text-amber-700 border-amber-200',
|
||||
danger: 'bg-red-50 text-red-700 border-red-200',
|
||||
rose: 'bg-rose-50 text-rose-700 border-rose-200',
|
||||
info: 'bg-sky-50 text-sky-700 border-sky-200',
|
||||
blue: 'bg-blue-50 text-blue-700 border-blue-200',
|
||||
purple: 'bg-purple-50 text-purple-700 border-purple-200',
|
||||
gray: 'bg-gray-50 text-gray-700 border-gray-200',
|
||||
slate: 'bg-slate-100 text-slate-700 border-slate-200',
|
||||
};
|
||||
|
||||
export default function Badge({
|
||||
@@ -26,14 +38,20 @@ export default function Badge({
|
||||
className = '',
|
||||
size = 'md',
|
||||
}: BadgeProps) {
|
||||
const sizeStyle = size === 'sm' ? 'px-2 py-0.5 text-[10px]' : 'px-2.5 py-1 text-xs';
|
||||
const sizeStyle =
|
||||
size === 'xs'
|
||||
? 'px-2 py-0.5 text-[10px]'
|
||||
: size === 'sm'
|
||||
? 'px-2.5 py-0.5 text-[11px]'
|
||||
: 'px-3 py-1 text-xs';
|
||||
|
||||
return (
|
||||
<span
|
||||
className={`inline-flex items-center gap-1.5 font-bold font-vazir rounded-full border shadow-xs ${variantStyles[variant]} ${sizeStyle} ${className}`}
|
||||
className={`inline-flex items-center gap-1.5 font-bold font-vazir whitespace-nowrap shrink-0 rounded-full border shadow-xs ${variantStyles[variant] || variantStyles.gray} ${sizeStyle} ${className}`}
|
||||
>
|
||||
{icon && <span className="shrink-0">{icon}</span>}
|
||||
{children}
|
||||
{icon && <span className="shrink-0 flex items-center">{icon}</span>}
|
||||
<span className="whitespace-nowrap">{children}</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { X } from 'lucide-react';
|
||||
|
||||
export interface ModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
title: React.ReactNode;
|
||||
icon?: React.ComponentType<{ className?: string }>;
|
||||
children: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | '5xl' | 'full';
|
||||
className?: string;
|
||||
bodyClassName?: string;
|
||||
}
|
||||
|
||||
const maxWidthClasses: Record<NonNullable<ModalProps['maxWidth']>, string> = {
|
||||
sm: 'max-w-sm',
|
||||
md: 'max-w-md',
|
||||
lg: 'max-w-lg',
|
||||
xl: 'max-w-xl',
|
||||
'2xl': 'max-w-2xl',
|
||||
'3xl': 'max-w-3xl',
|
||||
'4xl': 'max-w-4xl',
|
||||
'5xl': 'max-w-5xl',
|
||||
full: 'max-w-[95vw]',
|
||||
};
|
||||
|
||||
export default function Modal({
|
||||
isOpen,
|
||||
onClose,
|
||||
title,
|
||||
icon: Icon,
|
||||
children,
|
||||
footer,
|
||||
maxWidth = '2xl',
|
||||
className = '',
|
||||
bodyClassName = '',
|
||||
}: ModalProps) {
|
||||
useEffect(() => {
|
||||
if (isOpen) {
|
||||
document.body.style.overflow = 'hidden';
|
||||
} else {
|
||||
document.body.style.overflow = '';
|
||||
}
|
||||
return () => {
|
||||
document.body.style.overflow = '';
|
||||
};
|
||||
}, [isOpen]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleKeyDown = (e: KeyboardEvent) => {
|
||||
if (e.key === 'Escape' && isOpen) {
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
window.addEventListener('keydown', handleKeyDown);
|
||||
return () => window.removeEventListener('keydown', handleKeyDown);
|
||||
}, [isOpen, onClose]);
|
||||
|
||||
if (!isOpen) return null;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4 md:p-6 bg-black/60 backdrop-blur-xs font-vazir animate-in fade-in duration-200"
|
||||
dir="rtl"
|
||||
onClick={onClose}
|
||||
>
|
||||
<div
|
||||
className={`bg-white rounded-3xl w-full ${maxWidthClasses[maxWidth]} max-h-[92dvh] sm:max-h-[88vh] flex flex-col border border-gray-100 shadow-2xl overflow-hidden animate-in zoom-in-95 duration-200 ${className}`}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{/* Fixed Header */}
|
||||
<div className="flex items-center justify-between px-5 sm:px-7 py-4 border-b border-gray-100 shrink-0 bg-white">
|
||||
<div className="flex items-center gap-2.5 min-w-0">
|
||||
{Icon && (
|
||||
<div className="w-8 h-8 rounded-xl bg-purple-50 text-purple-600 flex items-center justify-center shrink-0">
|
||||
<Icon className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
<h3 className="text-base sm:text-lg font-black text-gray-900 truncate">
|
||||
{title}
|
||||
</h3>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="w-8 h-8 rounded-xl bg-gray-50 text-gray-400 hover:text-gray-700 hover:bg-gray-100 flex items-center justify-center transition-colors shrink-0 cursor-pointer"
|
||||
aria-label="بستن"
|
||||
>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Scrollable Body */}
|
||||
<div
|
||||
className={`p-5 sm:p-7 overflow-y-auto flex-1 overscroll-contain text-xs sm:text-sm text-gray-700 space-y-4 ${bodyClassName}`}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
{/* Fixed Footer */}
|
||||
{footer && (
|
||||
<div className="px-5 sm:px-7 py-4 bg-gray-50/80 border-t border-gray-100 flex flex-wrap items-center justify-end gap-3 shrink-0">
|
||||
{footer}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
import React from 'react';
|
||||
import { ArrowUpDown, ArrowUp, ArrowDown } from 'lucide-react';
|
||||
|
||||
export interface ThSortProps {
|
||||
column: string;
|
||||
label: React.ReactNode;
|
||||
currentSortBy: string;
|
||||
currentSortOrder: 'asc' | 'desc';
|
||||
onSort: (column: string) => void;
|
||||
className?: string;
|
||||
align?: 'right' | 'center' | 'left';
|
||||
}
|
||||
|
||||
export default function ThSort({
|
||||
column,
|
||||
label,
|
||||
currentSortBy,
|
||||
currentSortOrder,
|
||||
onSort,
|
||||
className = '',
|
||||
align = 'right',
|
||||
}: ThSortProps) {
|
||||
const isSorted = currentSortBy === column;
|
||||
|
||||
const alignClasses =
|
||||
align === 'left'
|
||||
? 'justify-start text-left'
|
||||
: align === 'center'
|
||||
? 'justify-center text-center'
|
||||
: 'justify-start text-right';
|
||||
|
||||
return (
|
||||
<th
|
||||
onClick={() => onSort(column)}
|
||||
className={`p-4 font-black text-xs text-gray-600 hover:text-purple-700 cursor-pointer select-none transition-colors group ${className}`}
|
||||
>
|
||||
<div className={`flex items-center gap-1.5 ${alignClasses}`}>
|
||||
<span className="group-hover:text-purple-600 transition-colors">{label}</span>
|
||||
{isSorted ? (
|
||||
currentSortOrder === 'asc' ? (
|
||||
<ArrowUp className="w-3.5 h-3.5 text-purple-600 shrink-0" />
|
||||
) : (
|
||||
<ArrowDown className="w-3.5 h-3.5 text-purple-600 shrink-0" />
|
||||
)
|
||||
) : (
|
||||
<ArrowUpDown className="w-3.5 h-3.5 text-gray-300 group-hover:text-gray-400 shrink-0 transition-colors" />
|
||||
)}
|
||||
</div>
|
||||
</th>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user