feat: complete admin panel major functionalities including responsive layout, recharts, custom modals, inline editing, and loading states

This commit is contained in:
parsa committed 2026-06-12 16:19:57 +03:30
1 parent ee041d4e52
commit a7ebb8d792
33 files changed
+1311 -173

No files matched your search

@@ -1,13 +1,16 @@
import { useState } from 'react';
import { Outlet } from 'react-router-dom';
import Sidebar from './Sidebar';
import Topbar from './Topbar';
export default function Layout() {
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
return (
<div className="flex min-h-screen bg-gray-50 text-gray-900 font-vazir" dir="rtl">
<Sidebar />
<div className="flex-1 flex flex-col min-h-screen">
<Topbar />
<div className="flex min-h-screen bg-gray-50 text-gray-900 font-vazir relative overflow-hidden" dir="rtl">
<Sidebar isOpen={isMobileMenuOpen} setIsOpen={setIsMobileMenuOpen} />
<div className="flex-1 flex flex-col min-h-screen w-full lg:w-auto">
<Topbar toggleMenu={() => setIsMobileMenuOpen(!isMobileMenuOpen)} />
<main className="flex-1 p-6 overflow-y-auto">
<Outlet />
</main>
@@ -0,0 +1,11 @@
import { Navigate, Outlet } from 'react-router-dom';
export default function ProtectedRoute() {
const token = localStorage.getItem('adminToken');
if (!token) {
return <Navigate to="/login" replace />;
}
return <Outlet />;
}
@@ -10,11 +10,27 @@ const menuItems = [
{ icon: Settings, label: 'تنظیمات', path: '/settings' },
];
export default function Sidebar() {
interface SidebarProps {
isOpen: boolean;
setIsOpen: (val: boolean) => void;
}
export default function Sidebar({ isOpen, setIsOpen }: SidebarProps) {
const location = useLocation();
return (
<aside className="w-64 bg-white border-l border-gray-200 h-screen sticky top-0 flex flex-col font-vazir shadow-sm">
<>
{/* Mobile Backdrop */}
{isOpen && (
<div
className="fixed inset-0 bg-black/50 z-40 lg:hidden backdrop-blur-sm"
onClick={() => setIsOpen(false)}
/>
)}
<aside className={`w-64 bg-white border-l border-gray-200 h-screen fixed lg:sticky top-0 flex flex-col font-vazir shadow-sm z-50 transform transition-transform duration-300 ease-in-out ${
isOpen ? 'translate-x-0' : 'translate-x-full lg:translate-x-0'
}`}>
<div className="h-16 flex items-center justify-center border-b border-gray-200">
<h1 className="text-xl font-black text-purple-600">کانی‌نا | ادمین‌پنل</h1>
</div>
@@ -48,5 +64,6 @@ export default function Sidebar() {
</button>
</div>
</aside>
</>
);
}
+15 -5
View File
@@ -1,10 +1,20 @@
import { Bell, Search, UserCircle } from 'lucide-react';
import { Bell, Search, UserCircle, Menu } from 'lucide-react';
export default function Topbar() {
interface TopbarProps {
toggleMenu: () => void;
}
export default function Topbar({ toggleMenu }: TopbarProps) {
return (
<header className="h-16 bg-white border-b border-gray-200 flex items-center justify-between px-6 sticky top-0 z-10 shadow-sm font-vazir">
<div className="flex-1 flex items-center max-w-xl">
<div className="relative w-full">
<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-10 shadow-sm font-vazir">
<div className="flex-1 flex items-center gap-3 max-w-xl">
<button
onClick={toggleMenu}
className="lg:hidden p-2 text-gray-500 hover:bg-gray-100 rounded-lg transition-colors"
>
<Menu className="w-6 h-6" />
</button>
<div className="relative w-full hidden sm:block">
<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" />
</div>
@@ -0,0 +1,61 @@
import React from 'react';
import { X, AlertTriangle } from 'lucide-react';
interface ConfirmModalProps {
isOpen: boolean;
title: string;
message: string;
onConfirm: () => void;
onCancel: () => void;
confirmText?: string;
cancelText?: string;
isDestructive?: boolean;
}
export default function ConfirmModal({
isOpen,
title,
message,
onConfirm,
onCancel,
confirmText = 'تایید',
cancelText = 'لغو',
isDestructive = true
}: ConfirmModalProps) {
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/40 backdrop-blur-sm">
<div className="bg-white rounded-2xl shadow-xl w-full max-w-md overflow-hidden animate-in fade-in zoom-in duration-200">
<div className="flex items-center justify-between p-4 border-b border-gray-100">
<h3 className="text-lg font-bold text-gray-900 flex items-center gap-2">
{isDestructive && <AlertTriangle className="w-5 h-5 text-red-500" />}
{title}
</h3>
<button onClick={onCancel} className="text-gray-400 hover:bg-gray-100 p-1.5 rounded-lg transition-colors">
<X className="w-5 h-5" />
</button>
</div>
<div className="p-6">
<p className="text-gray-600 font-medium leading-relaxed">{message}</p>
</div>
<div className="p-4 border-t border-gray-100 bg-gray-50 flex justify-end gap-3">
<button
onClick={onCancel}
className="px-4 py-2 font-bold text-gray-700 bg-white border border-gray-200 rounded-xl hover:bg-gray-50 transition-colors"
>
{cancelText}
</button>
<button
onClick={onConfirm}
className={`px-4 py-2 font-bold text-white rounded-xl transition-colors ${
isDestructive ? 'bg-red-600 hover:bg-red-700 shadow-md shadow-red-200' : 'bg-purple-600 hover:bg-purple-700 shadow-md shadow-purple-200'
}`}
>
{confirmText}
</button>
</div>
</div>
</div>
);
}
@@ -0,0 +1,7 @@
import React from 'react';
export default function Skeleton({ className = '' }: { className?: string }) {
return (
<div className={`animate-pulse bg-gray-200 rounded-md ${className}`}></div>
);
}
@@ -0,0 +1,17 @@
import React from 'react';
export default function Spinner({ size = 'md', className = '' }: { size?: 'sm' | 'md' | 'lg', className?: string }) {
const sizeClasses = {
sm: 'w-4 h-4',
md: 'w-6 h-6',
lg: 'w-8 h-8'
};
return (
<div className={`inline-block animate-spin rounded-full border-2 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite] ${sizeClasses[size]} ${className}`} role="status">
<span className="!absolute !-m-px !h-px !w-px !overflow-hidden !whitespace-nowrap !border-0 !p-0 ![clip:rect(0,0,0,0)]">
درحال بارگذاری...
</span>
</div>
);
}