mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-01-28 23:43:22 +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 { useClasses } from '@/context/ClassesContext';
|
||||||
import { useCsrfToken } from '@/context/CsrfContext';
|
import { useCsrfToken } from '@/context/CsrfContext';
|
||||||
import { FE_ADMIN_SUBSCRIPTIONS_URL, BASE_URL } from '@/utils/Url';
|
import { FE_ADMIN_SUBSCRIPTIONS_URL, BASE_URL } from '@/utils/Url';
|
||||||
|
import { useNotification } from '@/context/NotificationContext';
|
||||||
|
|
||||||
export default function CreateSubscriptionPage() {
|
export default function CreateSubscriptionPage() {
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
@ -67,6 +68,7 @@ export default function CreateSubscriptionPage() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
const { showNotification } = useNotification();
|
||||||
// Si l'ID est valorisé, alors on est en mode édition
|
// Si l'ID est valorisé, alors on est en mode édition
|
||||||
const registerFormID = searchParams.get('id');
|
const registerFormID = searchParams.get('id');
|
||||||
const registerFormMoment = searchParams.get('school_year');
|
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 '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -247,7 +262,10 @@ export default function CreateSubscriptionPage() {
|
|||||||
guardianProfileRole:
|
guardianProfileRole:
|
||||||
data?.student?.guardians[0]?.profile_role || '',
|
data?.student?.guardians[0]?.profile_role || '',
|
||||||
}));
|
}));
|
||||||
|
setIsNewResponsable(
|
||||||
|
!Array.isArray(data?.student?.guardians) ||
|
||||||
|
data.student.guardians.length <= 1
|
||||||
|
);
|
||||||
// Définir l'email initial
|
// Définir l'email initial
|
||||||
setInitialGuardianEmail(
|
setInitialGuardianEmail(
|
||||||
data?.student?.guardians[0]?.associated_profile_email || ''
|
data?.student?.guardians[0]?.associated_profile_email || ''
|
||||||
@ -492,6 +510,12 @@ export default function CreateSubscriptionPage() {
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
logger.error('Erreur lors de la mise à jour du dossier:', error);
|
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 {
|
} else {
|
||||||
// Création du dossier d'inscription
|
// Création du dossier d'inscription
|
||||||
@ -533,11 +557,23 @@ export default function CreateSubscriptionPage() {
|
|||||||
"Erreur lors de l'enregistrement du template:",
|
"Erreur lors de l'enregistrement du template:",
|
||||||
error
|
error
|
||||||
);
|
);
|
||||||
|
showNotification(
|
||||||
|
"Erreur lors de la création du dossier d'inscription",
|
||||||
|
'error',
|
||||||
|
'Erreur',
|
||||||
|
'ERR_ADM_SUB_03'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
logger.error('Error during cloning or sending:', error);
|
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:",
|
"Erreur lors de l'enregistrement du parent template:",
|
||||||
error
|
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) => {
|
.catch((error) => {
|
||||||
setIsLoading(false);
|
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);
|
logger.error('Error during cloning or sending:', error);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
setIsLoading(false);
|
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);
|
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.filter((id) => id !== guardian.id)
|
||||||
: [...prevData.selectedGuardians, guardian.id];
|
: [...prevData.selectedGuardians, guardian.id];
|
||||||
|
|
||||||
const updatedFormData = {
|
return {
|
||||||
...prevData,
|
...prevData,
|
||||||
selectedGuardians: updatedSelectedGuardians,
|
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 { useEffect, useState } from 'react';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react';
|
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react';
|
||||||
|
import { errorMessages } from '@/utils/errorCodes';
|
||||||
|
|
||||||
const typeStyles = {
|
const typeStyles = {
|
||||||
success: {
|
success: {
|
||||||
@ -26,6 +27,7 @@ export default function FlashNotification({
|
|||||||
title,
|
title,
|
||||||
message,
|
message,
|
||||||
type = 'info',
|
type = 'info',
|
||||||
|
errorCode,
|
||||||
onClose,
|
onClose,
|
||||||
}) {
|
}) {
|
||||||
const [isVisible, setIsVisible] = useState(true);
|
const [isVisible, setIsVisible] = useState(true);
|
||||||
@ -58,6 +60,12 @@ export default function FlashNotification({
|
|||||||
<div className="flex-1 w-96 p-4">
|
<div className="flex-1 w-96 p-4">
|
||||||
<p className="font-bold text-black">{title}</p>
|
<p className="font-bold text-black">{title}</p>
|
||||||
<p className="text-gray-700">{message}</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>
|
</div>
|
||||||
{/* Bouton de fermeture */}
|
{/* Bouton de fermeture */}
|
||||||
<button
|
<button
|
||||||
|
|||||||
@ -8,14 +8,20 @@ export const NotificationProvider = ({ children }) => {
|
|||||||
message: '',
|
message: '',
|
||||||
type: '',
|
type: '',
|
||||||
title: '',
|
title: '',
|
||||||
|
errorCode: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const showNotification = (message, type = 'info', title = '') => {
|
const showNotification = (
|
||||||
setNotification({ message, type, title });
|
message,
|
||||||
|
type = 'info',
|
||||||
|
title = '',
|
||||||
|
errorCode = ''
|
||||||
|
) => {
|
||||||
|
setNotification({ message, type, title, errorCode });
|
||||||
};
|
};
|
||||||
|
|
||||||
const clearNotification = () => {
|
const clearNotification = () => {
|
||||||
setNotification({ message: '', type: '', title: '' });
|
setNotification({ message: '', type: '', title: '', errorCode: '' });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -25,6 +31,7 @@ export const NotificationProvider = ({ children }) => {
|
|||||||
title={notification.title}
|
title={notification.title}
|
||||||
message={notification.message}
|
message={notification.message}
|
||||||
type={notification.type}
|
type={notification.type}
|
||||||
|
errorCode={notification.errorCode}
|
||||||
onClose={clearNotification}
|
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