mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
feat: implement dedicated mobile layout with bottom navigation and store selection.
This commit is contained in:
1 parent
583a2469c9
commit
7f4c172eeb
1 file changed
+72
-9
@@ -1,12 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* MobileLayout - Layout dédié pour l'application mobile
|
* MobileLayout - Layout dédié pour l'application mobile
|
||||||
* Affiche le magasin sélectionné de manière visible et une navigation bottom
|
* Affiche le magasin sélectionné de manière visible et une navigation bottom
|
||||||
|
* Inclut son propre StoreProvider
|
||||||
*/
|
*/
|
||||||
import { ReactNode, useState } from "react";
|
import { ReactNode, useState, useEffect } from "react";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { Menu, X, Store, ChevronDown, LogOut } from "lucide-react";
|
import { Menu, Store, ChevronDown, LogOut } from "lucide-react";
|
||||||
import { useAuthUnified } from "@/hooks/useAuthUnified";
|
import { useAuthUnified } from "@/hooks/useAuthUnified";
|
||||||
import { useStore } from "@/contexts/StoreContext";
|
import { StoreProvider } from "@/contexts/StoreContext";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@/components/ui/sheet";
|
||||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||||
@@ -16,13 +17,17 @@ import type { Group } from "@shared/schema";
|
|||||||
interface MobileLayoutProps {
|
interface MobileLayoutProps {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
title?: string;
|
title?: string;
|
||||||
showBackButton?: boolean;
|
|
||||||
onBack?: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function MobileLayout({ children, title }: MobileLayoutProps) {
|
// Inner component that uses the store context
|
||||||
const { user } = useAuthUnified();
|
function MobileLayoutInner({ children, title, selectedStoreId, setSelectedStoreId, stores, user }: {
|
||||||
const { selectedStoreId, setSelectedStoreId, stores } = useStore();
|
children: ReactNode;
|
||||||
|
title?: string;
|
||||||
|
selectedStoreId: number | null;
|
||||||
|
setSelectedStoreId: (id: number | null) => void;
|
||||||
|
stores: Group[];
|
||||||
|
user: any;
|
||||||
|
}) {
|
||||||
const [menuOpen, setMenuOpen] = useState(false);
|
const [menuOpen, setMenuOpen] = useState(false);
|
||||||
|
|
||||||
// Get selected store name
|
// Get selected store name
|
||||||
@@ -56,7 +61,7 @@ export default function MobileLayout({ children, title }: MobileLayoutProps) {
|
|||||||
width: '100%',
|
width: '100%',
|
||||||
maxWidth: '100vw',
|
maxWidth: '100vw',
|
||||||
overflowX: 'hidden',
|
overflowX: 'hidden',
|
||||||
paddingBottom: '80px' // Space for bottom nav
|
paddingBottom: '80px'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{/* Header fixe */}
|
{/* Header fixe */}
|
||||||
@@ -178,3 +183,61 @@ export default function MobileLayout({ children, title }: MobileLayoutProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main MobileLayout component with StoreProvider
|
||||||
|
export default function MobileLayout({ children, title }: MobileLayoutProps) {
|
||||||
|
const { user } = useAuthUnified();
|
||||||
|
|
||||||
|
// Store state management
|
||||||
|
const [selectedStoreId, setSelectedStoreId] = useState<number | null>(() => {
|
||||||
|
const saved = localStorage.getItem('selectedStoreId');
|
||||||
|
return saved ? parseInt(saved) : null;
|
||||||
|
});
|
||||||
|
const [sidebarCollapsed, setSidebarCollapsed] = useState(false);
|
||||||
|
const [mobileMenuOpen, setMobileMenuOpen] = useState(false);
|
||||||
|
const [storeInitialized, setStoreInitialized] = useState(false);
|
||||||
|
|
||||||
|
// Fetch stores
|
||||||
|
const { data: stores = [] } = useQuery<Group[]>({
|
||||||
|
queryKey: ['/api/groups'],
|
||||||
|
enabled: !!user,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize store selection
|
||||||
|
useEffect(() => {
|
||||||
|
if (user && stores.length > 0) {
|
||||||
|
if ((user.role === 'directeur' || user.role === 'manager') && !selectedStoreId && stores.length === 1) {
|
||||||
|
const singleStoreId = stores[0].id;
|
||||||
|
setSelectedStoreId(singleStoreId);
|
||||||
|
localStorage.setItem('selectedStoreId', singleStoreId.toString());
|
||||||
|
}
|
||||||
|
setStoreInitialized(true);
|
||||||
|
}
|
||||||
|
}, [user, stores, selectedStoreId]);
|
||||||
|
|
||||||
|
const storeContextValue = {
|
||||||
|
selectedStoreId,
|
||||||
|
setSelectedStoreId,
|
||||||
|
stores,
|
||||||
|
sidebarCollapsed,
|
||||||
|
setSidebarCollapsed,
|
||||||
|
mobileMenuOpen,
|
||||||
|
setMobileMenuOpen,
|
||||||
|
storeInitialized
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StoreProvider value={storeContextValue}>
|
||||||
|
<MobileLayoutInner
|
||||||
|
title={title}
|
||||||
|
selectedStoreId={selectedStoreId}
|
||||||
|
setSelectedStoreId={setSelectedStoreId}
|
||||||
|
stores={stores}
|
||||||
|
user={user}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</MobileLayoutInner>
|
||||||
|
</StoreProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user