Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-15 18:56:39 +02:00
parent 1349789226
commit fb076c174f
117 changed files with 10380 additions and 1905 deletions
@@ -1,4 +1,4 @@
import { useState } from 'react';
import { useEffect, useRef, useState } from 'react';
import DemographicEvidence, {
type DemographicAnalysis,
} from './demographic-evidence';
@@ -8,10 +8,17 @@ export default function DemographicContext({
}: {
territoryId?: string | null;
}) {
if (!territoryId) return null;
// A change of territory resets this consultation, never the investor's dossier.
return <TerritoryDemography key={territoryId} territoryId={territoryId} />;
}
function TerritoryDemography({ territoryId }: { territoryId: string }) {
const [evidence, setEvidence] = useState<DemographicAnalysis | null>(null);
const [message, setMessage] = useState('');
const [busy, setBusy] = useState(false);
if (!territoryId) return null;
const pending = useRef<AbortController | null>(null);
useEffect(() => () => pending.current?.abort(), []);
return (
<details className="rounded border p-4">
<summary>Demografia na análise de viabilidade</summary>
@@ -26,20 +33,35 @@ export default function DemographicContext({
onClick={async () => {
setBusy(true);
setMessage('');
setEvidence(null);
pending.current?.abort();
const controller = new AbortController();
pending.current = controller;
try {
const response = await fetch(
`/api/v1/investment/demography?territories[]=${encodeURIComponent(territoryId)}`,
{ headers: { Accept: 'application/json' } },
`/api/v1/investment/demography?investment_context=1&territories[]=${encodeURIComponent(territoryId)}`,
{
headers: { Accept: 'application/json' },
signal: controller.signal,
},
);
if (!response.ok)
throw new Error('Consulta indisponível.');
setEvidence(await response.json());
const result = await response.json();
if (!controller.signal.aborted) {
setEvidence(result);
if (result.broader_context)
setMessage(
'Contexto administrativo mais amplo. Estes indicadores não representam a população da localidade escolhida.',
);
}
} catch {
if (controller.signal.aborted) return;
setMessage(
'Não foi possível consultar a evidência demográfica.',
);
} finally {
setBusy(false);
if (!controller.signal.aborted) setBusy(false);
}
}}
>