mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +00:00
feat: Gestion de la validation du dossier d'inscription
This commit is contained in:
@ -200,6 +200,11 @@ class RegistrationForm(models.Model):
|
|||||||
null=True,
|
null=True,
|
||||||
blank=True
|
blank=True
|
||||||
)
|
)
|
||||||
|
fusion_file = models.FileField(
|
||||||
|
upload_to=registration_file_path,
|
||||||
|
null=True,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
associated_rf = models.CharField(max_length=200, default="", blank=True)
|
associated_rf = models.CharField(max_length=200, default="", blank=True)
|
||||||
|
|
||||||
# Many-to-Many Relationship
|
# Many-to-Many Relationship
|
||||||
|
|||||||
@ -274,33 +274,11 @@ class RegisterFormWithIdView(APIView):
|
|||||||
updateStateMachine(registerForm, 'EVENT_SIGNATURE')
|
updateStateMachine(registerForm, 'EVENT_SIGNATURE')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return JsonResponse({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
return JsonResponse({'error': str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||||
|
|
||||||
elif _status == RegistrationForm.RegistrationFormStatus.RF_VALIDATED:
|
|
||||||
updateStateMachine(registerForm, 'EVENT_VALIDATE')
|
|
||||||
elif _status == RegistrationForm.RegistrationFormStatus.RF_SENT:
|
elif _status == RegistrationForm.RegistrationFormStatus.RF_SENT:
|
||||||
if registerForm.status == RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW:
|
if registerForm.status == RegistrationForm.RegistrationFormStatus.RF_UNDER_REVIEW:
|
||||||
updateStateMachine(registerForm, 'EVENT_REFUSE')
|
updateStateMachine(registerForm, 'EVENT_REFUSE')
|
||||||
util.delete_registration_files(registerForm)
|
util.delete_registration_files(registerForm)
|
||||||
elif _status == RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT:
|
elif _status == RegistrationForm.RegistrationFormStatus.RF_SEPA_SENT:
|
||||||
# Vérifier si le paramètre fusion est activé via l'URL
|
|
||||||
fusion = studentForm_data.get('fusion', False)
|
|
||||||
if fusion:
|
|
||||||
# Fusion des documents
|
|
||||||
# Récupération des fichiers d'inscription
|
|
||||||
fileNames = RegistrationSchoolFileTemplate.get_files_from_rf(registerForm.pk)
|
|
||||||
if registerForm.registration_file:
|
|
||||||
fileNames.insert(0, registerForm.registration_file.path)
|
|
||||||
|
|
||||||
# Création du fichier PDF Fusionné
|
|
||||||
merged_pdf_content = util.merge_files_pdf(fileNames)
|
|
||||||
|
|
||||||
# Mise à jour du champ registration_file avec le fichier fusionné
|
|
||||||
registerForm.registration_file.save(
|
|
||||||
f"dossier_complet.pdf",
|
|
||||||
File(merged_pdf_content),
|
|
||||||
save=True
|
|
||||||
)
|
|
||||||
|
|
||||||
# Sauvegarde du mandat SEPA
|
# Sauvegarde du mandat SEPA
|
||||||
student = registerForm.student
|
student = registerForm.student
|
||||||
guardian = student.getMainGuardian()
|
guardian = student.getMainGuardian()
|
||||||
@ -314,6 +292,42 @@ class RegisterFormWithIdView(APIView):
|
|||||||
# Le parent a rempli le dossier d'inscription en sélectionnant "Prélèvement par Mandat SEPA"
|
# Le parent a rempli le dossier d'inscription en sélectionnant "Prélèvement par Mandat SEPA"
|
||||||
# L'école doit désormais envoyer le mandat SEPA pour poursuivre l'inscription
|
# L'école doit désormais envoyer le mandat SEPA pour poursuivre l'inscription
|
||||||
updateStateMachine(registerForm, 'EVENT_WAITING_FOR_SEPA')
|
updateStateMachine(registerForm, 'EVENT_WAITING_FOR_SEPA')
|
||||||
|
|
||||||
|
elif _status == RegistrationForm.RegistrationFormStatus.RF_VALIDATED:
|
||||||
|
# Vérifier si le paramètre fusion est activé via l'URL
|
||||||
|
fusion = studentForm_data.get('fusion', False)
|
||||||
|
if fusion:
|
||||||
|
# Fusion des documents
|
||||||
|
# Récupération des fichiers schoolFileTemplates
|
||||||
|
school_file_paths = RegistrationSchoolFileTemplate.get_files_from_rf(registerForm.pk)
|
||||||
|
|
||||||
|
# Récupération des fichiers parentFileTemplates
|
||||||
|
parent_file_templates = RegistrationParentFileTemplate.get_files_from_rf(registerForm.pk)
|
||||||
|
|
||||||
|
# Initialisation de la liste des fichiers à fusionner
|
||||||
|
fileNames = []
|
||||||
|
|
||||||
|
# Ajout du fichier registration_file en première position
|
||||||
|
if registerForm.registration_file:
|
||||||
|
fileNames.append(registerForm.registration_file.path)
|
||||||
|
|
||||||
|
# Ajout des fichiers schoolFileTemplates
|
||||||
|
fileNames.extend(school_file_paths)
|
||||||
|
|
||||||
|
# Ajout des fichiers parentFileTemplates
|
||||||
|
fileNames.extend(parent_file_templates)
|
||||||
|
|
||||||
|
# Création du fichier PDF fusionné
|
||||||
|
merged_pdf_content = util.merge_files_pdf(fileNames)
|
||||||
|
|
||||||
|
# Mise à jour du champ registration_file avec le fichier fusionné
|
||||||
|
registerForm.fusion_file.save(
|
||||||
|
f"dossier_complet.pdf",
|
||||||
|
File(merged_pdf_content),
|
||||||
|
save=True
|
||||||
|
)
|
||||||
|
|
||||||
|
updateStateMachine(registerForm, 'EVENT_VALIDATE')
|
||||||
|
|
||||||
# Retourner les données mises à jour
|
# Retourner les données mises à jour
|
||||||
return JsonResponse(studentForm_serializer.data, safe=False)
|
return JsonResponse(studentForm_serializer.data, safe=False)
|
||||||
|
|||||||
@ -35,7 +35,7 @@ import {
|
|||||||
archiveRegisterForm,
|
archiveRegisterForm,
|
||||||
fetchStudents,
|
fetchStudents,
|
||||||
editRegisterForm,
|
editRegisterForm,
|
||||||
sendSEPARegisterForm,
|
editRegisterFormWithBinaryFile,
|
||||||
} from '@/app/actions/subscriptionAction';
|
} from '@/app/actions/subscriptionAction';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -379,7 +379,7 @@ export default function Page({ params: { locale } }) {
|
|||||||
formData.append('sepa_file', file);
|
formData.append('sepa_file', file);
|
||||||
|
|
||||||
// Appeler l'API pour uploader le fichier SEPA
|
// Appeler l'API pour uploader le fichier SEPA
|
||||||
sendSEPARegisterForm(row.student.id, formData, csrfToken)
|
editRegisterFormWithBinaryFile(row.student.id, formData, csrfToken)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
logger.debug('Mandat SEPA uploadé avec succès :', response);
|
logger.debug('Mandat SEPA uploadé avec succès :', response);
|
||||||
setPopupMessage('Le mandat SEPA a été uploadé avec succès.');
|
setPopupMessage('Le mandat SEPA a été uploadé avec succès.');
|
||||||
@ -797,11 +797,7 @@ export default function Page({ params: { locale } }) {
|
|||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
const paymentSepa =
|
const url = `${FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL}?studentId=${row.student.id}&firstName=${row.student.first_name}&lastName=${row.student.last_name}&sepa_file=${row.sepa_file}&student_file=${row.registration_file}`;
|
||||||
row.registration_payment === 1 || row.tuition_payment === 1
|
|
||||||
? 1
|
|
||||||
: 0;
|
|
||||||
const url = `${FE_ADMIN_SUBSCRIPTIONS_VALIDATE_URL}?studentId=${row.student.id}&firstName=${row.student.first_name}&lastName=${row.student.last_name}&paymentSepa=${paymentSepa}&file=${row.registration_file}`;
|
|
||||||
router.push(`${url}`);
|
router.push(`${url}`);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -809,11 +805,11 @@ export default function Page({ params: { locale } }) {
|
|||||||
5: [
|
5: [
|
||||||
{
|
{
|
||||||
icon: (
|
icon: (
|
||||||
<span title="Valider le dossier">
|
<span title="Voir les fichiers">
|
||||||
<CheckCircle className="w-5 h-5 text-green-500 hover:text-green-700" />
|
<FileText className="w-5 h-5 text-cyan-500 hover:text-cyan-700" />
|
||||||
</span>
|
</span>
|
||||||
),
|
),
|
||||||
onClick: () => openModalAssociationEleve(row.student),
|
onClick: () => openFilesModal(row),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
7: [
|
7: [
|
||||||
@ -1087,7 +1083,10 @@ export default function Page({ params: { locale } }) {
|
|||||||
key={`${currentPage}-${searchTerm}`}
|
key={`${currentPage}-${searchTerm}`}
|
||||||
data={
|
data={
|
||||||
activeTab === 'pending'
|
activeTab === 'pending'
|
||||||
? registrationFormsDataPending
|
? [
|
||||||
|
...registrationFormsDataPending,
|
||||||
|
...registrationFormsDataSubscribed,
|
||||||
|
]
|
||||||
: activeTab === 'subscribed'
|
: activeTab === 'subscribed'
|
||||||
? registrationFormsDataSubscribed
|
? registrationFormsDataSubscribed
|
||||||
: registrationFormsDataArchived
|
: registrationFormsDataArchived
|
||||||
|
|||||||
@ -1,53 +1,59 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { useSearchParams, useRouter } from 'next/navigation';
|
import { useSearchParams, useRouter } from 'next/navigation';
|
||||||
import ValidateSubscription from '@/components/Inscription/ValidateSubscription';
|
import ValidateSubscription from '@/components/Inscription/ValidateSubscription';
|
||||||
import { sendSEPARegisterForm } from '@/app/actions/subscriptionAction';
|
import { editRegisterFormWithBinaryFile } from '@/app/actions/subscriptionAction';
|
||||||
import { useCsrfToken } from '@/context/CsrfContext';
|
import { useCsrfToken } from '@/context/CsrfContext';
|
||||||
import logger from '@/utils/logger';
|
import logger from '@/utils/logger';
|
||||||
|
import Loader from '@/components/Loader';
|
||||||
import { FE_ADMIN_SUBSCRIPTIONS_URL } from '@/utils/Url';
|
import { FE_ADMIN_SUBSCRIPTIONS_URL } from '@/utils/Url';
|
||||||
|
|
||||||
export default function Page() {
|
export default function Page() {
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
// Récupérer les paramètres de la requête
|
// Récupérer les paramètres de la requête
|
||||||
const studentId = searchParams.get('studentId');
|
const studentId = searchParams.get('studentId');
|
||||||
const firstName = searchParams.get('firstName');
|
const firstName = searchParams.get('firstName');
|
||||||
const lastName = searchParams.get('lastName');
|
const lastName = searchParams.get('lastName');
|
||||||
const paymentSepa = searchParams.get('paymentSepa') === '1';
|
const sepa_file = searchParams.get('sepa_file');
|
||||||
const file = searchParams.get('file');
|
const student_file = searchParams.get('student_file');
|
||||||
|
|
||||||
const csrfToken = useCsrfToken();
|
const csrfToken = useCsrfToken();
|
||||||
|
|
||||||
const handleAcceptRF = (data) => {
|
const handleAcceptRF = (data) => {
|
||||||
logger.debug('Mise à jour du RF avec les données:', data);
|
const { status, fusionParam } = data;
|
||||||
|
|
||||||
const { status, sepa_file, fusionParam } = data;
|
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('status', status); // Ajoute le statut
|
formData.append('status', status); // Ajoute le statut
|
||||||
formData.append('sepa_file', sepa_file); // Ajoute le fichier SEPA
|
|
||||||
formData.append('fusion', fusionParam);
|
formData.append('fusion', fusionParam);
|
||||||
|
|
||||||
|
setIsLoading(true);
|
||||||
// Appeler l'API pour mettre à jour le RF
|
// Appeler l'API pour mettre à jour le RF
|
||||||
sendSEPARegisterForm(studentId, formData, csrfToken)
|
editRegisterFormWithBinaryFile(studentId, formData, csrfToken)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
logger.debug('RF mis à jour avec succès:', response);
|
logger.debug('RF mis à jour avec succès:', response);
|
||||||
router.push(FE_ADMIN_SUBSCRIPTIONS_URL);
|
router.push(FE_ADMIN_SUBSCRIPTIONS_URL);
|
||||||
|
setIsLoading(false);
|
||||||
// Logique supplémentaire après la mise à jour (par exemple, redirection ou notification)
|
// Logique supplémentaire après la mise à jour (par exemple, redirection ou notification)
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
setIsLoading(false);
|
||||||
logger.error('Erreur lors de la mise à jour du RF:', error);
|
logger.error('Erreur lors de la mise à jour du RF:', error);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isLoading) {
|
||||||
|
return <Loader />;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ValidateSubscription
|
<ValidateSubscription
|
||||||
studentId={studentId}
|
studentId={studentId}
|
||||||
firstName={firstName}
|
firstName={firstName}
|
||||||
lastName={lastName}
|
lastName={lastName}
|
||||||
paymentSepa={paymentSepa}
|
sepa_file={sepa_file}
|
||||||
file={file}
|
student_file={student_file}
|
||||||
onAccept={handleAcceptRF}
|
onAccept={handleAcceptRF}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import FileUpload from '@/components/FileUpload';
|
|||||||
import { FE_PARENTS_EDIT_INSCRIPTION_URL } from '@/utils/Url';
|
import { FE_PARENTS_EDIT_INSCRIPTION_URL } from '@/utils/Url';
|
||||||
import {
|
import {
|
||||||
fetchChildren,
|
fetchChildren,
|
||||||
sendSEPARegisterForm,
|
editRegisterFormWithBinaryFile,
|
||||||
} from '@/app/actions/subscriptionAction';
|
} from '@/app/actions/subscriptionAction';
|
||||||
import logger from '@/utils/logger';
|
import logger from '@/utils/logger';
|
||||||
import { BASE_URL } from '@/utils/Url';
|
import { BASE_URL } from '@/utils/Url';
|
||||||
@ -68,7 +68,7 @@ export default function ParentHomePage() {
|
|||||||
formData.append('sepa_file', uploadedFile); // Ajoute le fichier SEPA
|
formData.append('sepa_file', uploadedFile); // Ajoute le fichier SEPA
|
||||||
formData.append('status', 3); // Statut à envoyer
|
formData.append('status', 3); // Statut à envoyer
|
||||||
|
|
||||||
sendSEPARegisterForm(uploadingStudentId, formData, csrfToken)
|
editRegisterFormWithBinaryFile(uploadingStudentId, formData, csrfToken)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
logger.debug('RF mis à jour avec succès:', response);
|
logger.debug('RF mis à jour avec succès:', response);
|
||||||
setReloadFetch(true);
|
setReloadFetch(true);
|
||||||
|
|||||||
@ -60,7 +60,7 @@ export const editRegisterForm = (id, data, csrfToken) => {
|
|||||||
}).then(requestResponseHandler);
|
}).then(requestResponseHandler);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sendSEPARegisterForm = (id, data, csrfToken) => {
|
export const editRegisterFormWithBinaryFile = (id, data, csrfToken) => {
|
||||||
return fetch(`${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${id}`, {
|
return fetch(`${BE_SUBSCRIPTION_REGISTERFORMS_URL}/${id}`, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@ -14,6 +14,8 @@ const FilesModal = ({
|
|||||||
selectedRegisterForm,
|
selectedRegisterForm,
|
||||||
}) => {
|
}) => {
|
||||||
const [files, setFiles] = useState({
|
const [files, setFiles] = useState({
|
||||||
|
registrationFile: null,
|
||||||
|
fusionFile: null,
|
||||||
schoolFiles: [],
|
schoolFiles: [],
|
||||||
parentFiles: [],
|
parentFiles: [],
|
||||||
sepaFile: null,
|
sepaFile: null,
|
||||||
@ -52,6 +54,18 @@ const FilesModal = ({
|
|||||||
.then((parentFiles) => {
|
.then((parentFiles) => {
|
||||||
// Construct the categorized files list
|
// Construct the categorized files list
|
||||||
const categorizedFiles = {
|
const categorizedFiles = {
|
||||||
|
registrationFile: selectedRegisterForm.registration_file
|
||||||
|
? {
|
||||||
|
name: 'Fiche élève',
|
||||||
|
url: `${BASE_URL}${selectedRegisterForm.registration_file}`,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
fusionFile: selectedRegisterForm.fusion_file
|
||||||
|
? {
|
||||||
|
name: 'Documents fusionnés',
|
||||||
|
url: `${BASE_URL}${selectedRegisterForm.fusion_file}`,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
schoolFiles: fetchedSchoolFiles.map((file) => ({
|
schoolFiles: fetchedSchoolFiles.map((file) => ({
|
||||||
name: file.name || 'Document scolaire',
|
name: file.name || 'Document scolaire',
|
||||||
url: file.file ? `${BASE_URL}${file.file}` : null,
|
url: file.file ? `${BASE_URL}${file.file}` : null,
|
||||||
@ -85,6 +99,48 @@ const FilesModal = ({
|
|||||||
}
|
}
|
||||||
ContentComponent={() => (
|
ContentComponent={() => (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
|
{/* Section Fiche élève */}
|
||||||
|
{files.registrationFile && (
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
||||||
|
Fiche élève
|
||||||
|
</h3>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<FileText className="w-5 h-5 text-gray-500" />
|
||||||
|
<a
|
||||||
|
href={files.registrationFile.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-blue-500 hover:text-blue-700 underline"
|
||||||
|
>
|
||||||
|
{files.registrationFile.name}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Section Documents fusionnés */}
|
||||||
|
{files.fusionFile && (
|
||||||
|
<div>
|
||||||
|
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
||||||
|
Documents fusionnés
|
||||||
|
</h3>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<FileText className="w-5 h-5 text-gray-500" />
|
||||||
|
<a
|
||||||
|
href={files.fusionFile.url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="text-blue-500 hover:text-blue-700 underline"
|
||||||
|
>
|
||||||
|
{files.fusionFile.name}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<hr className="border-t border-gray-300" />
|
||||||
|
|
||||||
{/* Section Fichiers École */}
|
{/* Section Fichiers École */}
|
||||||
<div>
|
<div>
|
||||||
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
||||||
|
|||||||
@ -1,50 +1,30 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import Button from '@/components/Button';
|
import ToggleSwitch from '@/components/ToggleSwitch';
|
||||||
import ToggleSwitch from '@/components/ToggleSwitch'; // Import du composant ToggleSwitch
|
|
||||||
import { BASE_URL } from '@/utils/Url';
|
import { BASE_URL } from '@/utils/Url';
|
||||||
import { generateToken } from '@/app/actions/registerFileGroupAction';
|
|
||||||
import {
|
import {
|
||||||
fetchSchoolFileTemplatesFromRegistrationFiles,
|
fetchSchoolFileTemplatesFromRegistrationFiles,
|
||||||
fetchParentFileTemplatesFromRegistrationFiles,
|
fetchParentFileTemplatesFromRegistrationFiles,
|
||||||
} from '@/app/actions/subscriptionAction';
|
} from '@/app/actions/subscriptionAction';
|
||||||
import logger from '@/utils/logger';
|
import logger from '@/utils/logger';
|
||||||
import { GraduationCap } from 'lucide-react';
|
import { School, CheckCircle } from 'lucide-react';
|
||||||
import FileUpload from '@/components/FileUpload';
|
|
||||||
import SectionHeader from '@/components/SectionHeader';
|
import SectionHeader from '@/components/SectionHeader';
|
||||||
|
|
||||||
export default function ValidateSubscription({
|
export default function ValidateSubscription({
|
||||||
studentId,
|
studentId,
|
||||||
firstName,
|
firstName,
|
||||||
lastName,
|
lastName,
|
||||||
paymentSepa,
|
sepa_file,
|
||||||
file,
|
student_file,
|
||||||
onAccept,
|
onAccept,
|
||||||
}) {
|
}) {
|
||||||
const [token, setToken] = useState(null);
|
const [schoolFileTemplates, setSchoolFileTemplates] = useState([]);
|
||||||
const [uploadedFileName, setUploadedFileName] = useState('');
|
const [parentFileTemplates, setParentFileTemplates] = useState([]);
|
||||||
const [selectedFile, setSelectedFile] = useState(null); // Nouvel état pour le fichier sélectionné
|
const [currentTemplateIndex, setCurrentTemplateIndex] = useState(0);
|
||||||
const [pdfUrl, setPdfUrl] = useState(`${BASE_URL}/${file}`);
|
const [mergeDocuments, setMergeDocuments] = useState(false);
|
||||||
const [isSepa, setIsSepa] = useState(paymentSepa); // Vérifie si le mode de paiement est SEPA
|
|
||||||
const [currentPage, setCurrentPage] = useState(1); // Gestion des étapes
|
|
||||||
const [schoolFileTemplates, setSchoolFileTemplates] = useState([]); // Stocke les fichiers schoolFileTemplates
|
|
||||||
const [parentFileTemplates, setParentFileTemplates] = useState([]); // Stocke les fichiers parentFileTemplates
|
|
||||||
const [mergeDocuments, setMergeDocuments] = useState(false); // État pour activer/désactiver la fusion des documents
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isSepa) {
|
// Récupérer les fichiers schoolFileTemplates
|
||||||
generateToken('n3wt.school@gmail.com')
|
|
||||||
.then((data) => {
|
|
||||||
setToken(data.token);
|
|
||||||
})
|
|
||||||
.catch((error) =>
|
|
||||||
logger.error('Erreur lors de la génération du token:', error)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}, [isSepa]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
// Récupérer les fichiers schoolFileTemplates pour l'étudiant
|
|
||||||
fetchSchoolFileTemplatesFromRegistrationFiles(studentId)
|
fetchSchoolFileTemplatesFromRegistrationFiles(studentId)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setSchoolFileTemplates(data);
|
setSchoolFileTemplates(data);
|
||||||
@ -57,7 +37,7 @@ export default function ValidateSubscription({
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Récupérer les fichiers parentFileTemplates pour l'étudiant
|
// Récupérer les fichiers parentFileTemplates
|
||||||
fetchParentFileTemplatesFromRegistrationFiles(studentId)
|
fetchParentFileTemplatesFromRegistrationFiles(studentId)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
setParentFileTemplates(data);
|
setParentFileTemplates(data);
|
||||||
@ -72,21 +52,13 @@ export default function ValidateSubscription({
|
|||||||
}, [studentId]);
|
}, [studentId]);
|
||||||
|
|
||||||
const handleAccept = () => {
|
const handleAccept = () => {
|
||||||
if (!selectedFile && isSepa) {
|
|
||||||
logger.error('Aucun fichier sélectionné pour le champ SEPA.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ajouter le paramètre fusion dans l'URL
|
|
||||||
const fusionParam = mergeDocuments ? 'true' : 'false';
|
const fusionParam = mergeDocuments ? 'true' : 'false';
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
status: 7,
|
status: 5,
|
||||||
sepa_file: selectedFile, // Utilise le fichier sélectionné depuis l'état
|
|
||||||
fusionParam: fusionParam,
|
fusionParam: fusionParam,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Appeler la fonction passée par le parent pour mettre à jour le RF
|
|
||||||
onAccept(data);
|
onAccept(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -95,150 +67,114 @@ export default function ValidateSubscription({
|
|||||||
setMergeDocuments((prevState) => !prevState);
|
setMergeDocuments((prevState) => !prevState);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isValidateButtonDisabled = isSepa && !uploadedFileName;
|
const allTemplates = [
|
||||||
|
{ name: 'Fiche élève', file: student_file, type: 'main' },
|
||||||
const goToNextPage = () => {
|
...schoolFileTemplates.map((template) => ({
|
||||||
const totalPages =
|
name: template.name || 'Document scolaire',
|
||||||
1 +
|
file: template.file,
|
||||||
schoolFileTemplates.length +
|
description: template.description,
|
||||||
parentFileTemplates.length +
|
})),
|
||||||
(isSepa ? 1 : 0);
|
...parentFileTemplates.map((template) => ({
|
||||||
if (currentPage < totalPages) {
|
name: template.master_name || 'Document parent',
|
||||||
setCurrentPage(currentPage + 1);
|
file: template.file,
|
||||||
}
|
description: template.description,
|
||||||
};
|
})),
|
||||||
|
...(sepa_file
|
||||||
const goToPreviousPage = () => {
|
? [
|
||||||
if (currentPage > 1) {
|
{
|
||||||
setCurrentPage(currentPage - 1);
|
name: 'Mandat SEPA',
|
||||||
}
|
file: sepa_file,
|
||||||
};
|
description: 'Mandat SEPA pour prélèvement automatique',
|
||||||
|
},
|
||||||
const totalPages =
|
]
|
||||||
1 +
|
: []),
|
||||||
schoolFileTemplates.length +
|
];
|
||||||
parentFileTemplates.length +
|
|
||||||
(isSepa ? 1 : 0);
|
|
||||||
|
|
||||||
const renderContent = () => {
|
|
||||||
if (currentPage === 1) {
|
|
||||||
// Page 1 : Afficher le PDF principal
|
|
||||||
return (
|
|
||||||
<iframe
|
|
||||||
src={pdfUrl}
|
|
||||||
title="Aperçu du PDF"
|
|
||||||
className="w-full h-[900px] border rounded-lg"
|
|
||||||
style={{
|
|
||||||
transform: 'scale(0.95)', // Dézoom léger pour une meilleure vue
|
|
||||||
transformOrigin: 'top center',
|
|
||||||
border: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
currentPage > 1 &&
|
|
||||||
currentPage <= 1 + schoolFileTemplates.length
|
|
||||||
) {
|
|
||||||
// Pages des schoolFileTemplates
|
|
||||||
const index = currentPage - 2; // Décalage pour correspondre à l'index du tableau
|
|
||||||
return (
|
|
||||||
<iframe
|
|
||||||
src={`${BASE_URL}/${schoolFileTemplates[index]?.file}`}
|
|
||||||
title={`Document ${index + 1}`}
|
|
||||||
className="w-full h-[900px] border rounded-lg"
|
|
||||||
style={{
|
|
||||||
transform: 'scale(0.95)', // Dézoom léger pour une meilleure vue
|
|
||||||
transformOrigin: 'top center',
|
|
||||||
border: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
} else if (
|
|
||||||
currentPage > 1 + schoolFileTemplates.length &&
|
|
||||||
currentPage <= 1 + schoolFileTemplates.length + parentFileTemplates.length
|
|
||||||
) {
|
|
||||||
// Pages des parentFileTemplates
|
|
||||||
const index = currentPage - 2 - schoolFileTemplates.length; // Décalage pour correspondre à l'index du tableau
|
|
||||||
return (
|
|
||||||
<iframe
|
|
||||||
src={`${BASE_URL}/${parentFileTemplates[index]?.file}`}
|
|
||||||
title={`Document Parent ${index + 1}`}
|
|
||||||
className="w-full h-[900px] border rounded-lg"
|
|
||||||
style={{
|
|
||||||
transform: 'scale(0.95)', // Dézoom léger pour une meilleure vue
|
|
||||||
transformOrigin: 'top center',
|
|
||||||
border: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
} else if (currentPage === totalPages && isSepa) {
|
|
||||||
// Dernière page : Mandat SEPA
|
|
||||||
return (
|
|
||||||
<FileUpload
|
|
||||||
selectionMessage="Sélectionnez un mandat de prélèvement SEPA"
|
|
||||||
onFileSelect={(file) => {
|
|
||||||
setUploadedFileName(file.name); // Stocke uniquement le nom du fichier
|
|
||||||
setSelectedFile(file); // Stocke le fichier dans l'état
|
|
||||||
logger.debug('Fichier sélectionné:', file.name);
|
|
||||||
}}
|
|
||||||
uploadedFileName={uploadedFileName}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6 p-6">
|
<div className="mb-4 w-full mx-auto">
|
||||||
|
{/* En-tête de la section */}
|
||||||
<SectionHeader
|
<SectionHeader
|
||||||
icon={GraduationCap}
|
icon={School}
|
||||||
title={`Dossier scolaire de ${firstName} ${lastName}`}
|
title={`Validation du dossier de ${firstName} ${lastName}`}
|
||||||
description={`Année scolaire ${new Date().getFullYear()}-${new Date().getFullYear() + 1}`}
|
description={`Année scolaire ${new Date().getFullYear()}-${new Date().getFullYear() + 1}`}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Contenu principal */}
|
{/* Contenu principal */}
|
||||||
<div className="p-6 items-center">{renderContent()}</div>
|
<div className="flex gap-8">
|
||||||
|
{/* Liste des documents */}
|
||||||
|
<div className="w-1/4 bg-gray-50 p-4 rounded-lg shadow-sm border border-gray-200">
|
||||||
|
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
||||||
|
Liste des documents
|
||||||
|
</h3>
|
||||||
|
<ul className="space-y-2">
|
||||||
|
{allTemplates.map((template, index) => (
|
||||||
|
<li
|
||||||
|
key={index}
|
||||||
|
className={`flex items-center cursor-pointer ${
|
||||||
|
index === currentTemplateIndex
|
||||||
|
? 'text-blue-600 font-bold'
|
||||||
|
: template.file !== null
|
||||||
|
? 'text-green-600'
|
||||||
|
: 'text-gray-600'
|
||||||
|
}`}
|
||||||
|
onClick={() => setCurrentTemplateIndex(index)} // Mettre à jour l'index du template actuel
|
||||||
|
>
|
||||||
|
<span className="mr-2">
|
||||||
|
{template.file !== null ? (
|
||||||
|
<CheckCircle className="w-5 h-5 text-green-600" />
|
||||||
|
) : (
|
||||||
|
<Hourglass className="w-5 h-5 text-gray-600" />
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
{template.name}
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{/* Option de fusion des documents (affichée uniquement sur la dernière page) */}
|
{/* ToggleSwitch et bouton de validation */}
|
||||||
{currentPage === totalPages && (
|
<div className="mt-6 flex items-center justify-between">
|
||||||
<div className="flex items-center justify-between mt-6">
|
<ToggleSwitch
|
||||||
<span className="text-gray-700">
|
label="Fusionner"
|
||||||
Fusionner les documents en un seul fichier PDF
|
checked={mergeDocuments}
|
||||||
</span>
|
onChange={handleToggleMergeDocuments}
|
||||||
<ToggleSwitch
|
/>
|
||||||
label="Fusionner"
|
<button
|
||||||
checked={mergeDocuments}
|
onClick={handleAccept}
|
||||||
onChange={handleToggleMergeDocuments} // Appeler la fonction pour inverser l'état
|
className="px-4 py-2 bg-emerald-500 text-white rounded-md shadow-sm hover:bg-emerald-600 transition-colors"
|
||||||
/>
|
>
|
||||||
|
Valider
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Boutons de navigation */}
|
{/* Affichage du fichier actuel */}
|
||||||
<div className="flex justify-end items-center mt-6 space-x-4">
|
<div className="w-3/4">
|
||||||
{currentPage > 1 && (
|
{currentTemplateIndex < allTemplates.length && (
|
||||||
<Button
|
<div className="bg-white p-6 rounded-lg shadow-sm border border-gray-200">
|
||||||
text="Précédent"
|
<h3 className="text-lg font-semibold text-gray-800 mb-4">
|
||||||
onClick={goToPreviousPage}
|
{allTemplates[currentTemplateIndex].name || 'Document sans nom'}
|
||||||
className="bg-gray-300 text-gray-700 hover:bg-gray-400 px-6 py-2"
|
</h3>
|
||||||
/>
|
<p className="text-sm text-gray-500 mb-4">
|
||||||
)}
|
{allTemplates[currentTemplateIndex].description ||
|
||||||
{currentPage < totalPages && (
|
'Aucune description disponible pour ce document.'}
|
||||||
<Button
|
</p>
|
||||||
text="Suivant"
|
|
||||||
onClick={goToNextPage}
|
<iframe
|
||||||
primary
|
src={`${BASE_URL}/${allTemplates[currentTemplateIndex].file}`}
|
||||||
className="bg-emerald-500 text-white hover:bg-emerald-600 px-6 py-2"
|
title={
|
||||||
/>
|
allTemplates[currentTemplateIndex].type === 'main'
|
||||||
)}
|
? 'Document Principal'
|
||||||
{currentPage === totalPages && (
|
: 'Document Viewer'
|
||||||
<Button
|
}
|
||||||
text="Valider"
|
className="w-full"
|
||||||
onClick={handleAccept}
|
style={{
|
||||||
primary
|
height: '75vh',
|
||||||
className={`px-6 py-2 ${isValidateButtonDisabled ? 'bg-gray-300 text-gray-700 cursor-not-allowed' : 'bg-emerald-600 text-white hover:bg-emerald-700'}`}
|
border: 'none',
|
||||||
disabled={isValidateButtonDisabled}
|
}}
|
||||||
/>
|
/>
|
||||||
)}
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user