1418 lines
74 KiB
TypeScript
1418 lines
74 KiB
TypeScript
import { useEffect, useRef, useState } from 'react';
|
|
import { Link, router } from '@inertiajs/react';
|
|
import { Frame, card, input, button } from '@/pages/investment/shared';
|
|
import { profileJson, ProfileValidationError } from '@/lib/profile-json';
|
|
import { createOperationKey } from '@/lib/operation-key';
|
|
import {
|
|
PreparationAttempt,
|
|
swotDimensions,
|
|
type SwotRow,
|
|
type Workspace,
|
|
} from '@/lib/investment-preparation';
|
|
|
|
const apiStates: Record<string, string> = {
|
|
preparing: 'Em preparação',
|
|
ready: 'Pronto para entrega',
|
|
delivery_recorded: 'Entrega registada',
|
|
decision_received: 'Decisão recebida',
|
|
};
|
|
const externalKinds: Record<string, string> = {
|
|
delivery: 'Entrega externa',
|
|
clarification: 'Pedido de esclarecimento',
|
|
response: 'Resposta ao esclarecimento',
|
|
decision: 'Decisão recebida',
|
|
};
|
|
export default function Preparation({ workspace }: { workspace: Workspace }) {
|
|
return (
|
|
<PreparationEditor
|
|
key={workspace.case.id + ':' + (workspace.opportunity ?? 'dossier')}
|
|
initial={workspace}
|
|
/>
|
|
);
|
|
}
|
|
function PreparationEditor({ initial }: { initial: Workspace }) {
|
|
const [view, setView] = useState(initial),
|
|
[tab, setTab] = useState<'apiex' | 'swot'>('apiex');
|
|
const [swot, setSwot] = useState({
|
|
...initial.swot,
|
|
object_key: initial.swot.object_key || 'investment:' + initial.case.id,
|
|
source_fingerprint:
|
|
initial.swot.source_fingerprint || initial.swot_fingerprint,
|
|
});
|
|
const [note, setNote] = useState(initial.apiex.note ?? ''),
|
|
[additional, setAdditional] = useState(
|
|
initial.apiex.additional_documents,
|
|
);
|
|
const [reason, setReason] = useState(''),
|
|
[busy, setBusy] = useState(false),
|
|
[error, setError] = useState(''),
|
|
[notice, setNotice] = useState(''),
|
|
[pending, setPending] = useState(false),
|
|
[recovery, setRecovery] = useState<Workspace | null>(null);
|
|
const [apiDirty, setApiDirty] = useState(false),
|
|
[swotDirty, setSwotDirty] = useState(false);
|
|
const dirty = tab === 'apiex' ? apiDirty : swotDirty;
|
|
function setDirty(value: boolean) {
|
|
if (tab === 'apiex') setApiDirty(value);
|
|
else setSwotDirty(value);
|
|
}
|
|
const [external, setExternal] = useState({
|
|
kind: 'delivery',
|
|
date: '',
|
|
reference: '',
|
|
proof_document: '',
|
|
export_id: '',
|
|
related_id: '',
|
|
outcome: '',
|
|
});
|
|
const [action, setAction] = useState({
|
|
conclusion_id: '',
|
|
kind: 'risk',
|
|
title: '',
|
|
});
|
|
const attempt = useRef(new PreparationAttempt()),
|
|
running = useRef(false);
|
|
const base = '/investimentos/' + view.case.id + '/preparacao',
|
|
query = view.initial_scope
|
|
? '?history_scope=dossier'
|
|
: view.opportunity
|
|
? '?opportunity=' + encodeURIComponent(view.opportunity)
|
|
: '';
|
|
useEffect(() => {
|
|
const unsaved = apiDirty || swotDirty || pending || busy;
|
|
if (!unsaved) return;
|
|
const leave = (event: BeforeUnloadEvent) => {
|
|
event.preventDefault();
|
|
event.returnValue = '';
|
|
};
|
|
window.addEventListener('beforeunload', leave);
|
|
const off = router.on('before', (event) => {
|
|
if (
|
|
!window.confirm(
|
|
'Existem campos locais ou uma confirmação pendente. Sair sem os guardar?',
|
|
)
|
|
)
|
|
event.preventDefault();
|
|
});
|
|
return () => {
|
|
window.removeEventListener('beforeunload', leave);
|
|
off();
|
|
};
|
|
}, [apiDirty, swotDirty, pending, busy]);
|
|
function download(id: string) {
|
|
const a = document.createElement('a');
|
|
a.href = base + '/exportar/' + encodeURIComponent(id) + query;
|
|
a.download = '';
|
|
a.click();
|
|
}
|
|
async function send(body: Record<string, unknown>) {
|
|
if (running.current) return;
|
|
running.current = true;
|
|
setBusy(true);
|
|
setError('');
|
|
try {
|
|
const next = (await profileJson(base, body)) as Workspace;
|
|
setView(next);
|
|
attempt.current.complete();
|
|
setPending(false);
|
|
setRecovery(null);
|
|
if (body.action === 'swot_save' || body.action === 'swot_restore') {
|
|
setSwot({
|
|
...next.swot,
|
|
source_fingerprint:
|
|
next.swot.source_fingerprint || next.swot_fingerprint,
|
|
});
|
|
setSwotDirty(false);
|
|
}
|
|
if (body.action === 'swot_review')
|
|
setSwot((old) => ({
|
|
...old,
|
|
source_fingerprint: next.swot.source_fingerprint,
|
|
}));
|
|
if (body.action === 'apiex_save') setApiDirty(false);
|
|
if (body.action === 'external')
|
|
setExternal((old) => ({
|
|
...old,
|
|
date: '',
|
|
reference: '',
|
|
proof_document: '',
|
|
related_id: '',
|
|
outcome: '',
|
|
}));
|
|
if (body.action === 'apiex_export') {
|
|
download(String(body.operation_key));
|
|
setExternal((old) => ({
|
|
...old,
|
|
export_id: String(body.operation_key),
|
|
}));
|
|
setNotice(
|
|
'Pacote preparado para descarga. Exportar não submete nem regista entrega externa.',
|
|
);
|
|
} else
|
|
setNotice(
|
|
'Versão ' +
|
|
next.version +
|
|
' guardada. Dados e histórico anteriores preservados.',
|
|
);
|
|
} catch (e) {
|
|
setError(
|
|
e instanceof Error
|
|
? e.message
|
|
: 'Não foi possível confirmar a gravação.',
|
|
);
|
|
setPending(true);
|
|
if (
|
|
e instanceof ProfileValidationError &&
|
|
(e.status === null || (e.status >= 400 && e.status < 500 && e.status !== 408))
|
|
) {
|
|
attempt.current.complete();
|
|
setPending(false);
|
|
setError(e.message + ' ' + Object.values(e.fields).join(' '));
|
|
}
|
|
} finally {
|
|
running.current = false;
|
|
setBusy(false);
|
|
}
|
|
}
|
|
function act(kind: string, data: Record<string, unknown> = {}) {
|
|
if (running.current || pending) return;
|
|
void send(
|
|
attempt.current.start(
|
|
view.version,
|
|
view.opportunity,
|
|
kind,
|
|
data,
|
|
reason.trim() ||
|
|
'Operador confere e guarda esta versão do dossier',
|
|
),
|
|
);
|
|
}
|
|
async function consult() {
|
|
if (running.current) return;
|
|
running.current = true;
|
|
setBusy(true);
|
|
try {
|
|
setRecovery(
|
|
(await profileJson(base + query, {}, 'GET')) as Workspace,
|
|
);
|
|
} catch (e) {
|
|
setError(e instanceof Error ? e.message : 'Consulta indisponível');
|
|
} finally {
|
|
running.current = false;
|
|
setBusy(false);
|
|
}
|
|
}
|
|
function adopt() {
|
|
if (!recovery || !attempt.current.canAdopt(recovery)) return;
|
|
setView(recovery);
|
|
setSwot({
|
|
...recovery.swot,
|
|
object_key:
|
|
recovery.swot.object_key || 'investment:' + view.case.id,
|
|
source_fingerprint:
|
|
recovery.swot.source_fingerprint || recovery.swot_fingerprint,
|
|
});
|
|
setNote(recovery.apiex.note ?? '');
|
|
setAdditional(recovery.apiex.additional_documents);
|
|
attempt.current.complete();
|
|
setPending(false);
|
|
setApiDirty(false);
|
|
setSwotDirty(false);
|
|
setRecovery(null);
|
|
}
|
|
async function olderHistory() {
|
|
if (running.current || busy || !view.history_next) return;
|
|
running.current = true;
|
|
setBusy(true);
|
|
try {
|
|
const next = (await profileJson(
|
|
base +
|
|
query +
|
|
(query ? '&' : '?') +
|
|
'history_before=' +
|
|
view.history_next,
|
|
{},
|
|
'GET',
|
|
)) as Workspace;
|
|
setView((old) => ({
|
|
...old,
|
|
history: [
|
|
...new Map(
|
|
[...old.history, ...next.history].map((h) => [
|
|
h.version,
|
|
h,
|
|
]),
|
|
).values(),
|
|
],
|
|
history_next: next.history_next,
|
|
}));
|
|
} catch (e) {
|
|
setError(
|
|
e instanceof Error
|
|
? e.message
|
|
: 'Não foi possível consultar o histórico.',
|
|
);
|
|
} finally {
|
|
running.current = false;
|
|
setBusy(false);
|
|
}
|
|
}
|
|
function keepLocal() {
|
|
if (!recovery || !attempt.current.canAdopt(recovery)) return;
|
|
setView(recovery);
|
|
setApiDirty(true);
|
|
setSwotDirty(true);
|
|
attempt.current.complete();
|
|
setPending(false);
|
|
setRecovery(null);
|
|
setNotice(
|
|
'Campos locais mantidos; fontes e versão do servidor actualizadas. Compare,guarde e reveja antes de avançar.',
|
|
);
|
|
}
|
|
const change = (id: string, patch: Partial<SwotRow>) => {
|
|
setSwot((old) => ({
|
|
...old,
|
|
rows: old.rows.map((r) => (r.id === id ? { ...r, ...patch } : r)),
|
|
}));
|
|
setDirty(true);
|
|
};
|
|
const exportId =
|
|
external.export_id ||
|
|
(view.apiex.exports.length === 1 ? view.apiex.exports[0].id : '');
|
|
const locked = busy || pending;
|
|
return (
|
|
<Frame title="Preparação APIEX e análise SWOT">
|
|
<div className="space-y-5" aria-busy={busy}>
|
|
<p>
|
|
{view.case.title} · Oportunidade:{' '}
|
|
{view.opportunity_label ?? 'contexto único do dossier'} · Versão{' '}
|
|
{view.version}
|
|
</p>
|
|
<Link className="underline" href={view.links.dossier}>
|
|
Voltar ao mesmo dossier
|
|
</Link>
|
|
{view.historical && (
|
|
<p role="status">
|
|
Oportunidade retirada das escolhas actuais. Consulta
|
|
histórica preservada; não são alteradas as escolhas nem
|
|
os dados actuais do dossier.
|
|
</p>
|
|
)}
|
|
<p>
|
|
Preparação privada. Não há ligação de recepção electrónica
|
|
APIEX. Exportação, entrega externa e decisão são registos
|
|
distintos. A SWOT apoia a decisão; não produz pontuação
|
|
automática.
|
|
</p>
|
|
<div className="flex flex-wrap gap-3">
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
onClick={() => setTab('apiex')}
|
|
aria-pressed={tab === 'apiex'}
|
|
>
|
|
Documentos APIEX
|
|
</button>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
onClick={() => setTab('swot')}
|
|
aria-pressed={tab === 'swot'}
|
|
>
|
|
Análise SWOT
|
|
</button>
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={busy}
|
|
onClick={() => void consult()}
|
|
>
|
|
Consultar versão do servidor
|
|
</button>
|
|
</div>
|
|
{error && (
|
|
<p role="alert">
|
|
{error} Os campos locais foram conservados.
|
|
</p>
|
|
)}
|
|
{notice && <p role="status">{notice}</p>}
|
|
{pending && (
|
|
<div className={card}>
|
|
<p>
|
|
A confirmação está pendente. Repetir conserva
|
|
exactamente a mesma tentativa,sem duplicar o
|
|
registo.
|
|
</p>
|
|
<button
|
|
disabled={busy}
|
|
className={button}
|
|
type="button"
|
|
onClick={() => {
|
|
const body = attempt.current.current();
|
|
if (body) void send(body);
|
|
}}
|
|
>
|
|
Repetir a mesma tentativa
|
|
</button>
|
|
</div>
|
|
)}
|
|
{recovery && (
|
|
<section className={card}>
|
|
<h2>Versão do servidor: {recovery.version}</h2>
|
|
<p>
|
|
Consultar não substitui os campos locais. Compare
|
|
antes de recuperar.
|
|
</p>
|
|
<pre className="max-h-60 overflow-auto whitespace-pre-wrap">
|
|
{JSON.stringify(
|
|
{ apiex: recovery.apiex, swot: recovery.swot },
|
|
null,
|
|
2,
|
|
)}
|
|
</pre>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
busy || !attempt.current.canAdopt(recovery)
|
|
}
|
|
onClick={adopt}
|
|
>
|
|
Usar esta versão nos campos locais
|
|
</button>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
busy || !attempt.current.canAdopt(recovery)
|
|
}
|
|
onClick={keepLocal}
|
|
>
|
|
Manter os meus campos e usar esta versão como base
|
|
para nova revisão
|
|
</button>
|
|
</section>
|
|
)}
|
|
<fieldset disabled={locked} className="min-w-0 space-y-4">
|
|
<label className="block">
|
|
Nota de conferência (opcional)
|
|
<input
|
|
className={input}
|
|
value={reason}
|
|
onChange={(e) => setReason(e.target.value)}
|
|
/>
|
|
</label>
|
|
{tab === 'apiex' ? (
|
|
<>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
1. Requisitos — {apiStates[view.api_state]}
|
|
</h2>
|
|
<Link
|
|
className="underline"
|
|
href={view.links.context}
|
|
>
|
|
Alterar dados e enquadramento reutilizados
|
|
</Link>
|
|
<p>
|
|
Dados do investidor,empresa,oportunidade e
|
|
localização provêm do contexto autorizado.
|
|
Não é formulário oficial nem aprovação.
|
|
</p>
|
|
<details>
|
|
<summary>
|
|
Resumo dos dados reutilizados —
|
|
consultar
|
|
</summary>
|
|
<pre className="overflow-auto whitespace-pre-wrap">
|
|
{JSON.stringify(
|
|
view.context.fields,
|
|
null,
|
|
2,
|
|
)}
|
|
</pre>
|
|
</details>
|
|
<ul className="space-y-3">
|
|
{view.assessment.requirements.map((r) => (
|
|
<li key={r.key}>
|
|
<strong>{r.label}</strong>:{' '}
|
|
{r.state === 'not_applicable'
|
|
? 'Não aplicável'
|
|
: r.available
|
|
? 'Disponível'
|
|
: r.state === 'indeterminate'
|
|
? 'Por determinar'
|
|
: 'Em falta/indisponível'}
|
|
<p>
|
|
{r.reason} ·{' '}
|
|
<a
|
|
className="underline"
|
|
href={r.source.url}
|
|
>
|
|
{r.source.reference}
|
|
</a>
|
|
</p>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
{!!view.api_issues.length && (
|
|
<div role="status">
|
|
<h3>Falta completar ou conferir</h3>
|
|
<ul>
|
|
{view.api_issues.map((v, i) => (
|
|
<li key={i}>{v}</li>
|
|
))}
|
|
</ul>
|
|
</div>
|
|
)}
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
2. Documentos e modelos existentes
|
|
</h2>
|
|
<Link
|
|
className="underline"
|
|
href={view.links.documents}
|
|
>
|
|
Completar ou associar documentos no mesmo
|
|
dossier
|
|
</Link>{' '}
|
|
<Link
|
|
className="underline"
|
|
href={view.links.library}
|
|
>
|
|
Consultar modelos e documentos na biblioteca
|
|
deste contexto
|
|
</Link>
|
|
<p>
|
|
Os anexos exigidos são incluídos pela
|
|
associação existente. Escolha outros
|
|
modelos/documentos já disponíveis,sem criar
|
|
formulários oficiais.
|
|
</p>
|
|
<details>
|
|
<summary>
|
|
Anexos adicionais — consultar ou alterar
|
|
</summary>
|
|
{view.documents.map((d) => (
|
|
<label className="block" key={d.id}>
|
|
<input
|
|
disabled={!view.can_write}
|
|
type="checkbox"
|
|
checked={additional.includes(
|
|
d.document_id,
|
|
)}
|
|
onChange={(e) => {
|
|
setAdditional((old) =>
|
|
e.target.checked
|
|
? [
|
|
...old,
|
|
d.document_id,
|
|
]
|
|
: old.filter(
|
|
(id) =>
|
|
id !==
|
|
d.document_id,
|
|
),
|
|
);
|
|
setDirty(true);
|
|
}}
|
|
/>
|
|
{d.file_name} · versão{d.version_no}{' '}
|
|
·{' '}
|
|
{d.available
|
|
? 'disponível'
|
|
: 'indisponível para exportação'}{' '}
|
|
·{' '}
|
|
<a
|
|
className="underline"
|
|
href={
|
|
'/balcao-virtual/dossiers/' +
|
|
view.case.id +
|
|
'/documentos/' +
|
|
d.id
|
|
}
|
|
>
|
|
Conferir
|
|
</a>
|
|
</label>
|
|
))}
|
|
</details>
|
|
<label className="block">
|
|
Nota para organizar a preparação
|
|
<textarea
|
|
readOnly={!view.can_write}
|
|
className={input}
|
|
value={note}
|
|
onChange={(e) => {
|
|
setNote(e.target.value);
|
|
setDirty(true);
|
|
}}
|
|
/>
|
|
</label>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={!view.can_write}
|
|
onClick={() =>
|
|
act('apiex_save', {
|
|
note,
|
|
additional_documents: additional,
|
|
})
|
|
}
|
|
>
|
|
Guardar preparação documental
|
|
</button>
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
3. Conferir,pré-visualizar e exportar
|
|
</h2>
|
|
<a
|
|
className="underline"
|
|
href={base + '/previa' + query}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Pré-visualizar índice e documentos
|
|
</a>
|
|
<p>
|
|
O pacote ZIP inclui índice,manifesto com
|
|
versões e anexos. Exportar não equivale a
|
|
submeter; entrega registada não é aprovação.
|
|
</p>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
!view.can_review ||
|
|
dirty ||
|
|
!!view.api_issues.length
|
|
}
|
|
onClick={() =>
|
|
act('apiex_review', {
|
|
fingerprint: view.api_fingerprint,
|
|
})
|
|
}
|
|
>
|
|
Conferi esta versão para entrega externa
|
|
</button>{' '}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
!view.can_write ||
|
|
dirty ||
|
|
!!view.api_issues.length ||
|
|
view.apiex.review?.fingerprint !==
|
|
view.api_fingerprint
|
|
}
|
|
onClick={() => act('apiex_export')}
|
|
>
|
|
Exportar dossier organizado
|
|
</button>
|
|
{!!view.apiex.exports.length && (
|
|
<details>
|
|
<summary>
|
|
Versões preparadas para exportação
|
|
</summary>
|
|
<ul>
|
|
{view.apiex.exports.map((x) => (
|
|
<li key={x.id}>
|
|
{x.at} · contexto
|
|
{x.context_revision} ·{' '}
|
|
<a
|
|
className="underline"
|
|
href={
|
|
base +
|
|
'/exportar/' +
|
|
x.id +
|
|
query
|
|
}
|
|
>
|
|
Descarregar esta versão,
|
|
se ainda actual
|
|
</a>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</details>
|
|
)}
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
4. Registar entrega e comunicações externas
|
|
</h2>
|
|
<p>
|
|
Registe apenas actos efectivamente
|
|
realizados e os comprovativos existentes.
|
|
Nenhum pedido é enviado à APIEX pelo portal.
|
|
</p>
|
|
<label className="block">
|
|
Tipo de registo
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={external.kind}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
kind: e.target.value,
|
|
related_id: '',
|
|
outcome: '',
|
|
}))
|
|
}
|
|
>
|
|
{Object.entries(externalKinds).map(
|
|
([key, label]) => (
|
|
<option key={key} value={key}>
|
|
{label}
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Versão exportada
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={exportId}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
export_id: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">Escolher</option>
|
|
{view.apiex.exports.map((x) => (
|
|
<option key={x.id} value={x.id}>
|
|
{x.at} · contexto
|
|
{x.context_revision}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Data efectiva
|
|
<input
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
type="date"
|
|
value={external.date}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
date: e.target.value,
|
|
}))
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="block">
|
|
Referência externa
|
|
<input
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={external.reference}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
reference: e.target.value,
|
|
}))
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="block">
|
|
Comprovativo/documento
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={external.proof_document}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
proof_document: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">
|
|
Escolher documento do dossier
|
|
</option>
|
|
{view.documents
|
|
.filter((d) => d.available)
|
|
.map((d) => (
|
|
<option
|
|
key={d.id}
|
|
value={d.document_id}
|
|
>
|
|
{d.file_name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
{external.kind === 'response' && (
|
|
<label className="block">
|
|
Pedido de esclarecimento respondido
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={external.related_id}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
related_id: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">Escolher</option>
|
|
{view.apiex.external
|
|
.filter(
|
|
(x) =>
|
|
x.kind ===
|
|
'clarification' &&
|
|
x.export_id ===
|
|
exportId,
|
|
)
|
|
.map((x) => (
|
|
<option
|
|
key={x.id}
|
|
value={x.id}
|
|
>
|
|
{x.reference} · {x.date}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
)}
|
|
{external.kind === 'decision' && (
|
|
<label className="block">
|
|
Decisão efectivamente recebida
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={external.outcome}
|
|
onChange={(e) =>
|
|
setExternal((old) => ({
|
|
...old,
|
|
outcome: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">Escolher</option>
|
|
<option value="approved">
|
|
Aprovação recebida
|
|
</option>
|
|
<option value="refused">
|
|
Recusa recebida
|
|
</option>
|
|
<option value="conditional">
|
|
Decisão condicionada
|
|
</option>
|
|
<option value="other">
|
|
Outra resposta decisória
|
|
</option>
|
|
</select>
|
|
</label>
|
|
)}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={!view.can_write || !exportId}
|
|
onClick={() =>
|
|
act('external', {
|
|
...external,
|
|
export_id: exportId,
|
|
outcome: external.outcome || null,
|
|
related_id:
|
|
external.related_id || null,
|
|
})
|
|
}
|
|
>
|
|
Registar acto externo comprovado
|
|
</button>
|
|
<ul>
|
|
{view.apiex.external.map((x) => (
|
|
<li key={x.id}>
|
|
{externalKinds[x.kind]} · {x.date} ·{' '}
|
|
{x.reference} · {x.outcome ?? ''}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</section>
|
|
</>
|
|
) : (
|
|
<>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
1. Objecto e âmbito da análise
|
|
</h2>
|
|
<p>
|
|
Forças e fraquezas são internas ao objecto;
|
|
oportunidades e ameaças são externas.
|
|
Ausência de registos não prova ausência de
|
|
oferta ou concorrência.
|
|
</p>
|
|
<label className="block">
|
|
Objecto
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={swot.object_key}
|
|
onChange={(e) => {
|
|
setSwot((old) => ({
|
|
...old,
|
|
object_key: e.target.value,
|
|
}));
|
|
setDirty(true);
|
|
}}
|
|
>
|
|
{view.objects.map((x) => (
|
|
<option key={x.key} value={x.key}>
|
|
{x.kind} · {x.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<Link
|
|
className="underline"
|
|
href={view.links.context}
|
|
>
|
|
Alterar território,sector,cluster ou
|
|
oportunidade no contexto existente
|
|
</Link>
|
|
<label className="block">
|
|
Âmbito e fronteiras do objecto
|
|
<textarea
|
|
readOnly={!view.can_write}
|
|
className={input}
|
|
value={swot.scope ?? ''}
|
|
onChange={(e) => {
|
|
setSwot((old) => ({
|
|
...old,
|
|
scope: e.target.value,
|
|
}));
|
|
setDirty(true);
|
|
}}
|
|
/>
|
|
</label>
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
2. Evidências reutilizáveis
|
|
</h2>
|
|
{view.swot.sources_snapshot !== undefined && (
|
|
<details>
|
|
<summary>
|
|
Fontes e contexto conservados na
|
|
análise guardada — comparar com os
|
|
actuais
|
|
</summary>
|
|
<pre className="max-h-64 overflow-auto whitespace-pre-wrap">
|
|
{JSON.stringify(
|
|
view.swot.sources_snapshot,
|
|
null,
|
|
2,
|
|
)}
|
|
</pre>
|
|
</details>
|
|
)}
|
|
<p>
|
|
Consulte as fontes sem converter
|
|
associações,proximidade ou lacunas em factos
|
|
económicos. Competitividade usa apenas a
|
|
versão pública aprovada.
|
|
</p>
|
|
{!view.sources.length && (
|
|
<p>
|
|
Não há evidências associadas neste
|
|
contexto. Identifique fontes documentais
|
|
ou informação por confirmar; não conclua
|
|
ausência de concorrência.
|
|
</p>
|
|
)}
|
|
{view.sources.map((s) => (
|
|
<details key={s.key}>
|
|
<summary>{s.label}</summary>
|
|
<p>{s.notice}</p>
|
|
<pre className="max-h-64 overflow-auto whitespace-pre-wrap">
|
|
{JSON.stringify(
|
|
{
|
|
consultado: s.consulted,
|
|
actual: s.current,
|
|
},
|
|
null,
|
|
2,
|
|
)}
|
|
</pre>
|
|
</details>
|
|
))}
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
3. Quatro dimensões
|
|
</h2>
|
|
{Object.entries(swotDimensions).map(
|
|
([dimension, label]) => (
|
|
<fieldset
|
|
className="my-3 space-y-3 rounded border p-3"
|
|
key={dimension}
|
|
>
|
|
<legend>{label}</legend>
|
|
{swot.rows
|
|
.filter(
|
|
(r) =>
|
|
r.dimension ===
|
|
dimension,
|
|
)
|
|
.map((r) => (
|
|
<div
|
|
className="space-y-2 rounded border p-3"
|
|
key={r.id}
|
|
>
|
|
<label className="block">
|
|
Conclusão
|
|
<textarea
|
|
readOnly={
|
|
!view.can_write
|
|
}
|
|
className={
|
|
input
|
|
}
|
|
value={
|
|
r.text ?? ''
|
|
}
|
|
onChange={(e) =>
|
|
change(
|
|
r.id,
|
|
{
|
|
text: e
|
|
.target
|
|
.value,
|
|
},
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="block">
|
|
Classificação
|
|
declarada
|
|
<select
|
|
disabled={
|
|
!view.can_write
|
|
}
|
|
className={
|
|
input
|
|
}
|
|
value={
|
|
r.classification
|
|
}
|
|
onChange={(e) =>
|
|
change(
|
|
r.id,
|
|
{
|
|
classification:
|
|
e
|
|
.target
|
|
.value as SwotRow['classification'],
|
|
},
|
|
)
|
|
}
|
|
>
|
|
<option value="documented_fact">
|
|
Facto
|
|
documentado
|
|
</option>
|
|
<option value="hypothesis">
|
|
Hipótese
|
|
</option>
|
|
<option value="unconfirmed">
|
|
Informação
|
|
por
|
|
confirmar
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Evidência existente
|
|
<select
|
|
disabled={
|
|
!view.can_write
|
|
}
|
|
className={
|
|
input
|
|
}
|
|
value={
|
|
r.source_key ??
|
|
''
|
|
}
|
|
onChange={(e) =>
|
|
change(
|
|
r.id,
|
|
{
|
|
source_key:
|
|
e
|
|
.target
|
|
.value ||
|
|
null,
|
|
},
|
|
)
|
|
}
|
|
>
|
|
<option value="">
|
|
Fonte
|
|
documental
|
|
identificada
|
|
abaixo
|
|
</option>
|
|
{view.sources.map(
|
|
(s) => (
|
|
<option
|
|
key={
|
|
s.key
|
|
}
|
|
value={
|
|
s.key
|
|
}
|
|
>
|
|
{
|
|
s.label
|
|
}
|
|
</option>
|
|
),
|
|
)}
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Fonte,página/referência
|
|
e fundamento
|
|
<textarea
|
|
readOnly={
|
|
!view.can_write
|
|
}
|
|
className={
|
|
input
|
|
}
|
|
value={
|
|
r.reference ??
|
|
''
|
|
}
|
|
onChange={(e) =>
|
|
change(
|
|
r.id,
|
|
{
|
|
reference:
|
|
e
|
|
.target
|
|
.value,
|
|
},
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<label className="block">
|
|
Data da
|
|
fonte/conclusão
|
|
<input
|
|
disabled={
|
|
!view.can_write
|
|
}
|
|
className={
|
|
input
|
|
}
|
|
type="date"
|
|
value={
|
|
r.date ?? ''
|
|
}
|
|
onChange={(e) =>
|
|
change(
|
|
r.id,
|
|
{
|
|
date:
|
|
e
|
|
.target
|
|
.value ||
|
|
null,
|
|
},
|
|
)
|
|
}
|
|
/>
|
|
</label>
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={
|
|
!view.can_write
|
|
}
|
|
onClick={() => {
|
|
setSwot(
|
|
(old) => ({
|
|
...old,
|
|
rows: old.rows.filter(
|
|
(
|
|
x,
|
|
) =>
|
|
x.id !==
|
|
r.id,
|
|
),
|
|
}),
|
|
);
|
|
setDirty(true);
|
|
}}
|
|
>
|
|
Retirar esta
|
|
conclusão do
|
|
rascunho
|
|
</button>
|
|
</div>
|
|
))}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={!view.can_write}
|
|
onClick={() => {
|
|
setSwot((old) => ({
|
|
...old,
|
|
rows: [
|
|
...old.rows,
|
|
{
|
|
id: createOperationKey(),
|
|
dimension:
|
|
dimension as SwotRow['dimension'],
|
|
text: '',
|
|
reference: '',
|
|
source_key:
|
|
null,
|
|
date: null,
|
|
classification:
|
|
'unconfirmed',
|
|
},
|
|
],
|
|
}));
|
|
setDirty(true);
|
|
}}
|
|
>
|
|
Acrescentar{' '}
|
|
{label
|
|
.split(' — ')[0]
|
|
.toLowerCase()}
|
|
</button>
|
|
</fieldset>
|
|
),
|
|
)}
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
4. Guardar e rever com a equipa
|
|
</h2>
|
|
{view.swot_review_required && (
|
|
<p role="status">
|
|
Revisão necessária. Alterações nas
|
|
fontes não substituem as conclusões
|
|
guardadas.
|
|
</p>
|
|
)}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={!view.can_write}
|
|
onClick={() =>
|
|
act('swot_save', {
|
|
draft: {
|
|
object_key: swot.object_key,
|
|
scope: swot.scope,
|
|
rows: swot.rows,
|
|
source_fingerprint:
|
|
swot.source_fingerprint,
|
|
},
|
|
})
|
|
}
|
|
>
|
|
Guardar análise privada
|
|
</button>{' '}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={!view.can_review || dirty}
|
|
onClick={() =>
|
|
act('swot_review', {
|
|
fingerprint: view.swot_fingerprint,
|
|
})
|
|
}
|
|
>
|
|
Conferi objecto,quatro dimensões e fontes
|
|
desta versão
|
|
</button>
|
|
<p>
|
|
Revisão de apoio ao investimento,não
|
|
publicação. Para divulgação,use a gestão
|
|
editorial existente; nada é publicado
|
|
automaticamente.
|
|
</p>
|
|
<Link
|
|
className="underline"
|
|
href={view.links.editorial}
|
|
>
|
|
Continuar no fluxo editorial autorizado
|
|
</Link>
|
|
</section>
|
|
<section className={card}>
|
|
<h2 className="font-bold">
|
|
5. Ligar conclusão a uma acção no mesmo
|
|
dossier
|
|
</h2>
|
|
<label className="block">
|
|
Conclusão
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={action.conclusion_id}
|
|
onChange={(e) =>
|
|
setAction((old) => ({
|
|
...old,
|
|
conclusion_id: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="">Escolher</option>
|
|
{view.swot.rows.map((r) => (
|
|
<option key={r.id} value={r.id}>
|
|
{swotDimensions[r.dimension]} ·{' '}
|
|
{r.text.slice(0, 100)}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Acção
|
|
<select
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={action.kind}
|
|
onChange={(e) =>
|
|
setAction((old) => ({
|
|
...old,
|
|
kind: e.target.value,
|
|
}))
|
|
}
|
|
>
|
|
<option value="idea">
|
|
Explorar uma ideia
|
|
</option>
|
|
<option value="opportunity">
|
|
Preparar uma oportunidade
|
|
</option>
|
|
<option value="partners">
|
|
Procurar parceiros
|
|
</option>
|
|
<option value="risk">
|
|
Tratar um risco
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label className="block">
|
|
Próximo passo concreto
|
|
<input
|
|
disabled={!view.can_write}
|
|
className={input}
|
|
value={action.title}
|
|
onChange={(e) =>
|
|
setAction((old) => ({
|
|
...old,
|
|
title: e.target.value,
|
|
}))
|
|
}
|
|
/>
|
|
</label>
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
!view.can_write ||
|
|
dirty ||
|
|
view.swot_review_required
|
|
}
|
|
onClick={() => act('swot_action', action)}
|
|
>
|
|
Ligar acção a esta análise e dossier
|
|
</button>
|
|
<ul>
|
|
{view.swot.actions.map((a) => (
|
|
<li key={a.id}>
|
|
<Link
|
|
className="underline"
|
|
href={a.href}
|
|
>
|
|
{a.title}
|
|
</Link>{' '}
|
|
· revisão {a.review_version}
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</section>
|
|
</>
|
|
)}
|
|
</fieldset>
|
|
{!!view.saved_scopes?.length && (
|
|
<details className={card}>
|
|
<summary>
|
|
Preparações e históricos de outros âmbitos deste
|
|
dossier
|
|
</summary>
|
|
<ul>
|
|
{view.saved_scopes.map((s) => (
|
|
<li key={s.key}>
|
|
<Link className="underline" href={s.href}>
|
|
{s.label}
|
|
</Link>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</details>
|
|
)}
|
|
<details className={card}>
|
|
<summary>
|
|
Histórico de versões — consultar ou recuperar SWOT
|
|
</summary>
|
|
{view.history_next && (
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={busy}
|
|
onClick={() => void olderHistory()}
|
|
>
|
|
Consultar versões anteriores
|
|
</button>
|
|
)}
|
|
<p>
|
|
Recuperar cria uma nova versão privada por rever,sem
|
|
apagar registos de entrega ou acções já ligadas.
|
|
</p>
|
|
<ul>
|
|
{view.history.map((h) => (
|
|
<li key={h.version}>
|
|
Versão{h.version} · {h.action} · {h.at} ·{' '}
|
|
<button
|
|
className={button}
|
|
type="button"
|
|
disabled={
|
|
locked || !view.can_write || dirty
|
|
}
|
|
onClick={() =>
|
|
act('swot_restore', {
|
|
revision: h.version,
|
|
})
|
|
}
|
|
>
|
|
Recuperar SWOT desta versão como novo
|
|
rascunho
|
|
</button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</details>
|
|
</div>
|
|
</Frame>
|
|
);
|
|
}
|