From 025bca2e38516b574f35563888fc463515cd425f Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Tue, 9 Sep 2025 08:49:02 +0000 Subject: [PATCH] Improve task module loading for director and manager roles Enhance Layout component to auto-select a store for director/manager roles and add a useEffect hook in Tasks page to invalidate the "/api/tasks" query when selectedStoreId changes for these roles. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/yiEpJFx --- client/src/components/Layout.tsx | 9 ++++++++- client/src/pages/Tasks.tsx | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/src/components/Layout.tsx b/client/src/components/Layout.tsx index c34387c..86771d1 100644 --- a/client/src/components/Layout.tsx +++ b/client/src/components/Layout.tsx @@ -98,7 +98,14 @@ export default function Layout({ children }: LayoutProps) { // IMPORTANT FIX: Pour les rôles directeur/manager, forcer la sélection d'un magasin spécifique // si aucun n'est sélectionné et qu'ils n'ont accès qu'à un seul magasin if ((user.role === 'directeur' || user.role === 'manager') && !selectedStoreId && stores.length === 1 && !needsUpdate) { - console.log('🏪 Auto-selecting single available store for directeur/manager:', stores[0].id); + console.log('🏪 Auto-selecting single available store for directeur/manager:', { + storeId: stores[0].id, + storeName: stores[0].name, + userRole: user.role, + userId: user.id, + previousSelectedStoreId: selectedStoreId, + timestamp: new Date().toISOString() + }); const singleStoreId = stores[0].id; setSelectedStoreId(singleStoreId); localStorage.setItem('selectedStoreId', singleStoreId.toString()); diff --git a/client/src/pages/Tasks.tsx b/client/src/pages/Tasks.tsx index 1610f3a..592d3e7 100644 --- a/client/src/pages/Tasks.tsx +++ b/client/src/pages/Tasks.tsx @@ -331,6 +331,18 @@ export default function Tasks() { timestamp: new Date().toISOString() }); + // Force refresh when selectedStoreId changes for directeur/manager + useEffect(() => { + if (user && (user.role === 'directeur' || user.role === 'manager') && selectedStoreId) { + console.log('🔄 FORCE REFRESH: selectedStoreId changed for directeur/manager:', { + userRole: user.role, + selectedStoreId, + timestamp: new Date().toISOString() + }); + queryClient.invalidateQueries({ queryKey: ["/api/tasks"] }); + } + }, [selectedStoreId, user, queryClient]); + // États locaux const [searchTerm, setSearchTerm] = useState(""); const [statusFilter, setStatusFilter] = useState("all");