Skip to content

A full-featured CRM built with React, shadcn/ui, and Supabase.

add mobile header

Jean-Baptiste Kaiser6e8cae3f7a18
diff --git a/registry.json b/registry.json
index 3cf1cc21..fd7daaa2 100644
--- a/registry.json
+++ b/registry.json
@@ -372,6 +372,14 @@
"path": "src/components/atomic-crm/layout/TopToolbar.tsx",
"type": "registry:component"
},
+ {
+ "path": "src/components/atomic-crm/layout/MobileLayout.tsx",
+ "type": "registry:component"
+ },
+ {
+ "path": "src/components/atomic-crm/layout/MobileHeader.tsx",
+ "type": "registry:component"
+ },
{
"path": "src/components/atomic-crm/layout/Layout.tsx",
"type": "registry:component"
diff --git a/src/components/atomic-crm/layout/MobileHeader.tsx b/src/components/atomic-crm/layout/MobileHeader.tsx
new file mode 100644
index 00000000..2ea7dc08
--- /dev/null
+++ b/src/components/atomic-crm/layout/MobileHeader.tsx
@@ -0,0 +1,116 @@
+import { useTheme } from "@/components/admin/theme-provider";
+import { UserMenu } from "@/components/admin/user-menu";
+import {
+ DropdownMenuItem,
+ DropdownMenuPortal,
+ DropdownMenuSub,
+ DropdownMenuSubContent,
+ DropdownMenuSubTrigger,
+} from "@/components/ui/dropdown-menu";
+import { useUserMenu } from "@/hooks/user-menu-context";
+import { cn } from "@/lib/utils";
+import { Check, Moon, Settings, Sun, User } from "lucide-react";
+import { CanAccess } from "ra-core";
+import { Link } from "react-router";
+
+import { useConfigurationContext } from "../root/ConfigurationContext";
+
+const MobileHeader = () => {
+ const { darkModeLogo, lightModeLogo, title } = useConfigurationContext();
+
+ return (
+ <nav className="flex-grow">
+ <header className="bg-secondary">
+ <div className="px-4">
+ <div className="flex justify-between items-center flex-1">
+ <Link
+ to="/"
+ className="flex items-center gap-2 text-secondary-foreground no-underline py-3"
+ >
+ <img
+ className="[.light_&]:hidden h-6"
+ src={darkModeLogo}
+ alt={title}
+ />
+ <img
+ className="[.dark_&]:hidden h-6"
+ src={lightModeLogo}
+ alt={title}
+ />
+ <h1 className="text-xl font-semibold">{title}</h1>
+ </Link>
+ <div className="flex items-center">
+ <UserMenu>
+ <ThemeMenu />
+ <ConfigurationMenu />
+ <CanAccess resource="sales" action="list">
+ <UsersMenu />
+ </CanAccess>
+ </UserMenu>
+ </div>
+ </div>
+ </div>
+ </header>
+ </nav>
+ );
+};
+
+const UsersMenu = () => {
+ const { onClose } = useUserMenu() ?? {};
+ return (
+ <DropdownMenuItem asChild onClick={onClose}>
+ <Link to="/sales" className="flex items-center gap-2">
+ <User /> Users
+ </Link>
+ </DropdownMenuItem>
+ );
+};
+
+const ConfigurationMenu = () => {
+ const { onClose } = useUserMenu() ?? {};
+ return (
+ <DropdownMenuItem asChild onClick={onClose}>
+ <Link to="/settings" className="flex items-center gap-2">
+ <Settings />
+ My info
+ </Link>
+ </DropdownMenuItem>
+ );
+};
+
+const ThemeMenu = () => {
+ const { theme, setTheme } = useTheme();
+ return (
+ <DropdownMenuSub>
+ <DropdownMenuSubTrigger className="p-0">
+ <DropdownMenuItem
+ onSelect={(e) => {
+ e.preventDefault();
+ }}
+ >
+ <Sun className="rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
+ <Moon className="absolute rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
+ Theme
+ </DropdownMenuItem>
+ </DropdownMenuSubTrigger>
+ <DropdownMenuPortal>
+ <DropdownMenuSubContent>
+ <DropdownMenuItem onClick={() => setTheme("light")}>
+ Light
+ <Check className={cn("ml-auto", theme !== "light" && "hidden")} />
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={() => setTheme("dark")}>
+ Dark
+ <Check className={cn("ml-auto", theme !== "dark" && "hidden")} />
+ </DropdownMenuItem>
+ <DropdownMenuItem onClick={() => setTheme("system")}>
+ System
+ <Check className={cn("ml-auto", theme !== "system" && "hidden")} />
+ </DropdownMenuItem>
+ </DropdownMenuSubContent>
+ </DropdownMenuPortal>
+ </DropdownMenuSub>
+ );
+};
+
+export default MobileHeader;
diff --git a/src/components/atomic-crm/layout/MobileLayout.tsx b/src/components/atomic-crm/layout/MobileLayout.tsx
new file mode 100644
index 00000000..7a84d6d8
--- /dev/null
+++ b/src/components/atomic-crm/layout/MobileLayout.tsx
@@ -0,0 +1,21 @@
+import { Suspense, type ReactNode } from "react";
+import { ErrorBoundary } from "react-error-boundary";
+import { Notification } from "@/components/admin/notification";
+import { Error } from "@/components/admin/error";
+import { Skeleton } from "@/components/ui/skeleton";
+
+import MobileHeader from "./MobileHeader";
+
+export const MobileLayout = ({ children }: { children: ReactNode }) => (
+ <>
+ <MobileHeader />
+ <main className="max-w-screen-xl mx-auto pt-4 px-4" id="main-content">
+ <ErrorBoundary FallbackComponent={Error}>
+ <Suspense fallback={<Skeleton className="h-12 w-12 rounded-full" />}>
+ {children}
+ </Suspense>
+ </ErrorBoundary>
+ </main>
+ <Notification />
+ </>
+);
diff --git a/src/components/atomic-crm/root/CRM.tsx b/src/components/atomic-crm/root/CRM.tsx
index 9bfd8401..103f46cc 100644
--- a/src/components/atomic-crm/root/CRM.tsx
+++ b/src/components/atomic-crm/root/CRM.tsx
@@ -19,6 +19,7 @@ import { Dashboard } from "../dashboard/Dashboard";
import { MobileDashboard } from "../dashboard/MobileDashboard";
import deals from "../deals";
import { Layout } from "../layout/Layout";
+import { MobileLayout } from "../layout/MobileLayout";
import { SignupPage } from "../login/SignupPage";
import {
authProvider as defaultAuthProvider,
@@ -193,7 +194,7 @@ const MobileAdmin = (props: CoreAdminProps) => {
return (
<Admin
store={localStorageStore(undefined, "CRM")}
- layout={Layout}
+ layout={MobileLayout}
loginPage={StartPage}
i18nProvider={i18nProvider}
dashboard={MobileDashboard}