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
This commit is contained in:
michaelschal committed 2025-09-09 08:49:02 +00:00
1 parent 27305d5706
commit 025bca2e38
2 files changed
+20 -1

No files matched your search

+8 -1
View File
@@ -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());
+12
View File
@@ -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<string>("all");