Added new design to modals

This commit is contained in:
2026-02-08 14:16:55 +01:00
parent ccff904464
commit ff6201a42c
15 changed files with 1134 additions and 435 deletions

View File

@@ -4,6 +4,7 @@ import { getCurrentUser } from '@/lib/auth';
import { writeFile } from 'fs/promises';
import { join } from 'path';
import { existsSync, mkdirSync } from 'fs';
import { createNotification } from '@/lib/notifications';
// GET - Récupérer les messages d'une conversation
export async function GET(
@@ -23,7 +24,17 @@ export async function GET(
const conversation = await prisma.conversation.findUnique({
where: { id: params.id },
include: {
participants: true,
participants: {
include: {
user: {
select: {
id: true,
name: true,
email: true,
},
},
},
},
},
});
@@ -101,7 +112,17 @@ export async function POST(
const conversation = await prisma.conversation.findUnique({
where: { id: params.id },
include: {
participants: true,
participants: {
include: {
user: {
select: {
id: true,
name: true,
email: true,
},
},
},
},
},
});
@@ -197,13 +218,44 @@ export async function POST(
},
});
// Mettre à jour la date de mise à jour de la conversation
await prisma.conversation.update({
where: { id: params.id },
data: { updatedAt: new Date() },
});
// Mettre à jour la date de mise à jour de la conversation
await prisma.conversation.update({
where: { id: params.id },
data: { updatedAt: new Date() },
});
return NextResponse.json(messageWithFiles, { status: 201 });
// Créer des notifications pour tous les participants sauf l'expéditeur
const participants = conversation.participants.filter((p) => p.userId !== user.id);
// Récupérer le nom de la conversation
let conversationName = '';
if (conversation.type === 'group') {
conversationName = conversation.name || 'Groupe';
} else {
// Pour une conversation directe, utiliser le nom de l'autre participant
const otherParticipant = participants.find((p) => p.user);
conversationName = otherParticipant?.user?.name || otherParticipant?.user?.email || 'Utilisateur';
}
const messagePreview = content
? (content.length > 100 ? content.substring(0, 100) + '...' : content)
: files.length > 0
? `${files.length} fichier${files.length > 1 ? 's' : ''}`
: 'Nouveau message';
await Promise.all(
participants.map((participant) =>
createNotification({
userId: participant.userId,
type: 'message',
title: conversationName,
message: messagePreview,
link: `/dashboard/messagerie?conversation=${params.id}`,
})
)
);
return NextResponse.json(messageWithFiles, { status: 201 });
}
// Mettre à jour la date de mise à jour de la conversation
@@ -212,6 +264,35 @@ export async function POST(
data: { updatedAt: new Date() },
});
// Créer des notifications pour tous les participants sauf l'expéditeur
const participants = conversation.participants.filter((p) => p.userId !== user.id);
// Récupérer le nom de la conversation
let conversationName = '';
if (conversation.type === 'group') {
conversationName = conversation.name || 'Groupe';
} else {
// Pour une conversation directe, utiliser le nom de l'autre participant
const otherParticipant = participants.find((p) => p.user);
conversationName = otherParticipant?.user?.name || otherParticipant?.user?.email || 'Utilisateur';
}
const messagePreview = content
? (content.length > 100 ? content.substring(0, 100) + '...' : content)
: 'Nouveau message';
await Promise.all(
participants.map((participant) =>
createNotification({
userId: participant.userId,
type: 'message',
title: conversationName,
message: messagePreview,
link: `/dashboard/messagerie?conversation=${params.id}`,
})
)
);
return NextResponse.json(message, { status: 201 });
} catch (error) {
console.error('Erreur lors de l\'envoi du message:', error);