dograh/ui/src/components/layout/AppLayout.tsx

77 lines
2.4 KiB
TypeScript
Raw Normal View History

"use client";
import { usePathname } from "next/navigation";
import React, { ReactNode } from "react";
import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar";
import { AppSidebar } from "./AppSidebar";
interface AppLayoutProps {
children: ReactNode;
headerActions?: ReactNode;
stickyTabs?: ReactNode;
}
const AppLayout: React.FC<AppLayoutProps> = ({
children,
headerActions,
stickyTabs,
}) => {
const pathname = usePathname();
// Check if current route should have sidebar
// Hide sidebar for root (/), /handler routes (Stack Auth routes), and /auth routes
const shouldShowSidebar = pathname !== "/" && !pathname.startsWith("/handler") && !pathname.startsWith("/auth");
// Check if we're in workflow editor mode or superadmin runs - collapse sidebar by default
const isWorkflowEditor = /^\/workflow\/\d+/.test(pathname);
const isSuperadmin = pathname.startsWith("/superadmin");
2026-02-18 13:16:49 +05:30
// Always render SidebarProvider to keep the component tree shape consistent
// across route changes (avoids React hooks ordering violations during navigation).
return (
<SidebarProvider defaultOpen={!isWorkflowEditor && !isSuperadmin}>
2026-02-18 13:16:49 +05:30
{shouldShowSidebar ? (
<div className="flex min-h-screen w-full">
<AppSidebar />
<SidebarInset className="flex-1">
{/* Optional header area for specific pages */}
{headerActions && (
<header className="sticky top-0 z-50 w-full border-b bg-background">
<div className="container mx-auto px-4 py-4">
<div className="flex items-center justify-center">
{headerActions}
</div>
</div>
2026-02-18 13:16:49 +05:30
</header>
)}
2026-02-18 13:16:49 +05:30
{/* Optional sticky tabs */}
{stickyTabs && (
<div className="sticky top-0 z-40 bg-[#2a2e39] border-b border-gray-700">
<div className="container mx-auto px-4">
<div className="flex items-center justify-center py-2">
{stickyTabs}
</div>
</div>
</div>
2026-02-18 13:16:49 +05:30
)}
2026-02-18 13:16:49 +05:30
{/* Main content area */}
<main className="flex-1">
{children}
</main>
</SidebarInset>
</div>
) : (
<div className="flex-1 w-full">
{children}
</div>
)}
</SidebarProvider>
);
};
export default AppLayout;