@@ -1,8 +1,13 @@
|
||||
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 };
|
||||
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,
|
||||
@@ -14,7 +19,7 @@ export function Conversation({
|
||||
submitted: boolean;
|
||||
revisions: { version: number; created_at: string }[];
|
||||
}) {
|
||||
const form = useForm({ client_key: newSubmissionKey(), body: "" });
|
||||
const form = useForm({ client_key: newSubmissionKey(), body: '' });
|
||||
const [revision, setRevision] = useState<{
|
||||
version: number;
|
||||
snapshot: {
|
||||
@@ -28,31 +33,37 @@ export function Conversation({
|
||||
attachment_ids: string[];
|
||||
};
|
||||
} | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
const [error, setError] = useState('');
|
||||
return (
|
||||
<>
|
||||
<section className={card + " space-y-4"}>
|
||||
<section className={card + ' space-y-4'}>
|
||||
<h2 className="text-xl font-bold">Versões guardadas</h2>
|
||||
<Field label="Consultar versão">
|
||||
<select
|
||||
className={input}
|
||||
defaultValue=""
|
||||
onChange={(e) => {
|
||||
setError("");
|
||||
setError('');
|
||||
if (!e.target.value) {
|
||||
setRevision(null);
|
||||
return;
|
||||
}
|
||||
api(`/api/v1/investment/submissions/${id}/revisions/${e.target.value}`)
|
||||
api(
|
||||
`/api/v1/investment/submissions/${id}/revisions/${e.target.value}`,
|
||||
)
|
||||
.then(setRevision)
|
||||
.catch(() => setError("Não foi possível consultar esta versão."));
|
||||
.catch(() =>
|
||||
setError(
|
||||
'Não foi possível consultar esta versão.',
|
||||
),
|
||||
);
|
||||
}}
|
||||
>
|
||||
<option value="">Seleccionar versão</option>
|
||||
{revisions.map((r) => (
|
||||
<option value={r.version} key={r.version}>
|
||||
Versão {r.version} —{" "}
|
||||
{new Date(r.created_at).toLocaleString("pt-MZ")}
|
||||
Versão {r.version} —{' '}
|
||||
{new Date(r.created_at).toLocaleString('pt-MZ')}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
@@ -62,49 +73,70 @@ export function Conversation({
|
||||
<div className="space-y-2">
|
||||
<h3 className="font-bold">Versão {revision.version}</h3>
|
||||
<p>Investidor: {revision.snapshot.payload.full_name}</p>
|
||||
<p>Empresa: {revision.snapshot.payload.organisation || "Não indicada"}</p>
|
||||
<p className="whitespace-pre-line">
|
||||
Objectivo: {revision.snapshot.payload.objective || "Não indicado"}
|
||||
<p>
|
||||
Empresa:{' '}
|
||||
{revision.snapshot.payload.organisation ||
|
||||
'Não indicada'}
|
||||
</p>
|
||||
<p className="whitespace-pre-line">
|
||||
Objectivo:{' '}
|
||||
{revision.snapshot.payload.objective ||
|
||||
'Não indicado'}
|
||||
</p>
|
||||
<p>
|
||||
Prazo:{' '}
|
||||
{revision.snapshot.payload.horizon ||
|
||||
'Não indicado'}
|
||||
</p>
|
||||
<p>Prazo: {revision.snapshot.payload.horizon || "Não indicado"}</p>
|
||||
<ul>
|
||||
{revision.snapshot.needs.map((n, i) => (
|
||||
<li key={i}>{n.details.description}</li>
|
||||
))}
|
||||
</ul>
|
||||
<p>
|
||||
{revision.snapshot.attachment_ids.length} anexos associados nessa
|
||||
versão.
|
||||
{revision.snapshot.attachment_ids.length} anexos
|
||||
associados nessa versão.
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
{submitted && (
|
||||
<section className={card + " space-y-4"}>
|
||||
<section className={card + ' space-y-4'}>
|
||||
<h2 className="text-xl font-bold">Conversa com o apoio</h2>
|
||||
<p>
|
||||
As mensagens ficam registadas neste pedido e são visíveis ao investidor e à
|
||||
equipa autorizada.
|
||||
As mensagens ficam registadas neste pedido e são
|
||||
visíveis ao investidor e à equipa autorizada.
|
||||
</p>
|
||||
{messages.map((m) => (
|
||||
<article key={m.id} className="rounded-lg border p-4">
|
||||
<p className="font-semibold">
|
||||
{m.sender_role === "support" ? "Apoio ao Investidor" : "Investidor"}{" "}
|
||||
· {new Date(m.created_at).toLocaleString("pt-MZ")}
|
||||
{m.sender_role === 'support'
|
||||
? 'Apoio ao Investidor'
|
||||
: 'Investidor'}{' '}
|
||||
·{' '}
|
||||
{new Date(m.created_at).toLocaleString('pt-MZ')}
|
||||
</p>
|
||||
<p className="mt-2 whitespace-pre-line">{m.body}</p>
|
||||
</article>
|
||||
))}
|
||||
{!messages.length && <p>Ainda não existem mensagens neste pedido.</p>}
|
||||
{!messages.length && (
|
||||
<p>Ainda não existem mensagens neste pedido.</p>
|
||||
)}
|
||||
<form
|
||||
className="space-y-3"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.post(`/investidor/manifestacoes/${id}/messages`, {
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
form.setData({ client_key: newSubmissionKey(), body: "" }),
|
||||
});
|
||||
form.post(
|
||||
`/investidor/manifestacoes/${id}/messages`,
|
||||
{
|
||||
preserveScroll: true,
|
||||
onSuccess: () =>
|
||||
form.setData({
|
||||
client_key: newSubmissionKey(),
|
||||
body: '',
|
||||
}),
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<Field label="Mensagem para acompanhamento">
|
||||
@@ -115,7 +147,9 @@ export function Conversation({
|
||||
minLength={3}
|
||||
maxLength={5000}
|
||||
value={form.data.body}
|
||||
onChange={(e) => form.setData("body", e.target.value)}
|
||||
onChange={(e) =>
|
||||
form.setData('body', e.target.value)
|
||||
}
|
||||
/>
|
||||
</Field>
|
||||
{Object.entries(form.errors).map(([key, value]) => (
|
||||
|
||||
Reference in New Issue
Block a user