fix: Réintégration du bouton de Bilan de compétence + harmonisation des paths d'upload de fichier

This commit is contained in:
N3WT DE COMPET
2026-04-05 09:24:30 +02:00
parent 409cf05f1a
commit 2a223fe3dd
6 changed files with 223 additions and 52 deletions

View File

@ -10,7 +10,8 @@ import {
Pencil,
Trash2,
Save,
Download
Download,
FileText,
} from 'lucide-react';
import SectionHeader from '@/components/SectionHeader';
import Table from '@/components/Table';
@ -435,6 +436,37 @@ export default function Page() {
);
};
const getBilanForStudent = (student) => {
const bilans = Array.isArray(student?.bilans) ? student.bilans : [];
if (!bilans.length) return null;
const currentPeriodStr = currentPeriodValue
? getPeriodString(
currentPeriodValue,
selectedEstablishmentEvaluationFrequency,
selectedSchoolYear
)
: null;
if (currentPeriodStr) {
const exact = bilans.find(
(bilan) => bilan?.period === currentPeriodStr && bilan?.file
);
if (exact) return exact;
}
const schoolYearSuffix = `_${selectedSchoolYear}`;
const sameYearBilans = bilans.filter(
(bilan) => bilan?.file && bilan?.period?.endsWith(schoolYearSuffix)
);
if (!sameYearBilans.length) return null;
return [...sameYearBilans].sort(
(a, b) => new Date(b.created_at || 0) - new Date(a.created_at || 0)
)[0];
};
const columns = [
{ name: 'Photo', transform: () => null },
{ name: 'Élève', transform: () => null },
@ -510,8 +542,23 @@ export default function Page() {
<span className="text-gray-400 text-xs">0</span>
);
case 'Actions':
const bilan = getBilanForStudent(student);
return (
<div className="flex items-center justify-center gap-2">
{bilan?.file && (
<a
href={getSecureFileUrl(bilan.file)}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
className="flex items-center gap-1 px-2 py-1 rounded text-xs font-medium bg-cyan-100 text-cyan-700 hover:bg-cyan-200 transition whitespace-nowrap"
title={`Télécharger le bilan de compétences (${bilan.period})`}
>
<FileText size={14} />
Bilan
</a>
)}
<button
onClick={(e) => {
e.stopPropagation();

View File

@ -70,7 +70,7 @@ export default function StudentCompetenciesPage() {
'success',
'Succès'
);
router.push(`/admin/grades/${studentId}`);
router.push('/admin/grades');
})
.catch((error) => {
showNotification(