import Link from "next/link"; import { verifySession } from "@/lib/dal"; import { createClient } from "@/lib/supabase/server"; import { Card, CardContent } from "@/components/ui/card"; export default async function MessagesPage() { const user = await verifySession(); const supabase = await createClient(); const { data: conversations } = await supabase .from("conversations") .select( "id, created_at, author_id, merchant_id, needs(title), author:profiles!conversations_author_id_fkey(full_name), merchant:profiles!conversations_merchant_id_fkey(full_name)" ) .order("created_at", { ascending: false }); return (

Messages

{!conversations || conversations.length === 0 ? (

Aucune conversation pour le moment. Elles apparaissent ici une fois qu'une offre est acceptée.

) : (
{conversations.map((conv) => { const isAuthor = conv.author_id === user.id; const other = isAuthor ? conv.merchant : conv.author; const otherName = Array.isArray(other) ? other[0]?.full_name : other?.full_name; const need = Array.isArray(conv.needs) ? conv.needs[0] : conv.needs; return (

{otherName ?? "Utilisateur"}

{need?.title}

); })}
)}
); }