"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 = ({ 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"); // Always render SidebarProvider to keep the component tree shape consistent // across route changes (avoids React hooks ordering violations during navigation). return ( {shouldShowSidebar ? (
{/* Optional header area for specific pages */} {headerActions && (
{headerActions}
)} {/* Optional sticky tabs */} {stickyTabs && (
{stickyTabs}
)} {/* Main content area */}
{children}
) : (
{children}
)}
); }; export default AppLayout;