mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-29 07:53:23 +00:00
fix: Ordre des guardians lors de leur création / déselection correcte si
plusieurs guardians
This commit is contained in:
@ -43,6 +43,7 @@ import { fetchProfiles } from '@/app/actions/authAction';
|
||||
import { useClasses } from '@/context/ClassesContext';
|
||||
import { useCsrfToken } from '@/context/CsrfContext';
|
||||
import { FE_ADMIN_SUBSCRIPTIONS_URL, BASE_URL } from '@/utils/Url';
|
||||
import { useNotification } from '@/context/NotificationContext';
|
||||
|
||||
export default function CreateSubscriptionPage() {
|
||||
const [formData, setFormData] = useState({
|
||||
@ -67,6 +68,7 @@ export default function CreateSubscriptionPage() {
|
||||
});
|
||||
|
||||
const searchParams = useSearchParams();
|
||||
const { showNotification } = useNotification();
|
||||
// Si l'ID est valorisé, alors on est en mode édition
|
||||
const registerFormID = searchParams.get('id');
|
||||
const registerFormMoment = searchParams.get('school_year');
|
||||
@ -155,6 +157,19 @@ export default function CreateSubscriptionPage() {
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
// Student Form
|
||||
(field === 'studentLastName' &&
|
||||
(!formData.studentLastName ||
|
||||
formData.studentLastName.trim() === '')) ||
|
||||
(field === 'studentFirstName' &&
|
||||
(!formData.studentFirstName ||
|
||||
formData.studentFirstName.trim() === '')) ||
|
||||
(field === 'schoolYear' &&
|
||||
(!formData.schoolYear || formData.schoolYear.trim() === ''))
|
||||
) {
|
||||
return 'Champs requis';
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
@ -247,7 +262,10 @@ export default function CreateSubscriptionPage() {
|
||||
guardianProfileRole:
|
||||
data?.student?.guardians[0]?.profile_role || '',
|
||||
}));
|
||||
|
||||
setIsNewResponsable(
|
||||
!Array.isArray(data?.student?.guardians) ||
|
||||
data.student.guardians.length <= 1
|
||||
);
|
||||
// Définir l'email initial
|
||||
setInitialGuardianEmail(
|
||||
data?.student?.guardians[0]?.associated_profile_email || ''
|
||||
@ -492,6 +510,12 @@ export default function CreateSubscriptionPage() {
|
||||
.catch((error) => {
|
||||
setIsLoading(false);
|
||||
logger.error('Erreur lors de la mise à jour du dossier:', error);
|
||||
showNotification(
|
||||
"Erreur lors de la mise à jour du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_06'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Création du dossier d'inscription
|
||||
@ -533,11 +557,23 @@ export default function CreateSubscriptionPage() {
|
||||
"Erreur lors de l'enregistrement du template:",
|
||||
error
|
||||
);
|
||||
showNotification(
|
||||
"Erreur lors de la création du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_03'
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
setIsLoading(false);
|
||||
logger.error('Error during cloning or sending:', error);
|
||||
showNotification(
|
||||
"Erreur lors de la création du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_05'
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
@ -564,6 +600,12 @@ export default function CreateSubscriptionPage() {
|
||||
"Erreur lors de l'enregistrement du parent template:",
|
||||
error
|
||||
);
|
||||
showNotification(
|
||||
"Erreur lors de la création du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_02'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@ -575,11 +617,23 @@ export default function CreateSubscriptionPage() {
|
||||
})
|
||||
.catch((error) => {
|
||||
setIsLoading(false);
|
||||
showNotification(
|
||||
"Erreur lors de la création du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_04'
|
||||
);
|
||||
logger.error('Error during cloning or sending:', error);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
setIsLoading(false);
|
||||
showNotification(
|
||||
"Erreur lors de la création du dossier d'inscription",
|
||||
'error',
|
||||
'Erreur',
|
||||
'ERR_ADM_SUB_01'
|
||||
);
|
||||
logger.error('Error during register form creation:', error);
|
||||
});
|
||||
}
|
||||
@ -598,23 +652,10 @@ export default function CreateSubscriptionPage() {
|
||||
? prevData.selectedGuardians.filter((id) => id !== guardian.id)
|
||||
: [...prevData.selectedGuardians, guardian.id];
|
||||
|
||||
const updatedFormData = {
|
||||
return {
|
||||
...prevData,
|
||||
selectedGuardians: updatedSelectedGuardians,
|
||||
};
|
||||
|
||||
if (!isSelected) {
|
||||
// Si le guardian est sélectionné, remplir les champs
|
||||
updatedFormData.guardianLastName = guardian.last_name || '';
|
||||
updatedFormData.guardianFirstName = guardian.first_name || '';
|
||||
updatedFormData.guardianEmail = guardian.associated_profile_email || '';
|
||||
updatedFormData.guardianPhone = guardian.phone || '';
|
||||
} else {
|
||||
// Réinitialiser les champs si le guardian est désélectionné
|
||||
resetGuardianFields();
|
||||
}
|
||||
|
||||
return updatedFormData;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react';
|
||||
import { errorMessages } from '@/utils/errorCodes';
|
||||
|
||||
const typeStyles = {
|
||||
success: {
|
||||
@ -26,6 +27,7 @@ export default function FlashNotification({
|
||||
title,
|
||||
message,
|
||||
type = 'info',
|
||||
errorCode,
|
||||
onClose,
|
||||
}) {
|
||||
const [isVisible, setIsVisible] = useState(true);
|
||||
@ -58,6 +60,12 @@ export default function FlashNotification({
|
||||
<div className="flex-1 w-96 p-4">
|
||||
<p className="font-bold text-black">{title}</p>
|
||||
<p className="text-gray-700">{message}</p>
|
||||
{type === 'error' && errorCode && (
|
||||
<div className="mt-2 text-xs text-gray-500">
|
||||
Code :{' '}
|
||||
<span className="font-mono font-bold">{errorCode}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{/* Bouton de fermeture */}
|
||||
<button
|
||||
|
||||
@ -8,14 +8,20 @@ export const NotificationProvider = ({ children }) => {
|
||||
message: '',
|
||||
type: '',
|
||||
title: '',
|
||||
errorCode: '',
|
||||
});
|
||||
|
||||
const showNotification = (message, type = 'info', title = '') => {
|
||||
setNotification({ message, type, title });
|
||||
const showNotification = (
|
||||
message,
|
||||
type = 'info',
|
||||
title = '',
|
||||
errorCode = ''
|
||||
) => {
|
||||
setNotification({ message, type, title, errorCode });
|
||||
};
|
||||
|
||||
const clearNotification = () => {
|
||||
setNotification({ message: '', type: '', title: '' });
|
||||
setNotification({ message: '', type: '', title: '', errorCode: '' });
|
||||
};
|
||||
|
||||
return (
|
||||
@ -25,6 +31,7 @@ export const NotificationProvider = ({ children }) => {
|
||||
title={notification.title}
|
||||
message={notification.message}
|
||||
type={notification.type}
|
||||
errorCode={notification.errorCode}
|
||||
onClose={clearNotification}
|
||||
/>
|
||||
)}
|
||||
|
||||
9
Front-End/src/utils/errorCodes.js
Normal file
9
Front-End/src/utils/errorCodes.js
Normal file
@ -0,0 +1,9 @@
|
||||
export const errorMessages = {
|
||||
// Codes d'erreur sur la partie "ADMIN/Subsription"
|
||||
ERR_ADM_SUB_01: "Erreur lors de la création d'un dossier d'inscription.",
|
||||
ERR_ADM_SUB_02: "Erreur lors de l'enregistrement du template parent.",
|
||||
ERR_ADM_SUB_03: "Erreur lors de l'enregistrement du template école.",
|
||||
ERR_ADM_SUB_04: 'Erreur lors du clone du template parent.',
|
||||
ERR_ADM_SUB_05: 'Erreur lors du clone du template école.',
|
||||
ERR_ADM_SUB_06: "Erreur lors de la mise à jour du dossier d'inscription.",
|
||||
};
|
||||
Reference in New Issue
Block a user