2025-11-29 15:39:57 +05:30
|
|
|
"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
|
2026-02-20 18:21:24 +05:30
|
|
|
// Hide sidebar for root (/), /handler routes (Stack Auth routes), and /auth routes
|
|
|
|
|
const shouldShowSidebar = pathname !== "/" && !pathname.startsWith("/handler") && !pathname.startsWith("/auth");
|
2025-11-29 15:39:57 +05:30
|
|
|
|
2026-01-30 17:08:15 +05:30
|
|
|
// Check if we're in workflow editor mode or superadmin runs - collapse sidebar by default
|
2025-11-29 15:39:57 +05:30
|
|
|
const isWorkflowEditor = /^\/workflow\/\d+/.test(pathname);
|
2026-01-30 17:08:15 +05:30
|
|
|
const isSuperadmin = pathname.startsWith("/superadmin");
|
2025-11-29 15:39:57 +05:30
|
|
|
|
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).
|
2025-11-29 15:39:57 +05:30
|
|
|
return (
|
2026-01-30 17:08:15 +05:30
|
|
|
<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>
|
2025-11-29 15:39:57 +05:30
|
|
|
</div>
|
2026-02-18 13:16:49 +05:30
|
|
|
</header>
|
|
|
|
|
)}
|
2025-11-29 15:39:57 +05:30
|
|
|
|
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>
|
2025-11-29 15:39:57 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-02-18 13:16:49 +05:30
|
|
|
)}
|
2025-11-29 15:39:57 +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>
|
|
|
|
|
)}
|
2025-11-29 15:39:57 +05:30
|
|
|
</SidebarProvider>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AppLayout;
|