chore: Capacité de l'établissement retourné en variable de session /

login sur la home page
This commit is contained in:
N3WT DE COMPET
2025-05-22 18:47:19 +02:00
parent 3b667d3b15
commit 87b8cf6c05
6 changed files with 54 additions and 32 deletions

View File

@ -223,7 +223,7 @@ def makeToken(user):
""" """
try: try:
# Récupérer tous les rôles de l'utilisateur actifs # Récupérer tous les rôles de l'utilisateur actifs
roles = ProfileRole.objects.filter(profile=user, is_active=True).values('role_type', 'establishment__id', 'establishment__name', 'establishment__evaluation_frequency') roles = ProfileRole.objects.filter(profile=user, is_active=True).values('role_type', 'establishment__id', 'establishment__name', 'establishment__evaluation_frequency', 'establishment__total_capacity')
# Générer le JWT avec la bonne syntaxe datetime # Générer le JWT avec la bonne syntaxe datetime
access_payload = { access_payload = {

View File

@ -23,7 +23,7 @@ import {
} from '@/app/actions/subscriptionAction'; } from '@/app/actions/subscriptionAction';
import { useEstablishment } from '@/context/EstablishmentContext'; import { useEstablishment } from '@/context/EstablishmentContext';
import { useClasses } from '@/context/ClassesContext'; import { useClasses } from '@/context/ClassesContext';
import { Award, BookOpen, FileText } from 'lucide-react'; import { Award, FileText } from 'lucide-react';
import SectionHeader from '@/components/SectionHeader'; import SectionHeader from '@/components/SectionHeader';
import GradesDomainBarChart from '@/components/Grades/GradesDomainBarChart'; import GradesDomainBarChart from '@/components/Grades/GradesDomainBarChart';
import InputText from '@/components/InputText'; import InputText from '@/components/InputText';
@ -210,7 +210,7 @@ export default function Page() {
return ( return (
<div className="p-8 space-y-8"> <div className="p-8 space-y-8">
<SectionHeader <SectionHeader
icon={BookOpen} icon={Award}
title="Suivi pédagogique" title="Suivi pédagogique"
description="Suivez le parcours d'un élève" description="Suivez le parcours d'un élève"
/> />
@ -219,7 +219,7 @@ export default function Page() {
<div className="flex flex-row gap-8 items-start"> <div className="flex flex-row gap-8 items-start">
{/* Colonne gauche : InputText + bouton */} {/* Colonne gauche : InputText + bouton */}
<div className="w-4/5 flex items-end gap-4"> <div className="w-4/5 flex items-end gap-4">
<div className="flex-1"> <div className="flex-[3_3_0%]">
<InputText <InputText
name="studentSearch" name="studentSearch"
type="text" type="text"
@ -231,8 +231,7 @@ export default function Page() {
enable={true} enable={true}
/> />
</div> </div>
{/* Sélecteur de période */} <div className="flex-[1_1_0%]">
{formData.selectedStudent && (
<SelectChoice <SelectChoice
name="period" name="period"
label="Période" label="Période"
@ -250,9 +249,10 @@ export default function Page() {
})} })}
selected={selectedPeriod || ''} selected={selectedPeriod || ''}
callback={(e) => setSelectedPeriod(Number(e.target.value))} callback={(e) => setSelectedPeriod(Number(e.target.value))}
disabled={false} disabled={!formData.selectedStudent}
/> />
)} </div>
<div className="flex-[1_1_0%] flex items-end">
<Button <Button
primary primary
onClick={() => { onClick={() => {
@ -263,15 +263,16 @@ export default function Page() {
const url = `${FE_ADMIN_GRADES_STUDENT_COMPETENCIES_URL}?studentId=${formData.selectedStudent}&period=${periodString}`; const url = `${FE_ADMIN_GRADES_STUDENT_COMPETENCIES_URL}?studentId=${formData.selectedStudent}&period=${periodString}`;
router.push(url); router.push(url);
}} }}
className="mb-1 px-4 py-2 rounded-md shadow bg-emerald-500 text-white hover:bg-emerald-600" className="mb-1 px-4 py-2 rounded-md shadow bg-emerald-500 text-white hover:bg-emerald-600 w-full"
icon={<Award className="w-6 h-6" />} icon={<Award className="w-6 h-6" />}
text="Evaluer" text="Evaluer"
title="Evaluez l'élève" title="Evaluez l'élève"
disabled={!formData.selectedStudent || !selectedPeriod} disabled={!formData.selectedStudent || !selectedPeriod}
/> />
</div> </div>
</div>
{/* Colonne droite : Photo élève */} {/* Colonne droite : Photo élève */}
<div className="w-2/5 flex flex-col items-center justify-center"> <div className="w-1/5 flex flex-col items-center justify-center">
{formData.selectedStudent && {formData.selectedStudent &&
(() => { (() => {
const student = students.find( const student = students.find(

View File

@ -38,7 +38,8 @@ export default function DashboardPage() {
}); });
const [classes, setClasses] = useState([]); const [classes, setClasses] = useState([]);
const { selectedEstablishmentId } = useEstablishment(); const { selectedEstablishmentId, selectedEstablishmentTotalCapacity } =
useEstablishment();
const { showNotification } = useNotification(); const { showNotification } = useNotification();
useEffect(() => { useEffect(() => {
@ -116,13 +117,13 @@ export default function DashboardPage() {
/> />
<StatCard <StatCard
title={t('structureCapacity')} title={t('structureCapacity')}
value={`${structureCapacity}`} value={`${selectedEstablishmentTotalCapacity}`}
icon={<School className="text-green-500" size={24} />} icon={<School className="text-green-500" size={24} />}
color="emerald" color="emerald"
/> />
<StatCard <StatCard
title={t('capacityRate')} title={t('capacityRate')}
value={`${((totalStudents / structureCapacity) * 100).toFixed(1)}%`} value={`${((totalStudents / selectedEstablishmentTotalCapacity) * 100).toFixed(1)}%`}
icon={<School className="text-orange-500" size={24} />} icon={<School className="text-orange-500" size={24} />}
color="orange" color="orange"
/> />

View File

@ -62,8 +62,7 @@ export default function FlashNotification({
<p className="text-gray-700">{message}</p> <p className="text-gray-700">{message}</p>
{type === 'error' && errorCode && ( {type === 'error' && errorCode && (
<div className="mt-2 text-xs text-gray-500"> <div className="mt-2 text-xs text-gray-500">
Code :{' '} Code : <span className="font-mono font-bold">{errorCode}</span>
<span className="font-mono font-bold">{errorCode}</span>
</div> </div>
)} )}
</div> </div>

View File

@ -21,6 +21,15 @@ export const EstablishmentProvider = ({ children }) => {
); );
return storedEstablishmentEvaluationFrequency; return storedEstablishmentEvaluationFrequency;
}); });
const [
selectedEstablishmentTotalCapacity,
setSelectedEstablishmentTotalCapacityState,
] = useState(() => {
const storedEstablishmentTotalCapacity = +sessionStorage.getItem(
'setSelectedEstablishmentTotalCapacity'
);
return storedEstablishmentTotalCapacity;
});
const [selectedRoleId, setSelectedRoleIdState] = useState(() => { const [selectedRoleId, setSelectedRoleIdState] = useState(() => {
const storedRoleId = +sessionStorage.getItem('selectedRoleId'); const storedRoleId = +sessionStorage.getItem('selectedRoleId');
return storedRoleId; return storedRoleId;
@ -51,6 +60,12 @@ export const EstablishmentProvider = ({ children }) => {
sessionStorage.setItem('selectedEstablishmentEvaluationFrequency', id); sessionStorage.setItem('selectedEstablishmentEvaluationFrequency', id);
}; };
const setSelectedEstablishmentTotalCapacity = (id) => {
setSelectedEstablishmentTotalCapacityState(id);
logger.debug('setSelectedEstablishmentTotalCapacity', id);
sessionStorage.setItem('selectedEstablishmentTotalCapacity', id);
};
const setSelectedRoleId = (id) => { const setSelectedRoleId = (id) => {
setSelectedRoleIdState(id); setSelectedRoleIdState(id);
sessionStorage.setItem('selectedRoleId', id); sessionStorage.setItem('selectedRoleId', id);
@ -88,6 +103,7 @@ export const EstablishmentProvider = ({ children }) => {
id: role.establishment__id, id: role.establishment__id,
name: role.establishment__name, name: role.establishment__name,
evaluation_frequency: role.establishment__evaluation_frequency, evaluation_frequency: role.establishment__evaluation_frequency,
total_capacity: role.establishment__total_capacity,
role_id: i, role_id: i,
role_type: role.role_type, role_type: role.role_type,
})); }));
@ -104,6 +120,9 @@ export const EstablishmentProvider = ({ children }) => {
setSelectedEstablishmentEvaluationFrequency( setSelectedEstablishmentEvaluationFrequency(
userEstablishments[roleIndexDefault].evaluation_frequency userEstablishments[roleIndexDefault].evaluation_frequency
); );
setSelectedEstablishmentTotalCapacity(
userEstablishments[roleIndexDefault].total_capacity
);
setProfileRole(userEstablishments[roleIndexDefault].role_type); setProfileRole(userEstablishments[roleIndexDefault].role_type);
} }
if (endInitFunctionHandler) { if (endInitFunctionHandler) {
@ -133,6 +152,8 @@ export const EstablishmentProvider = ({ children }) => {
setSelectedEstablishmentId, setSelectedEstablishmentId,
selectedEstablishmentEvaluationFrequency, selectedEstablishmentEvaluationFrequency,
setSelectedEstablishmentEvaluationFrequency, setSelectedEstablishmentEvaluationFrequency,
selectedEstablishmentTotalCapacity,
setSelectedEstablishmentTotalCapacity,
selectedRoleId, selectedRoleId,
setSelectedRoleId, setSelectedRoleId,
profileRole, profileRole,

View File

@ -132,9 +132,9 @@ export const FE_API_DOCUSEAL_DOWNLOAD_URL = '/api/docuseal/downloadTemplate';
export function getRedirectUrlFromRole(role) { export function getRedirectUrlFromRole(role) {
switch (role) { switch (role) {
case RIGHTS.ADMIN: case RIGHTS.ADMIN:
return FE_ADMIN_SUBSCRIPTIONS_URL; return FE_ADMIN_HOME_URL;
case RIGHTS.TEACHER: case RIGHTS.TEACHER:
return FE_ADMIN_SUBSCRIPTIONS_URL; return FE_ADMIN_HOME_URL;
case RIGHTS.PARENT: case RIGHTS.PARENT:
return FE_PARENTS_HOME_URL; return FE_PARENTS_HOME_URL;
default: default: