435 lines
18 KiB
TypeScript
435 lines
18 KiB
TypeScript
import { ProactiveSummary } from '@/components/proactive-investment';
|
|
import EducationalGuides from '@/components/educational-guides';
|
|
import InvestmentComplements, {
|
|
type ComplementOption,
|
|
} from '@/components/investment-complements';
|
|
import {
|
|
searchTerritoryHref,
|
|
investmentPreparationHref,
|
|
} from '@/lib/search-territory';
|
|
import type { EducationalArticle } from '@/components/educational-article-card';
|
|
import { ClassificationSummary } from '@/components/opportunity-classification';
|
|
import { Head, Link, router, usePage } from '@inertiajs/react';
|
|
import {
|
|
opportunityDescription,
|
|
recordedVerificationDate,
|
|
} from '@/lib/opportunity-information';
|
|
import { useState } from 'react';
|
|
import { downloadPublicOpportunityOffline } from '@/lib/public-opportunity-offline';
|
|
import InvestmentMapPanel from '@/components/investment-map-panel';
|
|
import StructureGeographyPanel, {
|
|
LocationList,
|
|
} from '@/components/structure-geography';
|
|
import PartnershipSourceLinks from '@/components/partnership-source-links';
|
|
import TerritorialSources from '@/components/territorial-source-evidence';
|
|
import { Frame, card, button, money, groupLabels } from './shared';
|
|
import type { Opportunity, Context } from './shared';
|
|
export default function Detail({
|
|
complements = [],
|
|
guides = [],
|
|
record: r,
|
|
context: c,
|
|
zone_origin,
|
|
returnUrl = '/oportunidades',
|
|
dossierOrigin,
|
|
}: {
|
|
complements?: ComplementOption[];
|
|
guides?: EducationalArticle[];
|
|
record: Opportunity;
|
|
context: Context;
|
|
zone_origin?: { id: string; name: string } | null;
|
|
returnUrl?: string;
|
|
dossierOrigin?: { id: string; title: string } | null;
|
|
}) {
|
|
const page = usePage<{ auth: { user: unknown } }>();
|
|
const { auth } = page.props;
|
|
const dossierContext = new URLSearchParams(
|
|
page.url.split('?')[1] ?? '',
|
|
).get('context');
|
|
const [sharing, setSharing] = useState('');
|
|
const [offlineMessage, setOfflineMessage] = useState('');
|
|
return (
|
|
<Frame title={r.title}>
|
|
<Head>
|
|
<meta
|
|
head-key="description"
|
|
name="description"
|
|
content={opportunityDescription(r)}
|
|
/>
|
|
<meta
|
|
head-key="og:title"
|
|
property="og:title"
|
|
content={r.title}
|
|
/>
|
|
<meta
|
|
head-key="og:description"
|
|
property="og:description"
|
|
content={opportunityDescription(r)}
|
|
/>
|
|
</Head>
|
|
{r.maturity_label === 'Em preparação' && (
|
|
<p className="rounded border border-amber-700 bg-amber-50 p-4">
|
|
<strong>Em preparação.</strong> Consulte a oportunidade e
|
|
prepare o seu investimento. A execução depende das condições
|
|
e autorizações aplicáveis ao projecto.
|
|
</p>
|
|
)}
|
|
<Link
|
|
className={button}
|
|
href={investmentPreparationHref(
|
|
r.id,
|
|
page.url,
|
|
dossierOrigin?.id,
|
|
)}
|
|
>
|
|
Iniciar ou continuar investimento com esta oportunidade
|
|
</Link>
|
|
<PartnershipSourceLinks type="investment" id={r.id} />
|
|
{auth.user && dossierContext && (
|
|
<nav
|
|
aria-label="Preparar esta oportunidade"
|
|
className="flex flex-wrap gap-4"
|
|
>
|
|
<Link
|
|
className="underline"
|
|
href={`/simulador-fiscal?context=${encodeURIComponent(dossierContext)}&opportunity=opportunity%3A${r.id}`}
|
|
>
|
|
Simular esta oportunidade
|
|
</Link>
|
|
<Link
|
|
className="underline"
|
|
href={`/investimentos/${encodeURIComponent(dossierContext)}?opportunity=opportunity%3A${r.id}`}
|
|
>
|
|
Etapas e pedidos desta oportunidade
|
|
</Link>
|
|
<Link
|
|
className="underline"
|
|
href={`/investidor/terra-duat/novo?context=${encodeURIComponent(dossierContext)}&opportunity=opportunity%3A${r.id}`}
|
|
>
|
|
Terra/DUAT desta oportunidade
|
|
</Link>
|
|
<Link
|
|
className="underline"
|
|
href={`/balcao-virtual/dossiers/${encodeURIComponent(dossierContext)}?opportunity=opportunity%3A${r.id}`}
|
|
>
|
|
Balcão desta oportunidade
|
|
</Link>
|
|
</nav>
|
|
)}
|
|
<Link href={returnUrl} className="underline">
|
|
Voltar à pesquisa
|
|
</Link>
|
|
<ProactiveSummary value={r.proactive} />
|
|
{dossierOrigin && (
|
|
<p>
|
|
<Link
|
|
className="underline"
|
|
href={searchTerritoryHref(
|
|
`/carteira/${dossierOrigin.id}`,
|
|
page.url,
|
|
)}
|
|
>
|
|
Voltar ao dossier: {dossierOrigin.title}
|
|
</Link>
|
|
</p>
|
|
)}
|
|
<p>
|
|
{r.reference} · {r.sector?.name} · {r.province} {r.district}
|
|
</p>
|
|
<p className="text-xl">{r.summary}</p>
|
|
<div className="space-y-2">
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => {
|
|
try {
|
|
downloadPublicOpportunityOffline(r);
|
|
setOfflineMessage(
|
|
'Ficheiro preparado. Guarde-o e abra-o para consultar esta ficha sem rede.',
|
|
);
|
|
} catch {
|
|
setOfflineMessage(
|
|
'Não foi possível preparar o ficheiro. Tente novamente.',
|
|
);
|
|
}
|
|
}}
|
|
>
|
|
Guardar ficha para consulta offline (.html)
|
|
</button>
|
|
<p role="status" aria-live="polite">
|
|
{offlineMessage}
|
|
</p>
|
|
</div>
|
|
<InvestmentComplements items={complements} />
|
|
<ClassificationSummary rows={c.classification ?? []} />
|
|
<TerritorialSources sources={c.source_evidence} />
|
|
<section className={card + ' space-y-3'}>
|
|
<h2 className="text-xl font-bold">Onde se localiza</h2>
|
|
<p>
|
|
As relações cadastradas não confirmam disponibilidade ou
|
|
capacidade. Locais dos projetos associados, áreas de impacto
|
|
e abrangência dos clusters são apresentados separadamente.
|
|
</p>
|
|
<LocationList locations={c.opportunity_locations ?? []} />
|
|
{!c.opportunity_locations?.length && (
|
|
<p>
|
|
Implantação estruturada não documentada. O contexto
|
|
associado abaixo não confirma onde a oportunidade será
|
|
implantada.
|
|
</p>
|
|
)}
|
|
</section>
|
|
<InvestmentMapPanel
|
|
filters={{ opportunity_id: r.id }}
|
|
territoryId={c.primary_territory_path?.at(-1)?.id}
|
|
/>
|
|
{c.primary_territory_path &&
|
|
c.primary_territory_path.length > 0 && (
|
|
<p>
|
|
Território principal cadastrado (implantação por
|
|
confirmar):{' '}
|
|
{c.primary_territory_path
|
|
.map((node) => node.name)
|
|
.join(' → ')}
|
|
</p>
|
|
)}
|
|
<div className="flex flex-wrap gap-4">
|
|
<Link
|
|
className={button}
|
|
href={investmentPreparationHref(
|
|
r.id,
|
|
page.url,
|
|
dossierOrigin?.id,
|
|
)}
|
|
>
|
|
Iniciar ou continuar o roteiro deste investimento
|
|
</Link>
|
|
{auth.user ? (
|
|
<button
|
|
className={button}
|
|
onClick={() =>
|
|
router.post('/investidor/manifestacoes', {
|
|
opportunity_id: r.id,
|
|
...(zone_origin
|
|
? {
|
|
zone_id: zone_origin.id,
|
|
intent: 'interest',
|
|
}
|
|
: {}),
|
|
})
|
|
}
|
|
>
|
|
Preparar manifestação de interesse
|
|
</button>
|
|
) : (
|
|
<Link
|
|
className={button}
|
|
href={`/participar/entrar?return=${encodeURIComponent(page.url)}`}
|
|
>
|
|
Entrar para preparar manifestação
|
|
</Link>
|
|
)}
|
|
<Link
|
|
className="underline"
|
|
href={`/manifestar-interesse/${r.slug}`}
|
|
>
|
|
Contacto rápido sem rascunho
|
|
</Link>
|
|
<button
|
|
className="underline"
|
|
onClick={() => {
|
|
if (!navigator.clipboard) {
|
|
setSharing(
|
|
'Copie a ligação na barra de endereço do navegador.',
|
|
);
|
|
return;
|
|
}
|
|
navigator.clipboard
|
|
.writeText(window.location.href)
|
|
.then(() => setSharing('Ligação copiada.'))
|
|
.catch(() =>
|
|
setSharing(
|
|
'Copie a ligação na barra de endereço do navegador.',
|
|
),
|
|
);
|
|
}}
|
|
>
|
|
Copiar ligação
|
|
</button>
|
|
</div>
|
|
{sharing && <p role="status">{sharing}</p>}
|
|
{!!c.zones?.length && (
|
|
<section className={card}>
|
|
<h2 className="text-xl font-bold">
|
|
ZEE, ZFI e parques associados
|
|
</h2>
|
|
{c.zones.map((z) => (
|
|
<p key={z.id}>
|
|
<Link
|
|
className="underline"
|
|
href={`/zonas?category=${z.category}&q=${encodeURIComponent(z.name)}`}
|
|
>
|
|
{z.name}
|
|
</Link>{' '}
|
|
·{' '}
|
|
{z.association_type === 'official'
|
|
? 'Associação documental validada'
|
|
: 'Relação ' + z.association_type}{' '}
|
|
· Fonte: {z.source_reference}
|
|
</p>
|
|
))}
|
|
<p>
|
|
A associação não atribui automaticamente benefícios ou
|
|
licenças.
|
|
</p>
|
|
</section>
|
|
)}
|
|
<div className="grid gap-6 lg:grid-cols-3">
|
|
<section
|
|
className={card + ' whitespace-pre-line lg:col-span-2'}
|
|
>
|
|
<h2 className="mb-3 text-xl font-bold">O investimento</h2>
|
|
{r.description || 'Descrição por completar.'}
|
|
</section>
|
|
<dl className={card + ' space-y-4'}>
|
|
{[
|
|
['Promotor', r.promoter_name],
|
|
[
|
|
'Última verificação registada',
|
|
recordedVerificationDate(r.last_validated_at),
|
|
],
|
|
['Investimento', money(r)],
|
|
['Maturidade', r.maturity_label],
|
|
[
|
|
'Classificação da preparação',
|
|
r.maturity_catalogue_version === 'spec-v2'
|
|
? 'Etapas de preparação'
|
|
: r.maturity_catalogue_version === 'legacy-v1'
|
|
? 'Histórico — seis níveis'
|
|
: 'Versão não registada',
|
|
],
|
|
['Parceria', r.financing_modality],
|
|
['Impacto', r.expected_impact],
|
|
['Calendário', c.profile?.target_date],
|
|
].map(([key, value]) => (
|
|
<div key={key}>
|
|
<dt className="font-bold">{key}</dt>
|
|
<dd>{value || 'Não indicado'}</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
</div>
|
|
{c.profile && (
|
|
<section className={card + ' space-y-4'}>
|
|
<h2 className="text-xl font-bold">
|
|
Viabilidade e preparação
|
|
</h2>
|
|
{[
|
|
['Modelo de negócio', c.profile.business_model],
|
|
['Requisitos', c.profile.requirements],
|
|
['Riscos', c.profile.risks],
|
|
['Fonte', c.profile.source_reference],
|
|
].map(([label, text]) => (
|
|
<div key={label}>
|
|
<h3 className="font-bold">{label}</h3>
|
|
<p className="whitespace-pre-line">
|
|
{text || 'Não indicado'}
|
|
</p>
|
|
</div>
|
|
))}
|
|
{c.profile.is_education && (
|
|
<Link href="/educacao" className="underline">
|
|
Explorar oportunidades na educação
|
|
</Link>
|
|
)}
|
|
</section>
|
|
)}
|
|
<section className="grid gap-4 md:grid-cols-4">
|
|
{(
|
|
['clusters', 'corridors', 'projects', 'locations'] as const
|
|
).map((key, i) => (
|
|
<div className={card} key={key}>
|
|
<h2 className="font-bold">
|
|
{
|
|
[
|
|
'Clusters',
|
|
'Corredores',
|
|
'Projectos âncora',
|
|
'Referências territoriais anteriores',
|
|
][i]
|
|
}
|
|
</h2>
|
|
{c[key].map((entity) => (
|
|
<p key={entity.id}>
|
|
{entity.dossiers?.map((dossier) => (
|
|
<span key={dossier.id}>
|
|
<Link
|
|
className="underline"
|
|
href={searchTerritoryHref(
|
|
`/carteira/${dossier.id}`,
|
|
page.url,
|
|
)}
|
|
>
|
|
Consultar dossier: {dossier.title}
|
|
</Link>
|
|
<br />
|
|
</span>
|
|
))}
|
|
<Link
|
|
className="underline"
|
|
href={
|
|
'/oportunidades?' +
|
|
[
|
|
'cluster_id',
|
|
'corridor_id',
|
|
'project_id',
|
|
'geo_location_id',
|
|
][i] +
|
|
'=' +
|
|
entity.id
|
|
}
|
|
>
|
|
{entity.name}
|
|
</Link>
|
|
</p>
|
|
))}
|
|
{!c[key].length && <p>Sem relação publicada.</p>}
|
|
</div>
|
|
))}
|
|
</section>
|
|
{(['projects', 'clusters'] as const).flatMap((key) =>
|
|
c[key]
|
|
.filter(
|
|
(entity) => entity.geography && entity.dossiers?.length,
|
|
)
|
|
.map((entity) => (
|
|
<StructureGeographyPanel
|
|
key={`${key}-${entity.id}`}
|
|
geography={entity.geography!}
|
|
cluster={key === 'clusters'}
|
|
dossierId={entity.dossiers![0].id}
|
|
/>
|
|
)),
|
|
)}
|
|
<section className={card}>
|
|
<h2 className="text-xl font-bold">
|
|
Infraestruturas, competências, educação e apoios
|
|
</h2>
|
|
{c.facets.map((f) => (
|
|
<p key={f.id}>
|
|
{groupLabels[f.group] ?? f.group}: {f.label}
|
|
</p>
|
|
))}
|
|
{!c.facets.length && (
|
|
<p>
|
|
Sem características estruturadas publicadas. Pode
|
|
declarar as suas necessidades na manifestação de
|
|
interesse.
|
|
</p>
|
|
)}
|
|
</section>
|
|
<EducationalGuides articles={guides} />
|
|
</Frame>
|
|
);
|
|
}
|