mirror of
https://git.v0id.ovh/n3wt-innov/n3wt-school.git
synced 2026-04-03 16:51:26 +00:00
feat: Envoi mail d'inscription aux enseignants [N3WTS-1]
This commit is contained in:
@ -140,38 +140,19 @@ const TeachersSection = ({
|
||||
const [removePopupMessage, setRemovePopupMessage] = useState('');
|
||||
const [removePopupOnConfirm, setRemovePopupOnConfirm] = useState(() => {});
|
||||
|
||||
const [confirmPopupVisible, setConfirmPopupVisible] = useState(false);
|
||||
const [confirmPopupMessage, setConfirmPopupMessage] = useState('');
|
||||
const [confirmPopupOnConfirm, setConfirmPopupOnConfirm] = useState(() => {});
|
||||
|
||||
const { selectedEstablishmentId } = useEstablishment();
|
||||
|
||||
// --- UTILS ---
|
||||
|
||||
// Retourne le profil existant pour un email, utilisé par un teacher actif ou le teacher en cours d'édition
|
||||
const getUsedProfileForEmail = (email, teacherId = null) => {
|
||||
const usedProfileIds = new Set(
|
||||
teachers.map(t => t.profile_role && t.profile).filter(Boolean)
|
||||
);
|
||||
// Ajoute le profil du teacher en cours d'édition si besoin
|
||||
if (teacherId) {
|
||||
const currentTeacher = teachers.find(t => t.id === teacherId);
|
||||
if (currentTeacher && currentTeacher.profile_role && currentTeacher.profile) {
|
||||
const profileObj = profiles.find(p => p.id === currentTeacher.profile);
|
||||
if (profileObj && profileObj.email === email) {
|
||||
usedProfileIds.add(profileObj.id);
|
||||
}
|
||||
} else {
|
||||
// Cas création immédiate : on cherche le profil par email dans profiles
|
||||
const profileObj = profiles.find(p => p.email === email);
|
||||
if (profileObj) {
|
||||
usedProfileIds.add(profileObj.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles.find(
|
||||
(profile) => profile.email === email && usedProfileIds.has(profile.id)
|
||||
);
|
||||
// Retourne le profil existant pour un email
|
||||
const getUsedProfileForEmail = (email) => {
|
||||
// On cherche tous les profils dont l'email correspond
|
||||
const matchingProfiles = profiles.filter(p => p.email === email);
|
||||
|
||||
// On retourne le premier profil correspondant (ou undefined)
|
||||
const result = matchingProfiles.length > 0 ? matchingProfiles[0] : undefined;
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
// Met à jour le formData et newTeacher si besoin
|
||||
@ -189,7 +170,7 @@ const TeachersSection = ({
|
||||
|
||||
const handleEmailChange = (e) => {
|
||||
const email = e.target.value;
|
||||
const existingProfile = getUsedProfileForEmail(email, editingTeacher);
|
||||
const existingProfile = getUsedProfileForEmail(email);
|
||||
|
||||
if (existingProfile) {
|
||||
logger.info(`Adresse email déjà utilisée pour le profil ${existingProfile.id}`);
|
||||
@ -290,9 +271,6 @@ const TeachersSection = ({
|
||||
};
|
||||
|
||||
const handleUpdateTeacher = (id, updatedData) => {
|
||||
// Simplification : le profil est forcément existant, on utilise directement existingProfileId du formData
|
||||
const currentTeacher = teachers.find((teacher) => teacher.id === id);
|
||||
|
||||
if (
|
||||
updatedData.last_name &&
|
||||
updatedData.first_name &&
|
||||
@ -302,7 +280,6 @@ const TeachersSection = ({
|
||||
id: updatedData.profile_role,
|
||||
establishment: selectedEstablishmentId,
|
||||
role_type: updatedData.role_type || 0,
|
||||
is_active: true,
|
||||
profile: updatedData.existingProfileId,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user