import { useForm } from "@inertiajs/react"; import { useState } from "react"; import { newSubmissionKey } from "@/lib/portal-api"; import { Field, card, input, button, api } from "./shared"; export type Message = { id: string; sender_role: string; body: string; created_at: string }; export function Conversation({ id, messages, submitted, revisions, }: { id: string; messages: Message[]; submitted: boolean; revisions: { version: number; created_at: string }[]; }) { const form = useForm({ client_key: newSubmissionKey(), body: "" }); const [revision, setRevision] = useState<{ version: number; snapshot: { payload: { full_name?: string; organisation?: string; objective?: string; horizon?: string; }; needs: { details: { description: string } }[]; attachment_ids: string[]; }; } | null>(null); const [error, setError] = useState(""); return ( <>

Versões guardadas

{error &&

{error}

} {revision && (

Versão {revision.version}

Investidor: {revision.snapshot.payload.full_name}

Empresa: {revision.snapshot.payload.organisation || "Não indicada"}

Objectivo: {revision.snapshot.payload.objective || "Não indicado"}

Prazo: {revision.snapshot.payload.horizon || "Não indicado"}

{revision.snapshot.attachment_ids.length} anexos associados nessa versão.

)}
{submitted && (

Conversa com o apoio

As mensagens ficam registadas neste pedido e são visíveis ao investidor e à equipa autorizada.

{messages.map((m) => (

{m.sender_role === "support" ? "Apoio ao Investidor" : "Investidor"}{" "} · {new Date(m.created_at).toLocaleString("pt-MZ")}

{m.body}

))} {!messages.length &&

Ainda não existem mensagens neste pedido.

}
{ e.preventDefault(); form.post(`/investidor/manifestacoes/${id}/messages`, { preserveScroll: true, onSuccess: () => form.setData({ client_key: newSubmissionKey(), body: "" }), }); }} >