import { postAdminComment } from "@/app/admin/clients/[id]/actions"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import type { Comment } from "@/db/schema"; import type { ClientFullDetail } from "@/lib/admin-queries"; type Props = { comments: Comment[]; phases: ClientFullDetail["phases"]; clientId: string; }; export async function CommentsTab({ comments, phases, clientId }: Props) { // Build entity label map for display (phases, tasks, deliverables, and general) const entityLabels: Record = { [clientId]: "Messaggio generale", }; for (const phase of phases) { entityLabels[phase.id] = `Fase: ${phase.title}`; for (const task of phase.tasks) { entityLabels[task.id] = `Task: ${task.title}`; for (const d of task.deliverables) { entityLabels[d.id] = `Deliverable: ${d.title}`; } } } // Build list of entities the admin can reply on const entities: Array<{ id: string; type: string; label: string }> = [ { id: clientId, type: "general", label: "Messaggio generale" }, ]; for (const phase of phases) { entities.push({ id: phase.id, type: "phase", label: `Fase: ${phase.title}` }); for (const task of phase.tasks) { entities.push({ id: task.id, type: "task", label: `Task: ${task.title}` }); for (const d of task.deliverables) { entities.push({ id: d.id, type: "deliverable", label: `Deliverable: ${d.title}`, }); } } } return (
{/* Comment list */} {comments.length === 0 && (

Nessun commento ancora.

)}
{comments.map((c) => (

{c.author === "admin" ? "iamcavalli" : "Cliente"} —{" "} {entityLabels[c.entity_id] ?? c.entity_id}

{c.body}

))}
{/* Admin reply form */}
{ "use server"; await postAdminComment(clientId, fd); }} className="bg-white border border-gray-200 rounded-lg p-4 space-y-3" >

Rispondi come admin