- 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.
126 lines
3.1 KiB
TypeScript
126 lines
3.1 KiB
TypeScript
"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" };
|
|
}
|
|
}
|