feat: prioritise missing preparation documents and retain associations
This commit is contained in:
@@ -64,6 +64,23 @@ export function PreparationSummary({
|
||||
caseId?: string;
|
||||
}) {
|
||||
if (!data) return null;
|
||||
const missingDocuments = data.requirements.filter(
|
||||
(requirement) =>
|
||||
requirement.required && requirement.state === 'missing',
|
||||
).length;
|
||||
const associatedDocuments = data.requirements.filter(
|
||||
(requirement) =>
|
||||
requirement.required && requirement.state === 'associated',
|
||||
).length;
|
||||
const undeterminedDocuments = data.requirements.filter(
|
||||
(requirement) => requirement.state === 'indeterminate',
|
||||
).length;
|
||||
const continueWithDocuments =
|
||||
data.enabled &&
|
||||
data.period_covered &&
|
||||
data.scope_covered &&
|
||||
data.missing_fields.length === 0 &&
|
||||
missingDocuments > 0;
|
||||
return (
|
||||
<section
|
||||
id="private-investment-preparation"
|
||||
@@ -109,15 +126,32 @@ export function PreparationSummary({
|
||||
.
|
||||
</p>
|
||||
)}
|
||||
{missingDocuments > 0 && (
|
||||
<p>Documentos por associar: {missingDocuments}.</p>
|
||||
)}
|
||||
{associatedDocuments > 0 && (
|
||||
<p>
|
||||
Documentos associados: {associatedDocuments} —
|
||||
conteúdo por conferir.
|
||||
</p>
|
||||
)}
|
||||
{undeterminedDocuments > 0 && (
|
||||
<p>
|
||||
Exigências documentais por determinar:{' '}
|
||||
{undeterminedDocuments}.
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{caseId && (
|
||||
<p>
|
||||
<Link
|
||||
className="inline-block rounded border px-4 py-2 font-semibold"
|
||||
href={`/investimentos/${caseId}/contexto/editar#preparation-questions`}
|
||||
href={`/investimentos/${caseId}/contexto/editar#${continueWithDocuments ? 'preparation-documents' : 'preparation-questions'}`}
|
||||
>
|
||||
Preencher ou continuar o formulário
|
||||
{continueWithDocuments
|
||||
? 'Associar documentos do dossier'
|
||||
: 'Preencher ou continuar o formulário'}
|
||||
</Link>
|
||||
</p>
|
||||
)}
|
||||
@@ -336,6 +370,39 @@ export function PreparationEditor({
|
||||
data.mode !== 'authorization' ||
|
||||
data.missing_fields.includes(q.key)),
|
||||
);
|
||||
const renderDocument = (r: Preparation['requirements'][number]) => (
|
||||
<label className="grid gap-1" key={r.key}>
|
||||
{r.label}
|
||||
<select
|
||||
className={input}
|
||||
disabled={disabled}
|
||||
value={
|
||||
Object.hasOwn(links, r.key)
|
||||
? (links[r.key] ?? '')
|
||||
: (r.document_id ?? '')
|
||||
}
|
||||
onChange={(e) => onLink(r.key, e.target.value || null)}
|
||||
>
|
||||
<option value="">Por associar</option>
|
||||
{documents.map((doc) => (
|
||||
<option key={doc.document_id} value={doc.document_id}>
|
||||
{doc.file_name} ·{' '}
|
||||
{{
|
||||
quarantined: 'Em quarentena',
|
||||
active: 'Disponível',
|
||||
deleted: 'Removido',
|
||||
}[doc.status] ?? 'Estado por conferir'}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span>
|
||||
{r.reason}{' '}
|
||||
<a className="underline" href={r.source.url}>
|
||||
{r.source.reference}
|
||||
</a>
|
||||
</span>
|
||||
</label>
|
||||
);
|
||||
return (
|
||||
<section
|
||||
id="preparation-questions"
|
||||
@@ -385,53 +452,29 @@ export function PreparationEditor({
|
||||
substitui a análise do pedido.
|
||||
</p>
|
||||
{data.requirements
|
||||
.filter((r) => r.required)
|
||||
.map((r) => (
|
||||
<label className="grid gap-1" key={r.key}>
|
||||
{r.label}
|
||||
<select
|
||||
className={input}
|
||||
disabled={disabled}
|
||||
value={
|
||||
Object.hasOwn(links, r.key)
|
||||
? (links[r.key] ?? '')
|
||||
: (r.document_id ?? '')
|
||||
}
|
||||
onChange={(e) =>
|
||||
onLink(
|
||||
r.key,
|
||||
e.target.value || null,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Por associar</option>
|
||||
{documents.map((doc) => (
|
||||
<option
|
||||
key={doc.document_id}
|
||||
value={doc.document_id}
|
||||
>
|
||||
{doc.file_name} ·{' '}
|
||||
{{
|
||||
quarantined:
|
||||
'Em quarentena',
|
||||
active: 'Disponível',
|
||||
deleted: 'Removido',
|
||||
}[doc.status] ??
|
||||
'Estado por conferir'}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span>
|
||||
{r.reason}{' '}
|
||||
<a
|
||||
className="underline"
|
||||
href={r.source.url}
|
||||
>
|
||||
{r.source.reference}
|
||||
</a>
|
||||
</span>
|
||||
</label>
|
||||
))}
|
||||
.filter(
|
||||
(r) => r.required && r.state !== 'associated',
|
||||
)
|
||||
.map(renderDocument)}
|
||||
{data.requirements.some(
|
||||
(r) => r.required && r.state === 'associated',
|
||||
) && (
|
||||
<details>
|
||||
<summary>
|
||||
Documentos já associados — consultar ou
|
||||
alterar
|
||||
</summary>
|
||||
<div className="space-y-3">
|
||||
{data.requirements
|
||||
.filter(
|
||||
(r) =>
|
||||
r.required &&
|
||||
r.state === 'associated',
|
||||
)
|
||||
.map(renderDocument)}
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user