Co-authored-by: renee-png <262607627+renee-png@users.noreply.github.com>
213 lines
7.8 KiB
TypeScript
213 lines
7.8 KiB
TypeScript
import { Link, useLocation, useNavigate } from "@tanstack/react-router";
|
|
import { useAuth } from "@/lib/auth";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Briefcase,
|
|
Users,
|
|
FileText,
|
|
Receipt,
|
|
ShieldCheck,
|
|
LogOut,
|
|
LayoutDashboard,
|
|
Calendar as CalendarIcon,
|
|
CheckSquare,
|
|
MessageSquare,
|
|
Activity,
|
|
DollarSign,
|
|
FolderOpen,
|
|
Files as FilesIcon,
|
|
Settings as SettingsIcon,
|
|
ClipboardList,
|
|
UserPlus,
|
|
User as UserIcon,
|
|
Inbox as InboxIcon,
|
|
CreditCard,
|
|
Archive as ArchiveIcon,
|
|
BarChart3,
|
|
} from "lucide-react";
|
|
import { cn } from "@/lib/utils";
|
|
import type { ReactNode } from "react";
|
|
import { HeaderTimer } from "@/components/timer/header-timer";
|
|
import { QuickAddTime, QuickAddExpense } from "@/components/quick-add/quick-add";
|
|
import { QuickAddCallLog } from "@/components/quick-add/quick-add-call-log";
|
|
import { DateCalculator } from "@/components/date-calculator";
|
|
import { NotificationBell } from "@/components/notifications/notification-bell";
|
|
import { JusticeIcon } from "@/components/justice-icon";
|
|
import { GlobalSearch } from "@/components/global-search";
|
|
|
|
interface NavItem {
|
|
to: string;
|
|
label: string;
|
|
icon: typeof Briefcase;
|
|
adminOnly?: boolean;
|
|
}
|
|
|
|
const NAV: NavItem[] = (() => {
|
|
const dashboard: NavItem = { to: "/", label: "Dashboard", icon: LayoutDashboard };
|
|
const main: NavItem[] = [
|
|
{ to: "/calendar", label: "Calendar", icon: CalendarIcon },
|
|
{ to: "/cases", label: "Cases", icon: Briefcase },
|
|
{ to: "/clients", label: "Clients", icon: Users },
|
|
{ to: "/collections", label: "Collections", icon: DollarSign },
|
|
{ to: "/contacts", label: "Contacts", icon: UserPlus },
|
|
{ to: "/files", label: "Files", icon: FilesIcon },
|
|
{ to: "/forms", label: "Forms", icon: ClipboardList },
|
|
{ to: "/inbox", label: "Inbox", icon: InboxIcon },
|
|
{ to: "/invoices", label: "Invoices", icon: Receipt },
|
|
{ to: "/messages", label: "Messages", icon: MessageSquare },
|
|
{ to: "/payments", label: "Payments", icon: CreditCard },
|
|
{ to: "/documents", label: "Pleadings", icon: FolderOpen },
|
|
{ to: "/reports", label: "Reports", icon: BarChart3 },
|
|
{ to: "/status", label: "Status Updates", icon: Activity },
|
|
{ to: "/tasks", label: "Tasks", icon: CheckSquare },
|
|
].sort((a, b) => a.label.localeCompare(b.label));
|
|
const bottom: NavItem[] = [
|
|
{ to: "/archive", label: "Archive", icon: ArchiveIcon },
|
|
{ to: "/settings", label: "Settings", icon: SettingsIcon },
|
|
{ to: "/admin/users", label: "Users", icon: ShieldCheck, adminOnly: true },
|
|
];
|
|
return [dashboard, ...main, ...bottom];
|
|
})();
|
|
void FileText;
|
|
|
|
export function AppShell({ children }: { children: ReactNode }) {
|
|
const { user, signOut, isAdmin, roles } = useAuth();
|
|
const location = useLocation();
|
|
const navigate = useNavigate();
|
|
|
|
const handleSignOut = async () => {
|
|
await signOut();
|
|
navigate({ to: "/login" });
|
|
};
|
|
|
|
return (
|
|
<div className="flex min-h-screen bg-background">
|
|
{/* Sidebar */}
|
|
<aside className="hidden md:flex w-64 flex-col bg-sidebar text-sidebar-foreground border-r border-sidebar-border">
|
|
<div className="px-6 py-5 border-b border-sidebar-border flex items-center gap-2.5">
|
|
<div className="h-9 w-9 rounded-md bg-sidebar-primary flex items-center justify-center p-1">
|
|
<JusticeIcon className="h-full w-full" invert />
|
|
</div>
|
|
<div className="leading-tight">
|
|
<div className="font-serif text-sm whitespace-nowrap">Stage Law Firm, PLLC</div>
|
|
<div className="text-[10px] uppercase tracking-widest text-sidebar-foreground/60">Law Firm Suite</div>
|
|
</div>
|
|
</div>
|
|
|
|
<GlobalSearch />
|
|
|
|
<nav className="flex-1 px-3 py-4 space-y-0.5">
|
|
{NAV.filter((n) => !n.adminOnly || isAdmin).map((item) => {
|
|
const active = item.to === "/" ? location.pathname === "/" : location.pathname.startsWith(item.to);
|
|
const Icon = item.icon;
|
|
return (
|
|
<Link
|
|
key={item.to}
|
|
to={item.to}
|
|
className={cn(
|
|
"flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors",
|
|
active
|
|
? "bg-sidebar-accent text-sidebar-accent-foreground"
|
|
: "text-sidebar-foreground/80 hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground",
|
|
)}
|
|
>
|
|
<Icon className="h-4 w-4" />
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
|
|
<div className="px-4 py-4 border-t border-sidebar-border">
|
|
<div className="text-xs text-sidebar-foreground/70 truncate mb-0.5">{user?.email}</div>
|
|
<div className="text-[10px] uppercase tracking-wider text-sidebar-foreground/50 mb-3">
|
|
{roles.join(" · ") || "no role"}
|
|
</div>
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="w-full justify-start text-sidebar-foreground/80 hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground"
|
|
onClick={handleSignOut}
|
|
>
|
|
<LogOut className="h-4 w-4 mr-2" />
|
|
Sign out
|
|
</Button>
|
|
</div>
|
|
</aside>
|
|
|
|
{/* Mobile top bar */}
|
|
<div className="md:hidden fixed top-0 inset-x-0 h-14 bg-sidebar text-sidebar-foreground border-b border-sidebar-border flex items-center justify-between px-4 z-30">
|
|
<Link to="/" className="flex items-center gap-2">
|
|
<JusticeIcon className="h-5 w-5" invert />
|
|
<span className="font-serif text-lg">Counsel</span>
|
|
</Link>
|
|
<Button variant="ghost" size="sm" onClick={handleSignOut} className="text-sidebar-foreground">
|
|
<LogOut className="h-4 w-4" />
|
|
</Button>
|
|
</div>
|
|
|
|
<main className="flex-1 min-w-0 md:ml-0 mt-14 md:mt-0">
|
|
{/* Desktop top toolbar */}
|
|
<div className="hidden md:flex items-center justify-end gap-2 px-6 py-2 border-b bg-card/50">
|
|
<QuickAddTime />
|
|
<QuickAddExpense />
|
|
<QuickAddCallLog />
|
|
<DateCalculator />
|
|
<HeaderTimer />
|
|
<NotificationBell />
|
|
<Link
|
|
to="/settings/profile"
|
|
className="inline-flex items-center justify-center h-9 w-9 rounded-md border border-input bg-background hover:bg-accent hover:text-accent-foreground transition-colors"
|
|
aria-label="My profile"
|
|
title="My profile"
|
|
>
|
|
<UserIcon className="h-4 w-4" />
|
|
</Link>
|
|
</div>
|
|
<div className="md:hidden flex overflow-x-auto gap-1 px-3 py-2 border-b bg-card">
|
|
{NAV.filter((n) => !n.adminOnly || isAdmin).map((item) => {
|
|
const active = item.to === "/" ? location.pathname === "/" : location.pathname.startsWith(item.to);
|
|
return (
|
|
<Link
|
|
key={item.to}
|
|
to={item.to}
|
|
className={cn(
|
|
"px-3 py-1.5 rounded-md text-xs font-medium whitespace-nowrap",
|
|
active ? "bg-primary text-primary-foreground" : "text-muted-foreground",
|
|
)}
|
|
>
|
|
{item.label}
|
|
</Link>
|
|
);
|
|
})}
|
|
</div>
|
|
{children}
|
|
</main>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function PageHeader({
|
|
title,
|
|
description,
|
|
actions,
|
|
}: {
|
|
title: string;
|
|
description?: string;
|
|
actions?: ReactNode;
|
|
}) {
|
|
return (
|
|
<div className="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3 mb-6">
|
|
<div>
|
|
<h1 className="font-serif text-3xl text-foreground">{title}</h1>
|
|
{description && <p className="text-sm text-muted-foreground mt-1">{description}</p>}
|
|
</div>
|
|
{actions && <div className="flex gap-2">{actions}</div>}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function PageContainer({ children }: { children: ReactNode }) {
|
|
return <div className="p-6 md:p-8 max-w-[1400px] mx-auto">{children}</div>;
|
|
}
|