Carteira 4.3: página para validar a relação de cada projecto integrado do PII com o âncora
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -0,0 +1,269 @@
|
||||
import { Link, router } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { Management, button, control } from './shared';
|
||||
import { api } from '@/pages/investment/shared';
|
||||
|
||||
type Item = {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
anchor_code: string | null;
|
||||
anchor_name: string | null;
|
||||
relation_literal: string;
|
||||
suggested_type: string | null;
|
||||
type: string | null;
|
||||
status: 'por_validar' | 'validada' | 'rejeitada';
|
||||
decided_by: string | null;
|
||||
decided_at: string | null;
|
||||
note: string | null;
|
||||
location_literal: string | null;
|
||||
cost_literal: string | null;
|
||||
currency_header_literal: string | null;
|
||||
source: string | null;
|
||||
possible_duplicate_of: string[];
|
||||
};
|
||||
|
||||
type Decision = 'validate' | 'reject' | 'reopen';
|
||||
|
||||
async function decide(
|
||||
ids: string[],
|
||||
decision: Decision,
|
||||
type: string | null,
|
||||
note: string,
|
||||
) {
|
||||
await api('/management/relacoes-pii', { ids, decision, type, note });
|
||||
router.reload();
|
||||
}
|
||||
|
||||
/** Carteira 4.3: how each integrated PII project relates to its anchor, decided by a person. Nothing is published here. */
|
||||
export default function PiiAnchorRelations({
|
||||
items,
|
||||
status,
|
||||
statuses,
|
||||
types,
|
||||
}: {
|
||||
items: Item[];
|
||||
status: string;
|
||||
statuses: Record<string, string>;
|
||||
types: Record<string, string>;
|
||||
}) {
|
||||
const groups = new Map<string, Item[]>();
|
||||
for (const item of items) {
|
||||
const key = `${item.anchor_code ?? '?'} — ${item.anchor_name ?? 'âncora por identificar'}`;
|
||||
groups.set(key, [...(groups.get(key) ?? []), item]);
|
||||
}
|
||||
return (
|
||||
<Management title="Relações dos projectos do PII com o âncora">
|
||||
<p>
|
||||
Os projectos integrados do PII 2026–2030 são investimentos
|
||||
planeados, internos e por confirmar com a entidade competente;
|
||||
não são oportunidades nem estão publicados. Aqui confirma como
|
||||
cada um se relaciona com o seu projecto âncora. O tipo sugerido
|
||||
vem do texto do relatório; pode aceitá-lo, escolher outro ou
|
||||
indicar que não há relação directa.
|
||||
</p>
|
||||
<nav className="my-3 flex flex-wrap gap-3" aria-label="Estado">
|
||||
{[...Object.entries(statuses), ['all', 'Todas']].map(
|
||||
([key, label]) => (
|
||||
<Link
|
||||
key={key}
|
||||
className={
|
||||
key === status ? 'font-bold' : 'underline'
|
||||
}
|
||||
href={`/management/relacoes-pii?status=${key}`}
|
||||
>
|
||||
{label}
|
||||
</Link>
|
||||
),
|
||||
)}
|
||||
</nav>
|
||||
{items.length === 0 ? (
|
||||
<p>Sem projectos neste estado.</p>
|
||||
) : (
|
||||
[...groups.entries()].map(([group, rows]) => (
|
||||
<Group
|
||||
key={group}
|
||||
title={group}
|
||||
rows={rows}
|
||||
types={types}
|
||||
/>
|
||||
))
|
||||
)}
|
||||
</Management>
|
||||
);
|
||||
}
|
||||
|
||||
function Group({
|
||||
title,
|
||||
rows,
|
||||
types,
|
||||
}: {
|
||||
title: string;
|
||||
rows: Item[];
|
||||
types: Record<string, string>;
|
||||
}) {
|
||||
const suggested = rows.filter(
|
||||
(row) => row.status === 'por_validar' && row.suggested_type,
|
||||
);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
return (
|
||||
<section className="mt-6" aria-label={title}>
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 className="text-lg font-semibold">
|
||||
{title} ({rows.length})
|
||||
</h2>
|
||||
{suggested.length > 1 && (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
setBusy(true);
|
||||
setError('');
|
||||
try {
|
||||
await decide(
|
||||
suggested.map((row) => row.id),
|
||||
'validate',
|
||||
null,
|
||||
'Tipo sugerido aceite para o grupo',
|
||||
);
|
||||
} catch (cause) {
|
||||
setError(
|
||||
cause instanceof Error
|
||||
? cause.message
|
||||
: 'Não foi possível guardar.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Aceitar as {suggested.length} sugestões
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
<ul className="mt-2 space-y-3">
|
||||
{rows.map((row) => (
|
||||
<Row key={row.id} item={row} types={types} />
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function Row({ item, types }: { item: Item; types: Record<string, string> }) {
|
||||
const [type, setType] = useState(item.type ?? item.suggested_type ?? '');
|
||||
const [note, setNote] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const act = async (decision: Decision) => {
|
||||
setBusy(true);
|
||||
setError('');
|
||||
try {
|
||||
await decide([item.id], decision, type || null, note);
|
||||
} catch (cause) {
|
||||
setError(
|
||||
cause instanceof Error
|
||||
? cause.message
|
||||
: 'Não foi possível guardar.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<li className="rounded border p-3">
|
||||
<p>
|
||||
<strong>{item.code}</strong> · {item.name}
|
||||
</p>
|
||||
<p className="text-sm">
|
||||
Relação no relatório: «{item.relation_literal || 'sem texto'}»
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs">
|
||||
{item.location_literal &&
|
||||
`Local na fonte: ${item.location_literal} · `}
|
||||
{item.cost_literal &&
|
||||
`Custo na fonte: ${item.cost_literal} (${item.currency_header_literal ?? 'moeda por indicar'}) · `}
|
||||
{item.source}
|
||||
</p>
|
||||
{item.possible_duplicate_of.length > 0 && (
|
||||
<p className="text-sm">
|
||||
Possível duplicado de:{' '}
|
||||
{item.possible_duplicate_of.join('; ')}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-sm">
|
||||
Estado:{' '}
|
||||
<strong>
|
||||
{item.status === 'validada'
|
||||
? `Validada — ${types[item.type ?? ''] ?? item.type}`
|
||||
: item.status === 'rejeitada'
|
||||
? 'Sem relação directa'
|
||||
: 'Por validar'}
|
||||
</strong>
|
||||
{item.decided_at &&
|
||||
` · ${item.decided_by ?? 'utilizador'} em ${new Date(item.decided_at).toLocaleString('pt-PT')}`}
|
||||
{item.note && ` · «${item.note}»`}
|
||||
</p>
|
||||
{item.status === 'por_validar' ? (
|
||||
<div className="mt-2 flex flex-wrap items-end gap-2">
|
||||
<label className="grid gap-1 text-sm">
|
||||
Tipo de relação
|
||||
<select
|
||||
className={control}
|
||||
value={type}
|
||||
onChange={(e) => setType(e.target.value)}
|
||||
>
|
||||
<option value="">Escolher…</option>
|
||||
{Object.entries(types).map(([key, label]) => (
|
||||
<option key={key} value={key}>
|
||||
{label}
|
||||
{key === item.suggested_type
|
||||
? ' (sugerido)'
|
||||
: ''}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
<label className="grid min-w-64 flex-1 gap-1 text-sm">
|
||||
Nota (opcional)
|
||||
<input
|
||||
className={control}
|
||||
value={note}
|
||||
maxLength={2000}
|
||||
onChange={(e) => setNote(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={busy || !type}
|
||||
onClick={() => act('validate')}
|
||||
>
|
||||
Validar
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={busy}
|
||||
onClick={() => act('reject')}
|
||||
>
|
||||
Sem relação directa
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
className={`${button} mt-2`}
|
||||
disabled={busy}
|
||||
onClick={() => act('reopen')}
|
||||
>
|
||||
Voltar a «por validar»
|
||||
</button>
|
||||
)}
|
||||
{error && <p role="alert">{error}</p>}
|
||||
</li>
|
||||
);
|
||||
}
|
||||
@@ -82,6 +82,9 @@ export function Management({
|
||||
<Link href="/management/ligacoes-carteira">
|
||||
Ligações da carteira
|
||||
</Link>
|
||||
<Link href="/management/relacoes-pii">
|
||||
Relações dos projectos do PII
|
||||
</Link>
|
||||
<Link href="/management/demography">Demografia INE</Link>
|
||||
<Link href="/management/crm/leads">CRM</Link>
|
||||
<Link href="/management/crm/investors">Investidores</Link>
|
||||
|
||||
Reference in New Issue
Block a user