@@ -0,0 +1,578 @@
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import { Frame, card, input, button } from '@/pages/investment/shared';
|
||||
import {
|
||||
DocumentReview,
|
||||
RequestOperations,
|
||||
type DeskDocument,
|
||||
type DeskPayment,
|
||||
} from '@/components/desk-internal-operations';
|
||||
|
||||
type Field = {
|
||||
label: string;
|
||||
type: string;
|
||||
required: boolean;
|
||||
options?: Record<string, string>;
|
||||
when?: { field: string; equals: string };
|
||||
};
|
||||
export default function RequestPage({
|
||||
request,
|
||||
case: dossier,
|
||||
definition,
|
||||
owner,
|
||||
manager,
|
||||
analyst,
|
||||
fieldsEditable,
|
||||
states,
|
||||
transitions,
|
||||
findings,
|
||||
messages,
|
||||
analysts,
|
||||
territories,
|
||||
events,
|
||||
documents,
|
||||
payments,
|
||||
caseVersion,
|
||||
}: {
|
||||
request: {
|
||||
id: string;
|
||||
version: number;
|
||||
status: string;
|
||||
payload: Record<string, string>;
|
||||
protocol: string | null;
|
||||
editable_fields: string[];
|
||||
analyst_id: number | null;
|
||||
due_at: string | null;
|
||||
};
|
||||
case: { id: string; title: string };
|
||||
definition: {
|
||||
title: string;
|
||||
fields: Record<string, Field>;
|
||||
result: string;
|
||||
};
|
||||
owner: boolean;
|
||||
manager: boolean;
|
||||
analyst: boolean;
|
||||
fieldsEditable: boolean;
|
||||
states: Record<string, string>;
|
||||
transitions: string[];
|
||||
findings: {
|
||||
code: string;
|
||||
explanation: string;
|
||||
recommendation: string;
|
||||
severity: string;
|
||||
}[];
|
||||
messages: {
|
||||
id: string;
|
||||
body: string;
|
||||
name: string;
|
||||
kind: string;
|
||||
created_at: string;
|
||||
}[];
|
||||
analysts: { id: number; name: string }[];
|
||||
territories: { id: string; name: string }[];
|
||||
documents: DeskDocument[];
|
||||
payments: DeskPayment[];
|
||||
caseVersion: number;
|
||||
events: {
|
||||
id: string;
|
||||
action: string;
|
||||
name: string;
|
||||
created_at: string;
|
||||
payload: Record<string, unknown>;
|
||||
}[];
|
||||
}) {
|
||||
const form = useForm({
|
||||
version: request.version,
|
||||
payload: request.payload,
|
||||
consent: false,
|
||||
reason: '',
|
||||
submit: false,
|
||||
});
|
||||
const decision = useForm({
|
||||
version: request.version,
|
||||
status: transitions[0] ?? '',
|
||||
reason: '',
|
||||
editable_fields: [] as string[],
|
||||
});
|
||||
const assignment = useForm({
|
||||
version: request.version,
|
||||
analyst_id: String(request.analyst_id ?? ''),
|
||||
reason: '',
|
||||
due_at: '',
|
||||
});
|
||||
const message = useForm({ body: '', client_key: crypto.randomUUID() });
|
||||
const canEdit = owner && fieldsEditable;
|
||||
return (
|
||||
<Frame title={definition.title}>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/balcao-virtual/dossiers/${dossier.id}`}
|
||||
>
|
||||
Voltar ao dossier {dossier.title}
|
||||
</Link>
|
||||
<p>{definition.result}</p>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-bold">
|
||||
{request.protocol
|
||||
? 'Pedido submetido pelo investidor'
|
||||
: 'Rascunho — ainda não submetido'}
|
||||
</h2>
|
||||
<p>
|
||||
{states[request.status]} · Protocolo:{' '}
|
||||
{request.protocol ?? 'Ainda sem protocolo'}
|
||||
</p>
|
||||
<p>
|
||||
Responsável real:{' '}
|
||||
{request.analyst_id ?? 'A aguardar atribuição'} · Prazo
|
||||
interno: {request.due_at ?? 'Não definido'}
|
||||
</p>
|
||||
{request.protocol && (
|
||||
<a
|
||||
className="underline"
|
||||
href={`/balcao-virtual/pedidos/${request.id}/recibo`}
|
||||
>
|
||||
Descarregar recibo interno e snapshot
|
||||
</a>
|
||||
)}
|
||||
</section>
|
||||
<section className={card + ' space-y-3'}>
|
||||
<h2 className="text-xl font-bold">
|
||||
Verificações automáticas de preparação
|
||||
</h2>
|
||||
{findings.map((f) => (
|
||||
<p key={f.code}>
|
||||
{f.explanation} {f.recommendation} (
|
||||
{f.severity === 'error'
|
||||
? 'Contradição nos valores declarados'
|
||||
: 'Informação / evidência pendente'}
|
||||
)
|
||||
</p>
|
||||
))}
|
||||
<p>
|
||||
A análise automática não é uma resposta do responsável nem
|
||||
uma aprovação oficial.
|
||||
</p>
|
||||
</section>
|
||||
<form
|
||||
className={card + ' space-y-3'}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
form.transform((d) => ({
|
||||
...d,
|
||||
version: request.version,
|
||||
submit: false,
|
||||
}));
|
||||
form.put(`/balcao-virtual/pedidos/${request.id}`);
|
||||
}}
|
||||
>
|
||||
{Object.entries(definition.fields)
|
||||
.filter(
|
||||
([, f]) =>
|
||||
!f.when ||
|
||||
form.data.payload[f.when.field] === f.when.equals,
|
||||
)
|
||||
.map(([key, f]) => (
|
||||
<label className="block" key={key}>
|
||||
{f.label}
|
||||
{f.required ? ' *' : ''}
|
||||
{f.type === 'select' || f.type === 'territory' ? (
|
||||
<select
|
||||
className={input}
|
||||
disabled={
|
||||
!canEdit ||
|
||||
(request.status === 'returned' &&
|
||||
!request.editable_fields.includes(
|
||||
key,
|
||||
))
|
||||
}
|
||||
value={form.data.payload[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
form.setData('payload', {
|
||||
...form.data.payload,
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">Por preencher</option>
|
||||
{(f.type === 'territory'
|
||||
? territories.map((t) => [t.id, t.name])
|
||||
: Object.entries(f.options ?? {})
|
||||
).map(([v, l]) => (
|
||||
<option key={v} value={v}>
|
||||
{l}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : f.type === 'textarea' ? (
|
||||
<textarea
|
||||
className={input}
|
||||
disabled={
|
||||
!canEdit ||
|
||||
(request.status === 'returned' &&
|
||||
!request.editable_fields.includes(
|
||||
key,
|
||||
))
|
||||
}
|
||||
value={form.data.payload[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
form.setData('payload', {
|
||||
...form.data.payload,
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
type={
|
||||
f.type === 'date'
|
||||
? 'date'
|
||||
: f.type === 'number'
|
||||
? 'number'
|
||||
: 'text'
|
||||
}
|
||||
step={
|
||||
f.type === 'number' ? '0.01' : undefined
|
||||
}
|
||||
className={input}
|
||||
disabled={
|
||||
!canEdit ||
|
||||
(request.status === 'returned' &&
|
||||
!request.editable_fields.includes(
|
||||
key,
|
||||
))
|
||||
}
|
||||
value={form.data.payload[key] ?? ''}
|
||||
onChange={(e) =>
|
||||
form.setData('payload', {
|
||||
...form.data.payload,
|
||||
[key]: e.target.value,
|
||||
})
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</label>
|
||||
))}
|
||||
{canEdit && (
|
||||
<>
|
||||
<label>
|
||||
Justificação de correcção
|
||||
<textarea
|
||||
className={input}
|
||||
value={form.data.reason}
|
||||
onChange={(e) =>
|
||||
form.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar rascunho
|
||||
</button>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.consent}
|
||||
onChange={(e) =>
|
||||
form.setData('consent', e.target.checked)
|
||||
}
|
||||
/>
|
||||
Revi o conteúdo e autorizo a submissão para análise
|
||||
interna.
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={form.processing || !form.data.consent}
|
||||
onClick={() => {
|
||||
form.transform((d) => ({
|
||||
...d,
|
||||
version: request.version,
|
||||
submit: true,
|
||||
}));
|
||||
form.put(
|
||||
`/balcao-virtual/pedidos/${request.id}`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
Submeter este pedido
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{Object.entries(form.errors).map(([k, v]) => (
|
||||
<p key={k} role="alert">
|
||||
{v}
|
||||
</p>
|
||||
))}
|
||||
</form>
|
||||
{!owner && (manager || analyst) && transitions.length > 0 && (
|
||||
<form
|
||||
className={card + ' space-y-3'}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
decision.transform((d) => ({
|
||||
...d,
|
||||
version: request.version,
|
||||
}));
|
||||
decision.post(
|
||||
`/balcao-virtual/pedidos/${request.id}/estado`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<h2 className="text-xl font-bold">
|
||||
Resposta / análise do responsável
|
||||
</h2>
|
||||
<label>
|
||||
Estado
|
||||
<select
|
||||
className={input}
|
||||
value={decision.data.status}
|
||||
onChange={(e) =>
|
||||
decision.setData('status', e.target.value)
|
||||
}
|
||||
>
|
||||
{transitions
|
||||
.filter(
|
||||
(s) =>
|
||||
manager ||
|
||||
![
|
||||
'accepted',
|
||||
'rejected',
|
||||
'closed',
|
||||
].includes(s),
|
||||
)
|
||||
.map((s) => (
|
||||
<option value={s} key={s}>
|
||||
{states[s]}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Fundamento da resposta
|
||||
<textarea
|
||||
className={input}
|
||||
required
|
||||
minLength={3}
|
||||
value={decision.data.reason}
|
||||
onChange={(e) =>
|
||||
decision.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
{decision.data.status === 'returned' && (
|
||||
<fieldset>
|
||||
<legend>Campos autorizados para correcção</legend>
|
||||
{Object.entries(definition.fields).map(([k, f]) => (
|
||||
<label className="block" key={k}>
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={decision.data.editable_fields.includes(
|
||||
k,
|
||||
)}
|
||||
onChange={(e) =>
|
||||
decision.setData(
|
||||
'editable_fields',
|
||||
e.target.checked
|
||||
? [
|
||||
...decision.data
|
||||
.editable_fields,
|
||||
k,
|
||||
]
|
||||
: decision.data.editable_fields.filter(
|
||||
(v) => v !== k,
|
||||
),
|
||||
)
|
||||
}
|
||||
/>{' '}
|
||||
{f.label}
|
||||
</label>
|
||||
))}
|
||||
</fieldset>
|
||||
)}
|
||||
<button className={button} disabled={decision.processing}>
|
||||
Registar resposta fundamentada
|
||||
</button>
|
||||
{Object.entries(decision.errors).map(([k, v]) => (
|
||||
<p role="alert" key={k}>
|
||||
{v}
|
||||
</p>
|
||||
))}
|
||||
</form>
|
||||
)}
|
||||
{manager &&
|
||||
!['draft', 'closed', 'cancelled'].includes(request.status) && (
|
||||
<form
|
||||
className={card + ' space-y-3'}
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
assignment.transform((d) => ({
|
||||
...d,
|
||||
version: request.version,
|
||||
}));
|
||||
assignment.post(
|
||||
`/balcao-virtual/pedidos/${request.id}/responsavel`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
<h2 className="text-xl font-bold">
|
||||
Atribuir responsável existente
|
||||
</h2>
|
||||
<label>
|
||||
Responsável
|
||||
<select
|
||||
className={input}
|
||||
required
|
||||
value={assignment.data.analyst_id}
|
||||
onChange={(e) =>
|
||||
assignment.setData(
|
||||
'analyst_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione</option>
|
||||
{analysts.map((a) => (
|
||||
<option key={a.id} value={a.id}>
|
||||
{a.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
Prazo interno
|
||||
<input
|
||||
className={input}
|
||||
type="datetime-local"
|
||||
value={assignment.data.due_at}
|
||||
onChange={(e) =>
|
||||
assignment.setData('due_at', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
Motivo
|
||||
<textarea
|
||||
className={input}
|
||||
required
|
||||
value={assignment.data.reason}
|
||||
onChange={(e) =>
|
||||
assignment.setData('reason', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className={button}
|
||||
disabled={assignment.processing}
|
||||
>
|
||||
Atribuir acompanhamento
|
||||
</button>
|
||||
{Object.entries(assignment.errors).map(([k, v]) => (
|
||||
<p role="alert" key={k}>
|
||||
{v}
|
||||
</p>
|
||||
))}
|
||||
</form>
|
||||
)}
|
||||
<section className={card + ' space-y-3'}>
|
||||
<h2 className="text-xl font-bold">
|
||||
Conversa do pedido existente
|
||||
</h2>
|
||||
{messages.map((m) => (
|
||||
<article key={m.id} className="rounded border p-3">
|
||||
<p>
|
||||
{m.kind === 'responsible_response'
|
||||
? 'Resposta de responsável'
|
||||
: m.kind === 'investor_message'
|
||||
? 'Mensagem do investidor'
|
||||
: 'Mensagem histórica — tipo original não registado'}{' '}
|
||||
— {m.name} · {m.created_at}
|
||||
</p>
|
||||
<p className="break-words whitespace-pre-wrap">
|
||||
{m.body}
|
||||
</p>
|
||||
</article>
|
||||
))}
|
||||
{!['closed', 'cancelled'].includes(request.status) && (
|
||||
<form
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
message.post(
|
||||
`/balcao-virtual/pedidos/${request.id}/mensagens`,
|
||||
{
|
||||
onSuccess: () => {
|
||||
message.reset('body');
|
||||
message.setData(
|
||||
'client_key',
|
||||
crypto.randomUUID(),
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
}}
|
||||
>
|
||||
<label>
|
||||
Mensagem privada
|
||||
<textarea
|
||||
className={input}
|
||||
value={message.data.body}
|
||||
required
|
||||
onChange={(e) =>
|
||||
message.setData('body', e.target.value)
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
className={button}
|
||||
disabled={message.processing}
|
||||
>
|
||||
Enviar esta mensagem no pedido
|
||||
</button>
|
||||
{Object.entries(message.errors).map(([k, v]) => (
|
||||
<p role="alert" key={k}>
|
||||
{v}
|
||||
</p>
|
||||
))}
|
||||
</form>
|
||||
)}
|
||||
</section>
|
||||
{!owner && (manager || analyst) && (
|
||||
<DocumentReview
|
||||
caseId={dossier.id}
|
||||
version={caseVersion}
|
||||
documents={documents}
|
||||
requestId={request.id}
|
||||
/>
|
||||
)}
|
||||
{!['closed', 'cancelled'].includes(request.status) && (
|
||||
<RequestOperations
|
||||
requestId={request.id}
|
||||
owner={owner}
|
||||
reviewer={!owner && (manager || analyst)}
|
||||
documents={documents}
|
||||
payments={payments}
|
||||
/>
|
||||
)}
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-bold">Respostas e histórico</h2>
|
||||
{events.map((e) => (
|
||||
<article className="mt-3 border-t pt-3" key={e.id}>
|
||||
<p>
|
||||
{e.action} · {e.name} · {e.created_at}
|
||||
</p>
|
||||
{typeof e.payload.reason === 'string' && (
|
||||
<p>{e.payload.reason}</p>
|
||||
)}
|
||||
{[
|
||||
'document_reviewed',
|
||||
'payment_reviewed',
|
||||
'manual_communication_recorded',
|
||||
].includes(e.action) && (
|
||||
<pre className="text-xs break-all whitespace-pre-wrap">
|
||||
{JSON.stringify(e.payload, null, 2)}
|
||||
</pre>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user