synchronisation du contenu avec la DB et amélioration du CMS
- Migration du blog et des interviews des données mockées vers PostgreSQL (Prisma). - Refonte des pages publiques en Server Components pour de meilleures performances/SEO. - Intégration d'un éditeur de texte riche (React Quill) avec titres H1-H6 et séparateurs. - Correction des erreurs de validation Prisma liées aux paramètres asynchrones (Next.js 15+). - Correction des problèmes d'affichage des modales de suspension via React Portals. - Installation de @tailwindcss/typography et correction du débordement de texte (break-words). - Implémentation des actions de modération (suspension/révocation) pour les utilisateurs et boutiques.
This commit is contained in:
52
admin/src/app/actions/moderation.ts
Normal file
52
admin/src/app/actions/moderation.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function getReports() {
|
||||
return await prisma.messageReport.findMany({
|
||||
include: {
|
||||
message: {
|
||||
include: {
|
||||
sender: {
|
||||
select: { id: true, name: true, email: true }
|
||||
},
|
||||
conversation: {
|
||||
include: {
|
||||
business: {
|
||||
select: { id: true, name: true }
|
||||
},
|
||||
messages: {
|
||||
orderBy: { createdAt: 'asc' },
|
||||
include: {
|
||||
sender: {
|
||||
select: { id: true, name: true }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
reporter: {
|
||||
select: { id: true, name: true, email: true }
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateReportStatus(id: string, status: 'RESOLVED' | 'DISMISSED') {
|
||||
try {
|
||||
await prisma.messageReport.update({
|
||||
where: { id },
|
||||
data: { status }
|
||||
});
|
||||
revalidatePath('/moderation');
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
return { success: false, error: "Erreur lors de la mise à jour" };
|
||||
}
|
||||
}
|
||||
125
admin/src/app/actions/suspension.ts
Normal file
125
admin/src/app/actions/suspension.ts
Normal file
@@ -0,0 +1,125 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
/**
|
||||
* Suspend a user account
|
||||
*/
|
||||
export async function suspendUser(userId: string, reason: string) {
|
||||
try {
|
||||
const user = await prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
isSuspended: true,
|
||||
suspensionReason: reason,
|
||||
},
|
||||
include: {
|
||||
businesses: true
|
||||
}
|
||||
});
|
||||
|
||||
// If the user is an entrepreneur with a business, we also suspend the business by default
|
||||
// to hide it from the site during the user's suspension.
|
||||
if (user.businesses) {
|
||||
await prisma.business.update({
|
||||
where: { id: user.businesses.id },
|
||||
data: {
|
||||
isSuspended: true,
|
||||
suspensionReason: `Compte propriétaire suspendu : ${reason}`,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath("/clients");
|
||||
revalidatePath("/entrepreneurs");
|
||||
revalidatePath("/moderation");
|
||||
|
||||
return { success: true, data: user };
|
||||
} catch (error) {
|
||||
console.error("Failed to suspend user:", error);
|
||||
return { success: false, error: "Erreur lors de la suspension" };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend a user account
|
||||
*/
|
||||
export async function unsuspendUser(userId: string) {
|
||||
try {
|
||||
const user = await prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
isSuspended: false,
|
||||
suspensionReason: null,
|
||||
},
|
||||
include: {
|
||||
businesses: true
|
||||
}
|
||||
});
|
||||
|
||||
// Also unsuspend their business if they had one
|
||||
if (user.businesses) {
|
||||
await prisma.business.update({
|
||||
where: { id: user.businesses.id },
|
||||
data: {
|
||||
isSuspended: false,
|
||||
suspensionReason: null,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath("/clients");
|
||||
revalidatePath("/entrepreneurs");
|
||||
revalidatePath("/moderation");
|
||||
|
||||
return { success: true, data: user };
|
||||
} catch (error) {
|
||||
console.error("Failed to unsuspend user:", error);
|
||||
return { success: false, error: "Erreur lors de la réactivation" };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Suspend a specific business (without suspending the whole user account)
|
||||
*/
|
||||
export async function suspendBusiness(businessId: string, reason: string) {
|
||||
try {
|
||||
const business = await prisma.business.update({
|
||||
where: { id: businessId },
|
||||
data: {
|
||||
isSuspended: true,
|
||||
suspensionReason: reason,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath("/entrepreneurs");
|
||||
|
||||
return { success: true, data: business };
|
||||
} catch (error) {
|
||||
console.error("Failed to suspend business:", error);
|
||||
return { success: false, error: "Erreur lors de la suspension de la boutique" };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsuspend a specific business
|
||||
*/
|
||||
export async function unsuspendBusiness(businessId: string) {
|
||||
try {
|
||||
const business = await prisma.business.update({
|
||||
where: { id: businessId },
|
||||
data: {
|
||||
isSuspended: false,
|
||||
suspensionReason: null,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath("/entrepreneurs");
|
||||
|
||||
return { success: true, data: business };
|
||||
} catch (error) {
|
||||
console.error("Failed to unsuspend business:", error);
|
||||
return { success: false, error: "Erreur lors de la réactivation de la boutique" };
|
||||
}
|
||||
}
|
||||
27
admin/src/app/actions/user.ts
Normal file
27
admin/src/app/actions/user.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function getClients() {
|
||||
try {
|
||||
const clients = await prisma.user.findMany({
|
||||
where: {
|
||||
role: { not: "ADMIN" },
|
||||
OR: [
|
||||
{ businesses: null },
|
||||
{ businesses: { isActive: false } }
|
||||
]
|
||||
},
|
||||
include: {
|
||||
businesses: true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
}
|
||||
});
|
||||
return { success: true, data: clients };
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch clients:", error);
|
||||
return { success: false, error: "Erreur lors de la récupération des clients" };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user