Evite les doublons dans les emails lors d'import de participants
Set version to 0.2.0 (et affiche le en footer)
This commit is contained in:
@@ -87,6 +87,10 @@ function CampaignParticipantsPageContent() {
|
||||
|
||||
const handleImportParticipants = async (data: any[]) => {
|
||||
try {
|
||||
// Récupérer les participants existants pour vérifier les emails
|
||||
const existingParticipants = await participantService.getByCampaign(campaignId);
|
||||
const existingEmails = new Set(existingParticipants.map(p => p.email.toLowerCase()));
|
||||
|
||||
const participantsToCreate = data.map(row => ({
|
||||
campaign_id: campaignId,
|
||||
first_name: row.Prénom || '',
|
||||
@@ -94,11 +98,24 @@ function CampaignParticipantsPageContent() {
|
||||
email: row.Email || ''
|
||||
}));
|
||||
|
||||
// Créer les participants un par un
|
||||
for (const participant of participantsToCreate) {
|
||||
// Filtrer les participants pour éviter les doublons d'email
|
||||
const newParticipants = participantsToCreate.filter(participant => {
|
||||
const email = participant.email.toLowerCase();
|
||||
return email && !existingEmails.has(email);
|
||||
});
|
||||
|
||||
const skippedCount = participantsToCreate.length - newParticipants.length;
|
||||
|
||||
// Créer les nouveaux participants un par un
|
||||
for (const participant of newParticipants) {
|
||||
await participantService.create(participant);
|
||||
}
|
||||
|
||||
// Afficher un message informatif si des participants ont été ignorés
|
||||
if (skippedCount > 0) {
|
||||
alert(`${skippedCount} participant(s) ignoré(s) car leur email existe déjà dans la campagne.`);
|
||||
}
|
||||
|
||||
loadData();
|
||||
} catch (error) {
|
||||
console.error('Erreur lors de l\'import des participants:', error);
|
||||
|
||||
Reference in New Issue
Block a user