diff --git a/Front-End/src/app/[locale]/admin/subscriptions/page.js b/Front-End/src/app/[locale]/admin/subscriptions/page.js
index bb3e29c..37f45f5 100644
--- a/Front-End/src/app/[locale]/admin/subscriptions/page.js
+++ b/Front-End/src/app/[locale]/admin/subscriptions/page.js
@@ -58,7 +58,6 @@ import {
import { fetchProfiles } from '@/app/actions/authAction';
import {
- BASE_URL,
FE_ADMIN_SUBSCRIPTIONS_EDIT_URL,
FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL,
} from '@/utils/Url';
@@ -68,6 +67,7 @@ import { useCsrfToken } from '@/context/CsrfContext';
import logger from '@/utils/logger';
import { PhoneLabel } from '@/components/PhoneLabel';
import FileUpload from '@/components/FileUpload';
+import FilesModal from '@/components/Inscription/FilesModal';
export default function Page({ params: { locale } }) {
const t = useTranslations('subscriptions');
@@ -108,7 +108,7 @@ export default function Page({ params: { locale } }) {
const [isOpenAddGuardian, setIsOpenAddGuardian] = useState(false);
const [isFilesModalOpen, setIsFilesModalOpen] = useState(false);
- const [selectedRowFiles, setSelectedRowFiles] = useState([]);
+ const [selectedRegisterForm, setSelectedRegisterForm] = useState([]);
const [popupVisible, setPopupVisible] = useState(false);
const [popupMessage, setPopupMessage] = useState('');
@@ -156,28 +156,10 @@ export default function Page({ params: { locale } }) {
};
const openFilesModal = (row) => {
- const files = [];
- if (row.registration_file) {
- files.push({
- name: "Fichier d'inscription",
- url: `${BASE_URL}${row.registration_file}`,
- });
- }
- if (row.sepa_file) {
- files.push({
- name: 'Mandat SEPA',
- url: `${BASE_URL}${row.sepa_file}`,
- });
- }
- setSelectedRowFiles(files);
+ setSelectedRegisterForm(row || []);
setIsFilesModalOpen(true);
};
- const closeFilesModal = () => {
- setIsFilesModalOpen(false);
- setSelectedRowFiles([]);
- };
-
const requestErrorHandler = (err) => {
logger.error('Error fetching data:', err);
};
@@ -971,20 +953,6 @@ export default function Page({ params: { locale } }) {
),
},
- {
- name: t('files'),
- transform: (row) =>
- row.registration_file != null && (
-
- ),
- },
{
name: 'Actions',
transform: (row) => (
@@ -1216,27 +1184,10 @@ export default function Page({ params: { locale } }) {
/>
)}
{isFilesModalOpen && (
- (
-
- )}
+ selectedRegisterForm={selectedRegisterForm}
/>
)}
diff --git a/Front-End/src/components/Inscription/FilesModal.js b/Front-End/src/components/Inscription/FilesModal.js
new file mode 100644
index 0000000..c50f641
--- /dev/null
+++ b/Front-End/src/components/Inscription/FilesModal.js
@@ -0,0 +1,187 @@
+import React, { useState, useEffect } from 'react';
+import Modal from '@/components/Modal';
+import { FileText } from 'lucide-react';
+import {
+ fetchSchoolFileTemplatesFromRegistrationFiles,
+ fetchParentFileTemplatesFromRegistrationFiles,
+} from '@/app/actions/subscriptionAction';
+import { BASE_URL } from '@/utils/Url';
+
+const FilesModal = ({
+ isOpen,
+ setIsOpen,
+ title = 'Fichiers disponibles',
+ selectedRegisterForm,
+}) => {
+ const [files, setFiles] = useState({
+ schoolFiles: [],
+ parentFiles: [],
+ sepaFile: null,
+ });
+
+ useEffect(() => {
+ if (!selectedRegisterForm?.student?.id) {
+ console.error(
+ 'selectedRegisterForm.student.id est invalide ou manquant.'
+ );
+ return;
+ }
+
+ let fetchedSchoolFiles = []; // Déclaré dans un scope plus large
+
+ // Fetch school and parent files sequentially
+ fetchSchoolFileTemplatesFromRegistrationFiles(
+ selectedRegisterForm.student.id
+ )
+ .then((schoolFiles) => {
+ if (!Array.isArray(schoolFiles)) {
+ console.error(
+ 'Les fichiers scolaires ne sont pas un tableau :',
+ schoolFiles
+ );
+ return;
+ }
+
+ fetchedSchoolFiles = schoolFiles; // Assigner les fichiers scolaires
+
+ // Fetch parent files after school files
+ return fetchParentFileTemplatesFromRegistrationFiles(
+ selectedRegisterForm.student.id
+ );
+ })
+ .then((parentFiles) => {
+ // Construct the categorized files list
+ const categorizedFiles = {
+ schoolFiles: fetchedSchoolFiles.map((file) => ({
+ name: file.name || 'Document scolaire',
+ url: file.file ? `${BASE_URL}${file.file}` : null,
+ })),
+ parentFiles: parentFiles.map((file) => ({
+ name: file.master_name || 'Document parent',
+ url: file.file ? `${BASE_URL}${file.file}` : null,
+ })),
+ sepaFile: selectedRegisterForm.sepa_file
+ ? {
+ name: 'Mandat SEPA',
+ url: `${BASE_URL}${selectedRegisterForm.sepa_file}`,
+ }
+ : null,
+ };
+ setFiles(categorizedFiles);
+ })
+ .catch((error) => {
+ console.error('Erreur lors de la récupération des fichiers :', error);
+ });
+ }, [selectedRegisterForm]);
+
+ return (
+
+ {title}
+
+ }
+ ContentComponent={() => (
+
+ {/* Section Fichiers École */}
+
+
+ Formulaires de l'établissement
+
+
+
+
+
+
+ {/* Section Fichiers Parent */}
+
+
+ Pièces fournies
+
+
+
+
+
+
+ {/* Section Mandat SEPA */}
+
+
+ Mandat SEPA
+
+ {files.sepaFile ? (
+
+ ) : (
+
Aucun mandat SEPA disponible.
+ )}
+
+
+ )}
+ />
+ );
+};
+
+export default FilesModal;