fix: correction de l'ouverture du dashbord [#39]

This commit is contained in:
Luc SORIGNET
2025-04-07 20:09:10 +02:00
parent 839a26257b
commit a157d53932
4 changed files with 27 additions and 6 deletions

View File

@ -127,7 +127,12 @@ export default function Layout({
onEstablishmentChange={(establishmentId) => {
const parsedEstablishmentId = parseInt(establishmentId, 10);
setSelectedEstablishmentId(parsedEstablishmentId);
const role = session.user.roles.find(role => role.establishment__id === parsedEstablishmentId)?.role_type;
let roleIndex = session.user.roles.findIndex(role => role.establishment__id === parsedEstablishmentId)
if (roleIndex === -1) {
roleIndex = 0;
}
setCurrentRoleIndex(roleIndex);
const role = session.user.roles[roleIndex].role_type;
setProfileRole(role);
}}
/>

View File

@ -10,6 +10,7 @@ import logger from '@/utils/logger';
import { fetchRegisterForms } from '@/app/actions/subscriptionAction';
import { fetchUpcomingEvents } from '@/app/actions/planningAction';
import { getSession } from 'next-auth/react';
import { getCurrentRoleIndex } from '@/store/Store';
// Composant EventCard pour afficher les événements
@ -46,7 +47,8 @@ export default function DashboardPage() {
getSession()
.then(session => {
if (session && session.user) {
setEstablishmentId(session.user.establishment);
const establishmentId = session.user.roles[getCurrentRoleIndex()].establishment__id;
setEstablishmentId(establishmentId);
}
})
.catch(err => {