feat: Ajout de la fratrie [#27]

This commit is contained in:
N3WT DE COMPET
2025-05-02 17:44:35 +02:00
parent 1ced4a1069
commit 4a382d523c
8 changed files with 279 additions and 30 deletions

View File

@ -7,6 +7,7 @@ import logger from '@/utils/logger';
import SectionHeader from '@/components/SectionHeader';
import { User } from 'lucide-react';
import FileUpload from '@/components/FileUpload';
import { BASE_URL } from '@/utils/Url';
const levels = [
{ value: '1', label: 'TPS - Très Petite Section' },
@ -25,6 +26,7 @@ export default function StudentInfoForm({
formData,
setFormData,
setGuardians,
setSiblings,
errors,
setIsPageValid,
hasInteracted,
@ -37,9 +39,11 @@ export default function StudentInfoForm({
fetchRegisterForm(studentId).then((data) => {
logger.debug(data);
const photoPath = data?.student?.photo || null;
setFormData({
id: data?.student?.id || '',
photo: data?.student?.photo || null,
photo: photoPath,
last_name: data?.student?.last_name || '',
first_name: data?.student?.first_name || '',
address: data?.student?.address || '',
@ -56,7 +60,29 @@ export default function StudentInfoForm({
totalRegistrationFees: data?.totalRegistrationFees,
totalTuitionFees: data?.totalTuitionFees,
});
setGuardians(data?.student?.guardians || []);
setSiblings(data?.student?.siblings || []);
// Convertir la photo en fichier binaire si elle est un chemin ou une URL
if (photoPath && typeof photoPath === 'string') {
fetch(`${BASE_URL}${photoPath}`)
.then((response) => {
if (!response.ok) {
throw new Error('Erreur lors de la récupération de la photo.');
}
return response.blob();
})
.then((blob) => {
const file = new File([blob], photoPath.split('/').pop(), {
type: blob.type,
});
handlePhotoUpload(file); // Utiliser handlePhotoUpload pour valoriser la photo
})
.catch((error) => {
logger.error('Erreur lors de la conversion de la photo :', error);
});
}
});
setIsLoading(false);