89 lines
3.3 KiB
TypeScript
89 lines
3.3 KiB
TypeScript
import React, { useState } from 'react'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { LayoutDashboard, Send, Settings2, MapPin, UserPlus, Menu, X, LogOut, Store, Package } from 'lucide-react'
|
|
import { useAuth } from '../lib/auth-context'
|
|
|
|
const NAV = [
|
|
{ to: '/dashboard', label: 'Dashboard', icon: LayoutDashboard },
|
|
{ to: '/admins', label: 'Admins', icon: UserPlus },
|
|
{ to: '/regions', label: 'Regions', icon: MapPin },
|
|
{ to: '/stores', label: 'Stores', icon: Store },
|
|
{ to: '/products', label: 'Products', icon: Package },
|
|
{ to: '/send-notifications', label: 'Send Admin Notifications', icon: Send },
|
|
{ to: '/constants', label: 'App Constants', icon: Settings2 },
|
|
] as const
|
|
|
|
export function AppShell({ children }: { children: React.ReactNode }) {
|
|
const [open, setOpen] = useState(false)
|
|
const { staff, logout } = useAuth()
|
|
|
|
return (
|
|
<div className="min-h-screen bg-gray-50">
|
|
<header className="sticky top-0 z-40 flex h-14 items-center justify-between border-b border-gray-200 bg-white px-4">
|
|
<div className="flex items-center gap-3">
|
|
<button
|
|
type="button"
|
|
aria-label="Toggle menu"
|
|
aria-expanded={open}
|
|
onClick={() => setOpen((v) => !v)}
|
|
className="rounded-lg p-2 text-gray-700 hover:bg-gray-100 md:hidden"
|
|
>
|
|
{open ? <X className="h-6 w-6" /> : <Menu className="h-6 w-6" />}
|
|
</button>
|
|
<Link to="/dashboard" className="text-lg font-bold text-gray-900">
|
|
Freshyo Superadmin
|
|
</Link>
|
|
</div>
|
|
|
|
<div className="flex items-center gap-3">
|
|
{staff?.name && (
|
|
<span className="hidden text-sm text-gray-500 sm:inline">{staff.name}</span>
|
|
)}
|
|
<button
|
|
type="button"
|
|
onClick={logout}
|
|
className="flex items-center gap-1.5 rounded-lg border border-gray-200 px-3 py-1.5 text-sm font-medium text-gray-700 hover:bg-gray-100"
|
|
>
|
|
<LogOut className="h-4 w-4" />
|
|
Logout
|
|
</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div className="flex">
|
|
<aside
|
|
className={`fixed inset-y-0 left-0 z-30 w-64 transform border-r border-gray-200 bg-white pt-14 transition-transform duration-200 ease-in-out md:static md:translate-x-0 md:pt-0 ${
|
|
open ? 'translate-x-0' : '-translate-x-full'
|
|
}`}
|
|
>
|
|
<nav className="space-y-1 p-3">
|
|
{NAV.map(({ to, label, icon: Icon }) => (
|
|
<Link
|
|
key={to}
|
|
to={to}
|
|
onClick={() => setOpen(false)}
|
|
activeProps={{ className: 'bg-blue-50 text-blue-700' }}
|
|
inactiveProps={{ className: 'text-gray-700' }}
|
|
className="flex items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium hover:bg-gray-100"
|
|
>
|
|
<Icon className="h-5 w-5" />
|
|
{label}
|
|
</Link>
|
|
))}
|
|
</nav>
|
|
</aside>
|
|
|
|
{open && (
|
|
<div
|
|
className="fixed inset-0 z-20 bg-black/30 md:hidden"
|
|
onClick={() => setOpen(false)}
|
|
/>
|
|
)}
|
|
|
|
<main className="min-h-[calc(100vh-3.5rem)] flex-1">{children}</main>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default AppShell
|