mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 14:08:15 +02:00
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
This commit is contained in:
1 parent
ee5c122664
commit
6631ece2ab
1 file changed
+13
-1
@@ -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
|
// Initialize create form
|
||||||
const form = useForm<AvoirFormData>({
|
const form = useForm<AvoirFormData>({
|
||||||
resolver: zodResolver(avoirSchema),
|
resolver: zodResolver(avoirSchema),
|
||||||
defaultValues: {
|
defaultValues: {
|
||||||
supplierId: 0,
|
supplierId: 0,
|
||||||
groupId: 0,
|
groupId: getDefaultGroupId(),
|
||||||
invoiceReference: "",
|
invoiceReference: "",
|
||||||
amount: undefined,
|
amount: undefined,
|
||||||
comment: "",
|
comment: "",
|
||||||
|
|||||||
Reference in new issue
Block a user