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:
2026-04-12 18:59:20 +02:00
parent b73939d381
commit 887030ee47
84 changed files with 5577 additions and 15128 deletions

View File

@@ -3,12 +3,14 @@
import React, { useState, useEffect } from 'react';
import Link from 'next/link';
import { LayoutDashboard, Edit3, ShoppingBag, CreditCard, LogOut, Eye } from 'lucide-react';
import { useRouter } from 'next/navigation';
import { LayoutDashboard, Edit3, ShoppingBag, CreditCard, LogOut, Eye, MessageSquare, User as UserIcon, Rocket } from 'lucide-react';
import { useRouter, useSearchParams } from 'next/navigation';
import { User } from '../../types';
import { MOCK_BUSINESSES } from '../../lib/mockData';
import DashboardOverview from '../../components/dashboard/DashboardOverview';
import DashboardProfile from '../../components/dashboard/DashboardProfile';
import DashboardProfileClient from '../../components/dashboard/DashboardProfileClient';
import DashboardMessages from '../../components/dashboard/DashboardMessages';
import DashboardOffers from '../../components/dashboard/DashboardOffers';
import PricingSection from '../../components/PricingSection';
import { useUser } from '../../components/UserProvider';
@@ -16,14 +18,25 @@ import { useUser } from '../../components/UserProvider';
const DashboardPage = () => {
const { user, logout } = useUser();
const router = useRouter();
const [currentView, setCurrentView] = useState<'overview' | 'profile' | 'offers' | 'subscription'>('overview');
const searchParams = useSearchParams();
const chatId = searchParams.get('chatId') || searchParams.get('chat');
const [currentView, setCurrentView] = useState<'overview' | 'profile' | 'offers' | 'subscription' | 'messages' | 'personal-profile'>('overview');
const [business, setBusiness] = useState<any>(null);
const [stats, setStats] = useState<{ totalViews: number, contactClicks: number } | null>(null);
const [loading, setLoading] = useState(true);
const [isMounted, setIsMounted] = useState(false);
const [unreadCount, setUnreadCount] = useState(0);
useEffect(() => {
setIsMounted(true);
}, []);
// Handle view from URL
const viewParam = searchParams.get('view');
if (viewParam && ['overview', 'profile', 'offers', 'subscription', 'messages', 'personal-profile'].includes(viewParam)) {
setCurrentView(viewParam as any);
}
}, [searchParams]);
// Fetch user's business
useEffect(() => {
@@ -37,6 +50,17 @@ const DashboardPage = () => {
const data = await res.json();
if (data && !data.error) {
setBusiness(data);
// Fetch stats for this business
try {
const statsRes = await fetch(`/api/analytics/businesses/${data.id}`);
const statsData = await statsRes.json();
if (!statsData.error) {
setStats(statsData);
}
} catch (e) {
console.error('Error fetching stats:', e);
}
}
} catch (error) {
console.error('Error fetching dashboard business:', error);
@@ -48,14 +72,60 @@ const DashboardPage = () => {
fetchBusiness();
}, [user, isMounted]);
if (!isMounted) return null;
// Fetch unread messages count
const fetchUnreadCount = async () => {
if (!user || !isMounted) return;
// If user has no id, try to find it via email (Session Reconciliation)
let effectiveUserId = user.id;
if (!effectiveUserId || effectiveUserId === 'undefined' || effectiveUserId === 'null') {
try {
const res = await fetch(`/api/users/profile?email=${encodeURIComponent(user.email)}`);
const data = await res.json();
if (data.id) {
effectiveUserId = data.id;
// Note: Ideally we'd update the global user object here too
} else {
return; // Can't count without ID
}
} catch (e) { return; }
}
if (!user) {
if (typeof window !== 'undefined') router.push('/login');
return null;
}
try {
const res = await fetch('/api/messages/unread', {
headers: { 'x-user-id': effectiveUserId }
});
const data = await res.json();
if (!data.error) {
setUnreadCount(data.count);
}
} catch (error) {
console.error('Error fetching unread count:', error);
}
};
if (loading) {
useEffect(() => {
fetchUnreadCount();
const interval = setInterval(fetchUnreadCount, 15000); // Polling every 15s
return () => clearInterval(interval);
}, [user, isMounted]);
// Update document title with unread count
useEffect(() => {
if (unreadCount > 0) {
document.title = `(${unreadCount}) Messages - Afropreunariat`;
} else {
document.title = 'Tableau de Bord - Afropreunariat';
}
}, [unreadCount]);
useEffect(() => {
if (!user && isMounted) {
router.push('/login');
}
}, [user, isMounted, router]);
if (!isMounted || (loading && user)) {
return (
<div className="min-h-screen flex items-center justify-center bg-gray-50">
<div className="flex flex-col items-center">
@@ -66,6 +136,10 @@ const DashboardPage = () => {
);
}
if (!user) {
return null;
}
// Default business structure for new users
const displayBusiness = business || {
id: 'new',
@@ -76,6 +150,7 @@ const DashboardPage = () => {
logoUrl: "https://picsum.photos/200/200?random=default",
contactEmail: user?.email || "",
contactPhone: "",
slug: "",
tags: [],
socialLinks: {},
verified: false,
@@ -96,15 +171,21 @@ const DashboardPage = () => {
</div>
<div className="flex-1 flex flex-col overflow-y-auto pt-5 pb-4">
<div className="px-4 mb-6">
<div className="flex items-center">
<div className="h-10 w-10 rounded-full bg-gray-300 flex items-center justify-center text-gray-600 font-bold shrink-0">
<div className="flex items-center relative group">
<div className="h-12 w-12 rounded-full bg-gradient-to-br from-brand-400 to-brand-600 flex items-center justify-center text-white font-bold shrink-0 relative shadow-lg shadow-brand-200 border-2 border-white">
{user.name.charAt(0)}
{unreadCount > 0 && (
<>
<span className="absolute -top-1.5 -right-1.5 block h-4 w-4 rounded-full bg-red-600 border-2 border-white animate-bounce"></span>
<span className="absolute -top-1.5 -right-1.5 block h-4 w-4 rounded-full bg-red-400 animate-ping opacity-75"></span>
</>
)}
</div>
<div className="ml-3">
<p className="text-sm font-medium text-gray-700 truncate">{user.name}</p>
<div className="flex items-center mt-1">
<span className="h-2 w-2 rounded-full bg-green-400 mr-1"></span>
<span className="text-xs text-gray-500">Actif</span>
<p className="text-sm font-bold text-gray-900 truncate">{user.name}</p>
<div className="flex items-center mt-0.5">
<span className="h-2 w-2 rounded-full bg-green-500 mr-1.5 shadow-[0_0_8px_rgba(34,197,94,0.6)]"></span>
<span className="text-[10px] font-bold text-green-600 uppercase tracking-tighter">En ligne</span>
</div>
</div>
</div>
@@ -114,18 +195,53 @@ const DashboardPage = () => {
<LayoutDashboard className={`${currentView === 'overview' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Tableau de Bord
</button>
<button onClick={() => setCurrentView('profile')} className={`${currentView === 'profile' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<Edit3 className={`${currentView === 'profile' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Éditer mon profil
<button onClick={() => setCurrentView('messages')} className={`${currentView === 'messages' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full relative`}>
<MessageSquare className={`${currentView === 'messages' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Messages
{unreadCount > 0 && (
<span className="absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-1.5">
<span className="flex h-5 w-5 items-center justify-center rounded-full bg-red-500 text-[10px] font-bold text-white shadow-lg shadow-red-200">
{unreadCount}
</span>
<span className="flex h-2 w-2 rounded-full bg-red-500 animate-pulse"></span>
</span>
)}
</button>
<button onClick={() => setCurrentView('offers')} className={`${currentView === 'offers' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<ShoppingBag className={`${currentView === 'offers' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Mes Offres
</button>
<button onClick={() => setCurrentView('subscription')} className={`${currentView === 'subscription' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<CreditCard className={`${currentView === 'subscription' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Abonnement
<button onClick={() => setCurrentView('personal-profile')} className={`${currentView === 'personal-profile' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<UserIcon className={`${currentView === 'personal-profile' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Mon Profil Client
</button>
<div className="pt-4 pb-2">
<p className="px-3 text-[10px] font-semibold text-gray-400 uppercase tracking-wider">Espace Business</p>
</div>
{user.role === 'ENTREPRENEUR' ? (
<>
<button onClick={() => setCurrentView('profile')} className={`${currentView === 'profile' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<Edit3 className={`${currentView === 'profile' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Ma Fiche Entreprise
</button>
<button onClick={() => setCurrentView('offers')} className={`${currentView === 'offers' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<ShoppingBag className={`${currentView === 'offers' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Mes Offres
</button>
<button onClick={() => setCurrentView('subscription')} className={`${currentView === 'subscription' ? 'bg-brand-50 text-brand-700' : 'text-gray-600 hover:bg-gray-50 hover:text-gray-900'} group flex items-center px-2 py-2 text-sm font-medium rounded-md w-full`}>
<CreditCard className={`${currentView === 'subscription' ? 'text-brand-500' : 'text-gray-400 group-hover:text-gray-500'} mr-3 flex-shrink-0 h-5 w-5`} />
Abonnement
</button>
</>
) : (
<button
onClick={() => setCurrentView('profile')}
className="mt-2 group flex items-center px-2 py-3 text-sm font-bold rounded-md w-full bg-brand-600 text-white hover:bg-brand-700 transition-all shadow-md group border-2 border-brand-400"
>
<Rocket className="mr-3 flex-shrink-0 h-5 w-5 text-brand-200" />
Propulser mon Business
</button>
)}
</nav>
</div>
<div className="flex-shrink-0 flex border-t border-gray-200 p-4">
@@ -143,7 +259,9 @@ const DashboardPage = () => {
<header className="bg-white shadow-sm z-10 flex justify-between items-center px-6 py-4 sticky top-0">
<h1 className="text-2xl font-bold text-gray-900 sm:truncate">
{currentView === 'overview' && 'Vue d\'ensemble'}
{currentView === 'profile' && 'Mon Profil'}
{currentView === 'messages' && 'Mes Messages'}
{currentView === 'personal-profile' && 'Mon Profil Client'}
{currentView === 'profile' && (user.role === 'ENTREPRENEUR' ? 'Ma Fiche Entreprise' : 'Créer mon Business')}
{currentView === 'offers' && 'Gestion des Offres'}
{currentView === 'subscription' && 'Mon Abonnement'}
</h1>
@@ -156,8 +274,28 @@ const DashboardPage = () => {
</header>
<main className="flex-1 overflow-y-auto p-6">
<div className="max-w-7xl mx-auto">
{currentView === 'overview' && <DashboardOverview business={displayBusiness} />}
<div className="max-w-7xl mx-auto space-y-6">
{business?.isSuspended && (
<div className="bg-orange-50 border-l-4 border-orange-500 p-4 rounded-r-lg shadow-sm animate-in fade-in slide-in-from-top duration-500">
<div className="flex">
<div className="flex-shrink-0">
<ShieldAlert className="h-5 w-5 text-orange-500" aria-hidden="true" />
</div>
<div className="ml-3">
<p className="text-sm text-orange-700 font-bold uppercase tracking-tight">Boutique Suspendue</p>
<p className="text-sm text-orange-600 mt-1 italic">
"{business.suspensionReason || "Votre boutique a é temporairement masquée suite à une décision de la modération."}"
</p>
<p className="text-xs text-orange-500 mt-2 font-medium">
Veuillez contacter l'administration pour plus d'informations.
</p>
</div>
</div>
</div>
)}
{currentView === 'overview' && <DashboardOverview business={displayBusiness} stats={stats} />}
{currentView === 'messages' && <DashboardMessages onMessagesRead={fetchUnreadCount} initialConversationId={chatId} />}
{currentView === 'personal-profile' && <DashboardProfileClient />}
{currentView === 'profile' && <DashboardProfile business={displayBusiness} setBusiness={setBusiness} />}
{currentView === 'offers' && <DashboardOffers />}
{currentView === 'subscription' && (