diff --git a/attached_assets/{16A95A8D-7826-4AD7-8519-09E89B6A0F44}_1756805143343.png b/attached_assets/{16A95A8D-7826-4AD7-8519-09E89B6A0F44}_1756805143343.png new file mode 100644 index 0000000..6eb1166 Binary files /dev/null and b/attached_assets/{16A95A8D-7826-4AD7-8519-09E89B6A0F44}_1756805143343.png differ diff --git a/attached_assets/{8B6C5975-064E-4FE4-A8C3-3176DFB1BEBE}_1756805383966.png b/attached_assets/{8B6C5975-064E-4FE4-A8C3-3176DFB1BEBE}_1756805383966.png new file mode 100644 index 0000000..ca699ac Binary files /dev/null and b/attached_assets/{8B6C5975-064E-4FE4-A8C3-3176DFB1BEBE}_1756805383966.png differ diff --git a/client/src/pages/Tasks.tsx b/client/src/pages/Tasks.tsx index 72a38e3..3ca3783 100644 --- a/client/src/pages/Tasks.tsx +++ b/client/src/pages/Tasks.tsx @@ -87,7 +87,13 @@ function TaskFormInline({ task, onClose, selectedStoreId, user }: any) { (taskData as any).createdBy = user?.username || 'admin'; } - console.log('📤 Sending request:', { url, method, taskData }); + console.log('📤 Tasks.tsx - Sending request:', { + url, + method, + taskData, + selectedStoreId, + finalGroupId: taskData.groupId + }); const response = await fetch(url, { method, diff --git a/client/src/pages/TasksSimplified.tsx b/client/src/pages/TasksSimplified.tsx index 9f08d1c..0f1728e 100644 --- a/client/src/pages/TasksSimplified.tsx +++ b/client/src/pages/TasksSimplified.tsx @@ -80,11 +80,20 @@ export default function TasksSimplified() { // Création d'une tâche const handleCreateTask = async (taskData: any) => { try { - await apiRequest('/api/tasks', 'POST', { + const finalData = { ...taskData, groupId: selectedStoreId ? parseInt(selectedStoreId) : stores[0]?.id + }; + + console.log('🔍 TasksSimplified - Creating task with data:', { + selectedStoreId, + storesLength: stores.length, + finalGroupId: finalData.groupId, + taskData: finalData }); + await apiRequest('/api/tasks', 'POST', finalData); + queryClient.invalidateQueries({ queryKey: ["/api/tasks"] }); setShowCreateModal(false); toast({ @@ -92,6 +101,7 @@ export default function TasksSimplified() { description: "Tâche créée avec succès", }); } catch (error) { + console.error('❌ TasksSimplified - Error creating task:', error); toast({ title: "Erreur", description: "Impossible de créer la tâche", diff --git a/server/routes.ts b/server/routes.ts index c7bf047..da5aade 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -1671,10 +1671,26 @@ export async function registerRoutes(app: Express): Promise { dueDateValue: data.dueDate }); + // Assign a default groupId if not provided + if (!data.groupId) { + if (user.role === 'admin') { + data.groupId = 1; // Default for admin + } else { + const userGroupIds = user.userGroups?.map(ug => ug.groupId) || []; + data.groupId = userGroupIds.length > 0 ? userGroupIds[0] : 1; + } + console.log('📝 POST /api/tasks - Assigned default groupId:', data.groupId); + } + // Check if user has access to the group if (user.role !== 'admin') { - const userGroupIds = user.userGroups.map(ug => ug.groupId); - if (!userGroupIds.includes(data.groupId)) { + const userGroupIds = user.userGroups?.map(ug => ug.groupId) || []; + console.log('📝 POST /api/tasks - User group access check:', { + userGroupIds, + requestedGroupId: data.groupId, + hasUserGroups: !!user.userGroups + }); + if (userGroupIds.length > 0 && !userGroupIds.includes(data.groupId)) { return res.status(403).json({ message: "Access denied to this group" }); } }