From 6631ece2abb8481046d40b0df39bc3908d707e4f Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 8 Sep 2025 20:59:38 +0000 Subject: [PATCH] Set default group based on user role for task creation Adjusted the default `groupId` in the Avoirs form. If the user is an 'admin', it defaults to `1`. Otherwise, it defaults to the first `groupId` associated with the user's `userGroups`, or `0` if none are assigned. This change is implemented in `client/src/pages/Avoirs.tsx`. 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/7eY9Hl8 --- client/src/pages/Avoirs.tsx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/client/src/pages/Avoirs.tsx b/client/src/pages/Avoirs.tsx index 5e86732..bf3a3a4 100644 --- a/client/src/pages/Avoirs.tsx +++ b/client/src/pages/Avoirs.tsx @@ -356,12 +356,24 @@ export default function Avoirs() { } }); + // Calculate default group ID based on user role + const getDefaultGroupId = () => { + if ((user as any)?.role === 'admin') { + // Admin : groupe 1 par défaut + return 1; + } else { + // Utilisateurs : leur groupe assigné par défaut + const userGroupIds = (user as any)?.userGroups?.map((ug: any) => ug.groupId) || []; + return userGroupIds.length > 0 ? userGroupIds[0] : 0; + } + }; + // Initialize create form const form = useForm({ resolver: zodResolver(avoirSchema), defaultValues: { supplierId: 0, - groupId: 0, + groupId: getDefaultGroupId(), invoiceReference: "", amount: undefined, comment: "",