feat: Ajout de l'emploi du temps sur la page parent

This commit is contained in:
N3WT DE COMPET
2025-05-31 02:00:00 +02:00
parent c117f96e52
commit 78d96f82f9
7 changed files with 187 additions and 79 deletions

View File

@ -2,7 +2,7 @@
import React, { useEffect, useState } from 'react';
import { useRouter } from 'next/navigation';
import Table from '@/components/Table';
import { Edit3, Users, Download, Eye, Upload } from 'lucide-react';
import { Edit3, Users, Download, Eye, Upload, CalendarDays } from 'lucide-react';
import StatusLabel from '@/components/StatusLabel';
import FileUpload from '@/components/FileUpload';
import { FE_PARENTS_EDIT_SUBSCRIPTION_URL } from '@/utils/Url';
@ -15,6 +15,12 @@ import { BASE_URL } from '@/utils/Url';
import { useEstablishment } from '@/context/EstablishmentContext';
import { useCsrfToken } from '@/context/CsrfContext';
import { useClasses } from '@/context/ClassesContext';
import {
PlanningProvider,
PlanningModes
} from '@/context/PlanningContext';
import SectionHeader from '@/components/SectionHeader';
import ParentPlanningSection from '@/components/ParentPlanningSection';
export default function ParentHomePage() {
const [children, setChildren] = useState([]);
@ -22,6 +28,8 @@ export default function ParentHomePage() {
const [uploadingStudentId, setUploadingStudentId] = useState(null); // ID de l'étudiant pour l'upload
const [uploadedFile, setUploadedFile] = useState(null); // Fichier uploadé
const [uploadState, setUploadState] = useState('off'); // État "on" ou "off" pour l'affichage du composant
const [showPlanning, setShowPlanning] = useState(false);
const [planningClassName, setPlanningClassName] = useState(null);
const router = useRouter();
const csrfToken = useCsrfToken();
const [reloadFetch, setReloadFetch] = useState(false);
@ -97,6 +105,11 @@ export default function ParentHomePage() {
}
};
const showClassPlanning = (student) => {
setPlanningClassName(`${student.associated_class_name} - ${getNiveauLabel(student.level)}`);
setShowPlanning(true);
};
const childrenColumns = [
{
name: 'photo',
@ -127,6 +140,12 @@ export default function ParentHomePage() {
},
{ name: 'Nom', transform: (row) => `${row.student.last_name}` },
{ name: 'Prénom', transform: (row) => `${row.student.first_name}` },
{
name: 'Classe',
transform: (row) => (
<div className="text-center">{(row.student.associated_class_name)}</div>
),
},
{
name: 'Niveau',
transform: (row) => (
@ -192,7 +211,6 @@ export default function ParentHomePage() {
>
<Download className="h-5 w-5" />
</a>
{/* Nouvelle action Upload */}
<button
className={`flex items-center justify-center w-8 h-8 rounded-full ${
uploadingStudentId === row.student.id && uploadState === 'on'
@ -201,7 +219,7 @@ export default function ParentHomePage() {
}`}
onClick={(e) => {
e.stopPropagation();
toggleUpload(row.student.id); // Activer ou désactiver l'upload pour cet étudiant
toggleUpload(row.student.id);
}}
aria-label="Uploader un fichier"
>
@ -211,16 +229,28 @@ export default function ParentHomePage() {
)}
{row.status === 5 && (
<button
className="text-purple-500 hover:text-purple-700"
onClick={(e) => {
e.stopPropagation();
handleView(row.student.id);
}}
aria-label="Visualiser le dossier"
>
<Eye className="h-5 w-5" />
</button>
<>
<button
className="text-purple-500 hover:text-purple-700"
onClick={(e) => {
e.stopPropagation();
handleView(row.student.id);
}}
aria-label="Visualiser le dossier"
>
<Eye className="h-5 w-5" />
</button>
<button
className="text-emerald-500 hover:text-emerald-700 ml-1"
onClick={(e) => {
e.stopPropagation();
showClassPlanning(row.student);
}}
aria-label="Voir le planning de la classe"
>
<CalendarDays className="h-5 w-5" />
</button>
</>
)}
</div>
),
@ -228,40 +258,66 @@ export default function ParentHomePage() {
];
return (
<div className="px-2 py-4 md:px-4 max-w-full">
<div>
<h2 className="text-xl font-semibold mb-3 px-1 flex items-center gap-2">
<Users className="h-6 w-6 text-emerald-600" />
Enfants
</h2>
<div className="overflow-x-auto">
<Table
data={children}
columns={childrenColumns}
defaultTheme="bg-gray-50"
/>
</div>
{/* Composant FileUpload et bouton Valider en dessous du tableau */}
{uploadState === 'on' && uploadingStudentId && (
<div className="mt-4">
<FileUpload
selectionMessage="Sélectionnez un fichier à uploader"
onFileSelect={handleFileUpload}
/>
<div className="w-full h-full">
{showPlanning && planningClassName ? (
// Affichage grand format mais respectant la sidebar
<>
<div className="p-4 flex items-center border-b">
<button
className={`mt-4 px-6 py-2 rounded-md ${
uploadedFile
? 'bg-emerald-500 text-white hover:bg-emerald-600'
: 'bg-gray-300 text-gray-700 cursor-not-allowed'
}`}
onClick={handleSubmit}
disabled={!uploadedFile}
className="text-emerald-600 hover:text-emerald-800 font-semibold flex items-center"
onClick={() => setShowPlanning(false)}
>
Valider
Retour
</button>
</div>
)}
</div>
<div className="flex-1 flex overflow-hidden">
<PlanningProvider
establishmentId={selectedEstablishmentId}
modeSet={PlanningModes.CLASS_SCHEDULE}
readOnly={true}
>
<ParentPlanningSection
planningClassName={planningClassName}
/>
</PlanningProvider>
</div>
</>
) : (
// Affichage classique avec le tableau des enfants
<div>
<SectionHeader
icon={Users}
title="Vos enfants"
description="Suivez le parcours de vos enfants"
/>
<div className="overflow-x-auto">
<Table
data={children}
columns={childrenColumns}
/>
</div>
{/* Composant FileUpload et bouton Valider en dessous du tableau */}
{uploadState === 'on' && uploadingStudentId && (
<div className="mt-4">
<FileUpload
selectionMessage="Sélectionnez un fichier à uploader"
onFileSelect={handleFileUpload}
/>
<button
className={`mt-4 px-6 py-2 rounded-md ${
uploadedFile
? 'bg-emerald-500 text-white hover:bg-emerald-600'
: 'bg-gray-300 text-gray-700 cursor-not-allowed'
}`}
onClick={handleSubmit}
disabled={!uploadedFile}
>
Valider
</button>
</div>
)}
</div>
)}
</div>
);
}