mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
fix: correction de l'ouverture du dashbord [#39]
This commit is contained in:
@ -127,7 +127,12 @@ export default function Layout({
|
|||||||
onEstablishmentChange={(establishmentId) => {
|
onEstablishmentChange={(establishmentId) => {
|
||||||
const parsedEstablishmentId = parseInt(establishmentId, 10);
|
const parsedEstablishmentId = parseInt(establishmentId, 10);
|
||||||
setSelectedEstablishmentId(parsedEstablishmentId);
|
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);
|
setProfileRole(role);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import logger from '@/utils/logger';
|
|||||||
import { fetchRegisterForms } from '@/app/actions/subscriptionAction';
|
import { fetchRegisterForms } from '@/app/actions/subscriptionAction';
|
||||||
import { fetchUpcomingEvents } from '@/app/actions/planningAction';
|
import { fetchUpcomingEvents } from '@/app/actions/planningAction';
|
||||||
import { getSession } from 'next-auth/react';
|
import { getSession } from 'next-auth/react';
|
||||||
|
import { getCurrentRoleIndex } from '@/store/Store';
|
||||||
|
|
||||||
|
|
||||||
// Composant EventCard pour afficher les événements
|
// Composant EventCard pour afficher les événements
|
||||||
@ -46,7 +47,8 @@ export default function DashboardPage() {
|
|||||||
getSession()
|
getSession()
|
||||||
.then(session => {
|
.then(session => {
|
||||||
if (session && session.user) {
|
if (session && session.user) {
|
||||||
setEstablishmentId(session.user.establishment);
|
const establishmentId = session.user.roles[getCurrentRoleIndex()].establishment__id;
|
||||||
|
setEstablishmentId(establishmentId);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
|||||||
@ -16,10 +16,10 @@ import { login } from '@/app/actions/authAction';
|
|||||||
import { getSession } from 'next-auth/react';
|
import { getSession } from 'next-auth/react';
|
||||||
import { useCsrfToken } from '@/context/CsrfContext'; // Importez le hook useCsrfToken
|
import { useCsrfToken } from '@/context/CsrfContext'; // Importez le hook useCsrfToken
|
||||||
import logger from '@/utils/logger';
|
import logger from '@/utils/logger';
|
||||||
import { useSession } from 'next-auth/react';
|
|
||||||
import ProfileSelector from '@/components/ProfileSelector'; // Importez le composant ProfileSelector
|
import ProfileSelector from '@/components/ProfileSelector'; // Importez le composant ProfileSelector
|
||||||
|
import { RIGHTS } from '@/utils/rights';
|
||||||
|
import { setCurrentRoleIndex } from '@/store/Store';
|
||||||
|
|
||||||
const useFakeData = process.env.NEXT_PUBLIC_USE_FAKE_DATA === 'true';
|
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
@ -63,9 +63,12 @@ export default function Page() {
|
|||||||
if (roles.length > 0) {
|
if (roles.length > 0) {
|
||||||
// Redirection en fonction du rôle
|
// Redirection en fonction du rôle
|
||||||
// Ne pas désactiver le loader avant la redirection
|
// Ne pas désactiver le loader avant la redirection
|
||||||
if (roles[0].role_type === 1) {
|
const currentRoleIndex = 0;
|
||||||
|
setCurrentRoleIndex(currentRoleIndex);
|
||||||
|
const role = roles[currentRoleIndex].role_type;
|
||||||
|
if (role === RIGHTS.ADMIN || role === RIGHTS.TEACHER) {
|
||||||
router.push(FE_ADMIN_SUBSCRIPTIONS_URL);
|
router.push(FE_ADMIN_SUBSCRIPTIONS_URL);
|
||||||
} else if (roles[0].role_type === 2) {
|
} else if (role === RIGHTS.PARENT) {
|
||||||
router.push(FE_PARENTS_HOME_URL);
|
router.push(FE_PARENTS_HOME_URL);
|
||||||
} else {
|
} else {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|||||||
11
Front-End/src/store/Store.js
Normal file
11
Front-End/src/store/Store.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
// Current Role Index
|
||||||
|
// Cette fonction permet de stocker et l'index du rôle actuel dans le localStorage
|
||||||
|
export function setCurrentRoleIndex(currentRoleIndex){
|
||||||
|
localStorage.setItem('currentRoleIndex', currentRoleIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getCurrentRoleIndex(){
|
||||||
|
const currentRoleIndex = localStorage.getItem('currentRoleIndex');
|
||||||
|
return currentRoleIndex? currentRoleIndex : 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user