2291 lines
106 KiB
TypeScript
2291 lines
106 KiB
TypeScript
import ParkDetailsEditor, {
|
||
ParkDetailsPublic,
|
||
emptyParkDetails,
|
||
type ParkDetails,
|
||
} from '@/components/investment-zone-operational-details';
|
||
import { Link, router, useForm, usePage } from '@inertiajs/react';
|
||
import { catalogueReturnHref } from '@/lib/catalogue-context';
|
||
import { searchTerritoryHref } from '@/lib/search-territory';
|
||
import InvestmentTerritory from '@/components/investment-territory';
|
||
import InvestmentMapPanel from '@/components/investment-map-panel';
|
||
import {
|
||
TerritoryFields,
|
||
type TerritoryOption,
|
||
} from '@/components/investment-territory';
|
||
import { useState } from 'react';
|
||
import { Frame, Field, input, button, card, api } from './shared';
|
||
import PartnershipSourceLinks from '@/components/partnership-source-links';
|
||
import TerritorialSources, {
|
||
type TerritorialSourceEvidence,
|
||
} from '@/components/territorial-source-evidence';
|
||
import ZoneRelations from './zone-relations';
|
||
import ZoneMap from './zone-map';
|
||
import ZoneAttachments from './zone-attachments';
|
||
import type { ZoneTargets } from './zone-relations';
|
||
|
||
type OperationalDetail = {
|
||
id?: string;
|
||
name: string;
|
||
status: string;
|
||
source_reference?: string | null;
|
||
source_date?: string | null;
|
||
kind?: string | null;
|
||
scope?: string | null;
|
||
capacity_type?: string | null;
|
||
capacity_value?: number | string | null;
|
||
capacity_unit?: string | null;
|
||
focus?: string | null;
|
||
economic_activity_id?: string | null;
|
||
support_document_ids?: string[];
|
||
private_note?: string | null;
|
||
};
|
||
type Area = {
|
||
type: string;
|
||
value: number | string | null;
|
||
unit: string;
|
||
source_reference: string;
|
||
source_date?: string | null;
|
||
status: string;
|
||
};
|
||
const labels: Record<string, string> = {
|
||
other: 'Outro',
|
||
unknown: 'Não informado',
|
||
not_informed: 'Não informado',
|
||
unconfirmed: 'Por confirmar',
|
||
inside: 'No parque',
|
||
regional: 'Proximidade regional',
|
||
infrastructure: 'Infraestrutura',
|
||
service: 'Serviço',
|
||
access: 'Acesso',
|
||
potential: 'Potencial',
|
||
proposed: 'Proposta',
|
||
existing: 'Existente segundo a fonte',
|
||
planned: 'Planeado',
|
||
installed: 'Instalada segundo a fonte',
|
||
promotional: 'Foco promocional',
|
||
reported: 'Declarado pela fonte',
|
||
confirmed: 'Confirmado no cadastro',
|
||
disputed: 'Divergente',
|
||
total: 'Total',
|
||
legal: 'Legal',
|
||
developed: 'Desenvolvida',
|
||
pilot: 'Piloto',
|
||
available: 'Disponível segundo a fonte',
|
||
in_development: 'Em desenvolvimento',
|
||
reported_unverified: 'Declarada, não confirmada',
|
||
industrial_park: 'Parque industrial',
|
||
pending: 'Por confirmar',
|
||
general: 'Geral',
|
||
not_applicable: 'Não aplicável',
|
||
operational: 'Operacional segundo o cadastro',
|
||
suspended: 'Suspenso',
|
||
partially_operational: 'Parcialmente operacional',
|
||
announced: 'Anunciado',
|
||
unavailable: 'Indisponível',
|
||
economic_zone: 'Zona económica',
|
||
agro_industrial_park: 'Parque agro-industrial',
|
||
industrial_logistics_park: 'Parque industrial e logístico',
|
||
};
|
||
const label = (value?: string | null) =>
|
||
value ? (labels[value] ?? value) : 'Não informado';
|
||
type Zone = {
|
||
editorial_enabled?: boolean;
|
||
editorial_workflow?: {
|
||
state: string;
|
||
fresh: boolean;
|
||
content_version: number;
|
||
hash: string;
|
||
can_approve: boolean;
|
||
independent_required: boolean;
|
||
} | null;
|
||
operational_details?: ParkDetails;
|
||
operational_details_public?: ParkDetails;
|
||
details_available?: boolean;
|
||
id: string;
|
||
version_no: number;
|
||
code: string;
|
||
category: string;
|
||
name: string;
|
||
name_en: string | null;
|
||
description: string | null;
|
||
description_en: string | null;
|
||
province: string | null;
|
||
district: string | null;
|
||
operator_id?: string;
|
||
legal_source_id?: string;
|
||
publication_status?: string;
|
||
validation_status: string;
|
||
physical_category?: string | null;
|
||
legal_regime?: string | null;
|
||
operational_status?: string;
|
||
development_status?: string;
|
||
availability_status?: string;
|
||
area_value?: string | null;
|
||
area_unit?: string | null;
|
||
area_components?: Area[];
|
||
public_version_no?: number;
|
||
base_public_version?: number;
|
||
has_private_draft?: boolean;
|
||
source_evidence?: {
|
||
title: string;
|
||
url: string;
|
||
source_type: string;
|
||
supports: string;
|
||
source_date?: string | null;
|
||
}[];
|
||
aliases?: string[];
|
||
activities?: OperationalDetail[];
|
||
resources?: OperationalDetail[];
|
||
historical_territory?: {
|
||
name: string;
|
||
district?: string;
|
||
province?: string;
|
||
source_reference?: string;
|
||
} | null;
|
||
};
|
||
type Source = {
|
||
id: string;
|
||
title: string;
|
||
url: string;
|
||
diploma: string;
|
||
article: string;
|
||
competent_entity: string;
|
||
valid_from: string;
|
||
valid_until: string | null;
|
||
version_no: number;
|
||
validation_status: string;
|
||
};
|
||
type ZoneEditorForm = {
|
||
operational_details: ParkDetails;
|
||
version_no: number;
|
||
code: string;
|
||
category: string;
|
||
physical_category: string;
|
||
legal_regime: string;
|
||
operational_status: string;
|
||
development_status: string;
|
||
availability_status: string;
|
||
area_value: string;
|
||
area_unit: string;
|
||
area_components: Area[];
|
||
source_evidence_json: string;
|
||
activities: OperationalDetail[];
|
||
resources: OperationalDetail[];
|
||
aliases_text: string;
|
||
historical_name: string;
|
||
historical_district: string;
|
||
historical_province: string;
|
||
historical_source_reference: string;
|
||
name: string;
|
||
name_en: string;
|
||
description: string;
|
||
description_en: string;
|
||
operator_id: string;
|
||
legal_source_id: string;
|
||
};
|
||
type Props = {
|
||
targets: ZoneTargets | null;
|
||
related: { id: string; title: string }[];
|
||
relations: {
|
||
id: string;
|
||
version_no: number;
|
||
association_type: string;
|
||
validation_status: string;
|
||
}[];
|
||
geometries: {
|
||
geometry_id: string;
|
||
id: string;
|
||
version_no: number;
|
||
purpose: string;
|
||
validation_status: string;
|
||
}[];
|
||
record: Zone;
|
||
territorialSources?: TerritorialSourceEvidence[];
|
||
management: boolean;
|
||
zoneExtensionsAvailable?: boolean;
|
||
economicActivities?: { id: string; display_label: string }[];
|
||
profileAvailable?: boolean;
|
||
zoneContext?: {
|
||
zone_id: string;
|
||
consulted_public_version: number;
|
||
notice: string;
|
||
} | null;
|
||
source: Source | null;
|
||
operator: string | null;
|
||
operators: { id: string; name: string }[];
|
||
legalSources: Source[];
|
||
links: {
|
||
id: string;
|
||
item_id: string;
|
||
association_type: string;
|
||
validation_status: string;
|
||
version_no: number;
|
||
}[];
|
||
revisions: { version_no: number; action: string; created_at: string }[];
|
||
locations: {
|
||
id: string;
|
||
name: string;
|
||
location_type: string;
|
||
scope_type: string;
|
||
source_reference: string;
|
||
validation_status: string;
|
||
}[];
|
||
attachments: {
|
||
id: string;
|
||
kind: string;
|
||
caption: string;
|
||
source_reference: string;
|
||
source_date: string | null;
|
||
rights_status?: string;
|
||
rights_basis?: string | null;
|
||
personal_data_status?: string;
|
||
review_status?: string;
|
||
reviewed_by?: number | null;
|
||
independent_review?: boolean;
|
||
publicly_selected?: boolean;
|
||
uploaded_by?: number;
|
||
version_no?: number;
|
||
file_name?: string;
|
||
document_id?: string;
|
||
media_type: string;
|
||
size_bytes: number | null;
|
||
download_url: string;
|
||
}[];
|
||
opportunities: {
|
||
data: { id: number; title: string; slug: string }[];
|
||
next_page_url: string | null;
|
||
prev_page_url: string | null;
|
||
} | null;
|
||
};
|
||
function ZoneHistory({
|
||
id,
|
||
revisions,
|
||
}: {
|
||
id: string;
|
||
revisions: Props['revisions'];
|
||
}) {
|
||
const [selected, setSelected] = useState<{
|
||
version_no: number;
|
||
fields: { name?: string; description?: string };
|
||
observations: {
|
||
label?: string;
|
||
value?: string;
|
||
unit?: string;
|
||
scope?: string;
|
||
period_start?: string;
|
||
period_end?: string;
|
||
source_reference?: string;
|
||
}[];
|
||
} | null>(null);
|
||
const [error, setError] = useState('');
|
||
const [loading, setLoading] = useState(false);
|
||
async function inspect(version: number) {
|
||
setLoading(true);
|
||
setError('');
|
||
setSelected(null);
|
||
try {
|
||
setSelected(
|
||
await api(
|
||
`/api/v2/investment/admin/zones/${id}/revisions/${version}`,
|
||
),
|
||
);
|
||
} catch (e) {
|
||
setError(
|
||
e instanceof Error
|
||
? e.message
|
||
: 'Não foi possível conferir esta versão.',
|
||
);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}
|
||
return (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">Histórico editorial</h2>
|
||
{revisions.map((r) => (
|
||
<p key={r.version_no}>
|
||
Versão {r.version_no} · {r.action} · {r.created_at}{' '}
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={loading}
|
||
onClick={() => inspect(r.version_no)}
|
||
>
|
||
Conferir versão {r.version_no}
|
||
</button>
|
||
</p>
|
||
))}
|
||
{error && <p role="alert">{error}</p>}
|
||
{selected && (
|
||
<div className="space-y-2 border-t pt-3">
|
||
<h3 className="font-bold">
|
||
Consulta da versão {selected.version_no}
|
||
</h3>
|
||
<p>
|
||
Esta consulta preserva a versão actual e a preparação em
|
||
curso.
|
||
</p>
|
||
<p>{selected.fields.name}</p>
|
||
<p className="whitespace-pre-line">
|
||
{selected.fields.description}
|
||
</p>
|
||
{selected.observations.map((row, index) => (
|
||
<div key={index}>
|
||
<strong>{row.label}</strong>
|
||
<p>
|
||
{row.value} {row.unit}
|
||
</p>
|
||
<p>
|
||
{row.scope} · {row.period_start} –{' '}
|
||
{row.period_end}
|
||
</p>
|
||
<p>{row.source_reference}</p>
|
||
</div>
|
||
))}
|
||
</div>
|
||
)}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function ZoneReview({
|
||
zone,
|
||
busy,
|
||
dirty,
|
||
action,
|
||
}: {
|
||
zone: Zone;
|
||
busy: boolean;
|
||
dirty: boolean;
|
||
action: (url: string, data: unknown) => Promise<void>;
|
||
}) {
|
||
const [reason, setReason] = useState('');
|
||
const workflow = zone.editorial_workflow;
|
||
const labels: Record<string, string> = {
|
||
submit: 'Submeter à revisão',
|
||
start_review: 'Iniciar revisão',
|
||
approve: 'Aprovar esta edição',
|
||
return: 'Devolver com fundamento',
|
||
reject: 'Rejeitar',
|
||
archive: 'Arquivar proposta privada',
|
||
};
|
||
const states: Record<string, string> = {
|
||
draft: 'Rascunho',
|
||
submitted: 'Submetido',
|
||
in_review: 'Em revisão',
|
||
approved: 'Aprovado',
|
||
returned: 'Devolvido',
|
||
rejected: 'Rejeitado',
|
||
archived: 'Arquivado',
|
||
};
|
||
const actions: Record<string, string[]> = {
|
||
not_started: ['submit'],
|
||
draft: ['submit', 'archive'],
|
||
submitted: ['start_review', 'archive'],
|
||
in_review: ['return', 'reject', 'approve', 'archive'],
|
||
approved: ['archive'],
|
||
returned: ['submit', 'archive'],
|
||
rejected: ['archive'],
|
||
archived: [],
|
||
};
|
||
return (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Revisão da zona e dos indicadores
|
||
</h2>
|
||
<p>
|
||
{workflow
|
||
? states[workflow.state]
|
||
: 'Prepare a revisão da edição actual.'}{' '}
|
||
A aprovação é separada da publicação. A apresentação anterior
|
||
mantém-se durante a revisão.
|
||
</p>
|
||
{workflow && (
|
||
<p>
|
||
Edição do conteúdo: {workflow.content_version} · versão de
|
||
trabalho: {zone.version_no}.
|
||
</p>
|
||
)}
|
||
{workflow && !workflow.fresh && (
|
||
<p role="alert">
|
||
O conteúdo, fonte ou anexos mudaram. Guarde uma nova
|
||
preparação e volte a conferir.
|
||
</p>
|
||
)}
|
||
{dirty && (
|
||
<p>Guarde as alterações antes de decidir sobre a edição.</p>
|
||
)}
|
||
<Field label="Fundamento da decisão">
|
||
<textarea
|
||
className={input}
|
||
value={reason}
|
||
onChange={(event) => setReason(event.target.value)}
|
||
/>
|
||
</Field>
|
||
<div className="mt-3 flex flex-wrap gap-3">
|
||
{(actions[workflow?.state ?? 'not_started'] ?? [])
|
||
.filter(
|
||
(name) => name !== 'approve' || workflow?.can_approve,
|
||
)
|
||
.map((name) => (
|
||
<button
|
||
key={name}
|
||
className={button}
|
||
type="button"
|
||
disabled={
|
||
busy ||
|
||
dirty ||
|
||
reason.trim().length < 10 ||
|
||
Boolean(
|
||
workflow &&
|
||
!workflow.fresh &&
|
||
['submit', 'approve'].includes(name),
|
||
)
|
||
}
|
||
onClick={() =>
|
||
void action(
|
||
`/api/v2/investment/admin/zones/${zone.id}/editorial/${name}`,
|
||
{ version_no: zone.version_no, reason },
|
||
)
|
||
}
|
||
>
|
||
{labels[name]}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
export default function ZonePage(props: Props) {
|
||
return (
|
||
<Editor
|
||
key={`${props.record.id}:${props.record.version_no}`}
|
||
{...props}
|
||
/>
|
||
);
|
||
}
|
||
function Editor({
|
||
targets,
|
||
related,
|
||
relations,
|
||
geometries,
|
||
record: z,
|
||
territorialSources,
|
||
management,
|
||
zoneExtensionsAvailable = false,
|
||
economicActivities = [],
|
||
profileAvailable = false,
|
||
zoneContext,
|
||
source,
|
||
operator,
|
||
operators,
|
||
legalSources,
|
||
links,
|
||
revisions,
|
||
locations,
|
||
attachments,
|
||
opportunities,
|
||
}: Props) {
|
||
const pageUrl = usePage().url;
|
||
const [message, setMessage] = useState('');
|
||
const [busy, setBusy] = useState(false);
|
||
const [locationPath, setLocationPath] = useState<TerritoryOption[]>([]);
|
||
const [locationSource, setLocationSource] = useState('');
|
||
const [locationScope, setLocationScope] = useState('administrative');
|
||
const [activityName, setActivityName] = useState('');
|
||
const [activityStatus, setActivityStatus] = useState('potential');
|
||
const [activitySource, setActivitySource] = useState('');
|
||
const [resourceName, setResourceName] = useState('');
|
||
const [resourceStatus, setResourceStatus] = useState('unconfirmed');
|
||
const [resourceSource, setResourceSource] = useState('');
|
||
const [_attachmentFile, _setAttachmentFile] = useState<File | null>(null);
|
||
const [_attachmentKind, _setAttachmentKind] = useState('legal_instrument');
|
||
const [_attachmentCaption, _setAttachmentCaption] = useState('');
|
||
const [_attachmentSource, _setAttachmentSource] = useState('');
|
||
const [_attachmentSourceDate, _setAttachmentSourceDate] = useState('');
|
||
const [_attachmentRightsBasis, _setAttachmentRightsBasis] = useState('');
|
||
const [_attachmentRightsStatus, _setAttachmentRightsStatus] =
|
||
useState('pending');
|
||
const [_reviewChoices, _setReviewChoices] = useState<
|
||
Record<string, { rights: string; personal: string }>
|
||
>({});
|
||
const form = useForm<ZoneEditorForm>({
|
||
operational_details: z.operational_details ?? emptyParkDetails(),
|
||
version_no: z.version_no,
|
||
code: z.code,
|
||
category: z.category,
|
||
physical_category: z.physical_category ?? 'unknown',
|
||
legal_regime: z.legal_regime ?? 'pending',
|
||
operational_status: z.operational_status ?? 'unknown',
|
||
development_status: z.development_status ?? 'unknown',
|
||
availability_status: z.availability_status ?? 'not_informed',
|
||
area_value: z.area_value ?? '',
|
||
area_unit: z.area_unit ?? '',
|
||
area_components: z.area_components ?? [],
|
||
source_evidence_json: JSON.stringify(z.source_evidence ?? [], null, 2),
|
||
activities: (z.activities ?? []).map((activity) => ({
|
||
...activity,
|
||
source_reference: activity.source_reference ?? null,
|
||
})),
|
||
resources: (z.resources ?? []).map((resource) => ({
|
||
...resource,
|
||
source_reference: resource.source_reference ?? null,
|
||
})),
|
||
aliases_text: (z.aliases ?? []).join('\n'),
|
||
historical_name: z.historical_territory?.name ?? '',
|
||
historical_district: z.historical_territory?.district ?? '',
|
||
historical_province: z.historical_territory?.province ?? '',
|
||
historical_source_reference:
|
||
z.historical_territory?.source_reference ?? '',
|
||
name: z.name,
|
||
name_en: z.name_en ?? '',
|
||
description: z.description ?? '',
|
||
description_en: z.description_en ?? '',
|
||
operator_id: z.operator_id ?? '',
|
||
legal_source_id: z.legal_source_id ?? '',
|
||
});
|
||
async function action(url: string, data: unknown) {
|
||
setBusy(true);
|
||
setMessage('');
|
||
try {
|
||
const result = await api(url, data);
|
||
if (
|
||
result &&
|
||
typeof result === 'object' &&
|
||
typeof result.editorial_url === 'string' &&
|
||
result.editorial_url.startsWith(
|
||
'/management/editorial/subjects/',
|
||
)
|
||
) {
|
||
router.visit(result.editorial_url);
|
||
} else {
|
||
router.reload();
|
||
}
|
||
} catch (e) {
|
||
setMessage(e instanceof Error ? e.message : 'Falha na operação.');
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}
|
||
return (
|
||
<Frame title={z.name}>
|
||
<Link
|
||
className="underline"
|
||
href={catalogueReturnHref(
|
||
management ? '/management/investment/zones' : '/zonas',
|
||
pageUrl,
|
||
)}
|
||
>
|
||
Voltar à pesquisa
|
||
</Link>
|
||
<TerritorialSources sources={territorialSources} />
|
||
{!management && z.category === 'industrial_park' && (
|
||
<ParkDetailsPublic value={z.operational_details_public} />
|
||
)}
|
||
{!management && <PartnershipSourceLinks type="zone" id={z.id} />}
|
||
<p>
|
||
{z.code} ·{' '}
|
||
{z.category === 'industrial_park'
|
||
? 'Parque industrial'
|
||
: z.category.toUpperCase()}{' '}
|
||
{management && `· ${z.validation_status}`} · {z.province}{' '}
|
||
{z.district}
|
||
</p>
|
||
<p>
|
||
A ficha é informativa. A associação territorial não atribui
|
||
benefícios, licenças ou autorização aduaneira.
|
||
</p>
|
||
{message && (
|
||
<p role="alert" className={card}>
|
||
{message}
|
||
</p>
|
||
)}
|
||
{management && z.category === 'industrial_park' && (
|
||
<p role="status">
|
||
Versão pública {z.public_version_no ?? z.version_no} ·
|
||
preparação privada{' '}
|
||
{z.has_private_draft ? z.version_no : 'ainda não guardada'}.
|
||
Guardar não altera a publicação.{' '}
|
||
{!profileAvailable &&
|
||
'A preparação requer a instalação nominal do esquema; a ficha pública foi preservada.'}
|
||
</p>
|
||
)}
|
||
{management &&
|
||
z.has_private_draft &&
|
||
z.base_public_version !== z.public_version_no && (
|
||
<section className={card}>
|
||
<p role="alert">
|
||
A base da preparação mudou. Compare a{' '}
|
||
<Link className="underline" href={`/zonas/${z.id}`}>
|
||
ficha pública atual
|
||
</Link>{' '}
|
||
antes de reconciliar. Os detalhes privados
|
||
mantêm-se; esta ação não publica.
|
||
</p>
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={busy || form.isDirty}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/zones/${z.id}/reconcile`,
|
||
{
|
||
version_no: z.version_no,
|
||
base_public_version:
|
||
z.public_version_no,
|
||
},
|
||
)
|
||
}
|
||
>
|
||
Confirmo a comparação e reconciliar a base
|
||
</button>
|
||
</section>
|
||
)}
|
||
{!management && z.category === 'industrial_park' && (
|
||
<Link
|
||
className={button}
|
||
href={'/investimentos/iniciar?source=park:' + z.id}
|
||
>
|
||
Comparar este parque no contexto de um investimento
|
||
</Link>
|
||
)}
|
||
{!management && zoneContext && (
|
||
<section className={card}>
|
||
<h2 className="font-semibold">
|
||
Preparar uma ideia com este parque como referência
|
||
</h2>
|
||
<p>{zoneContext.notice}</p>
|
||
<Link
|
||
className="underline"
|
||
href={`/investimentos/a-partir-do-parque/${zoneContext.zone_id}?consulted_public_version=${zoneContext.consulted_public_version}`}
|
||
>
|
||
Iniciar ou continuar uma ideia
|
||
</Link>
|
||
<p>
|
||
Versão pública consultada:{' '}
|
||
{zoneContext.consulted_public_version}
|
||
</p>
|
||
</section>
|
||
)}
|
||
{management ? (
|
||
<>
|
||
<form
|
||
className={card + ' grid gap-4 md:grid-cols-2'}
|
||
onSubmit={async (e) => {
|
||
e.preventDefault();
|
||
setBusy(true);
|
||
setMessage('');
|
||
try {
|
||
const {
|
||
source_evidence_json,
|
||
operational_details,
|
||
...base
|
||
} = form.data;
|
||
await api(
|
||
`/api/v2/investment/admin/zones/${z.id}`,
|
||
{
|
||
...base,
|
||
...(z.details_available &&
|
||
z.category === 'industrial_park'
|
||
? { operational_details }
|
||
: {}),
|
||
source_evidence:
|
||
JSON.parse(source_evidence_json),
|
||
_method: 'PUT',
|
||
},
|
||
);
|
||
router.reload();
|
||
} catch (failure) {
|
||
setMessage(
|
||
failure instanceof Error
|
||
? failure.message
|
||
: 'Falha ao guardar.',
|
||
);
|
||
} finally {
|
||
setBusy(false);
|
||
}
|
||
}}
|
||
>
|
||
{(
|
||
[
|
||
['code', 'Código'],
|
||
['name', 'Nome PT'],
|
||
['name_en', 'Nome EN'],
|
||
] as const
|
||
).map(([key, label]) => (
|
||
<Field key={key} label={label}>
|
||
<input
|
||
className={input}
|
||
value={form.data[key]}
|
||
onChange={(e) =>
|
||
form.setData(key, e.target.value)
|
||
}
|
||
/>
|
||
</Field>
|
||
))}
|
||
<Field label="Categoria">
|
||
<select
|
||
className={input}
|
||
value={form.data.category}
|
||
onChange={(e) =>
|
||
form.setData('category', e.target.value)
|
||
}
|
||
>
|
||
<option value="pending">Pendente</option>
|
||
<option value="zee">ZEE</option>
|
||
<option value="zfi">ZFI</option>
|
||
<option value="industrial_park">
|
||
Parque industrial
|
||
</option>
|
||
</select>
|
||
</Field>
|
||
<Field label="Categoria física">
|
||
<select
|
||
className={input}
|
||
value={form.data.physical_category}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'physical_category',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="unknown">Por confirmar</option>
|
||
<option value="economic_zone">
|
||
Zona económica
|
||
</option>
|
||
<option value="industrial_park">
|
||
Parque industrial
|
||
</option>
|
||
{zoneExtensionsAvailable && (
|
||
<>
|
||
<option value="agro_industrial_park">
|
||
Parque agro-industrial
|
||
</option>
|
||
<option value="industrial_logistics_park">
|
||
Parque industrial e logístico
|
||
</option>
|
||
</>
|
||
)}
|
||
<option value="industrial_free_zone">
|
||
Zona franca industrial
|
||
</option>
|
||
<option value="integrated_tourism_area">
|
||
Área de turismo integrado
|
||
</option>
|
||
<option value="other">Outra</option>
|
||
</select>
|
||
</Field>
|
||
<Field label="Regime jurídico">
|
||
<select
|
||
className={input}
|
||
value={form.data.legal_regime}
|
||
onChange={(e) =>
|
||
form.setData('legal_regime', e.target.value)
|
||
}
|
||
>
|
||
<option value="pending">
|
||
Pendente de confirmação
|
||
</option>
|
||
<option value="zee">ZEE</option>
|
||
<option value="zfi">ZFI</option>
|
||
<option value="general">Regime geral</option>
|
||
<option value="not_applicable">
|
||
Não aplicável
|
||
</option>
|
||
</select>
|
||
</Field>
|
||
<Field label="Estado operacional">
|
||
<select
|
||
className={input}
|
||
value={form.data.operational_status}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'operational_status',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="unknown">Não confirmado</option>
|
||
<option value="operational">Operacional</option>
|
||
<option value="implementation">
|
||
Em implementação
|
||
</option>
|
||
<option value="planned">Planeado</option>
|
||
<option value="suspended">Suspenso</option>
|
||
</select>
|
||
</Field>
|
||
{zoneExtensionsAvailable && (
|
||
<Field label="Estado de desenvolvimento">
|
||
<select
|
||
className={input}
|
||
value={form.data.development_status}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'development_status',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="unknown">
|
||
Por confirmar
|
||
</option>
|
||
<option value="announced">Anunciado</option>
|
||
<option value="planned">Planeado</option>
|
||
<option value="in_development">
|
||
Em desenvolvimento
|
||
</option>
|
||
<option value="partially_operational">
|
||
Parcialmente operacional
|
||
</option>
|
||
<option value="operational">
|
||
Operacional
|
||
</option>
|
||
<option value="suspended">Suspenso</option>
|
||
</select>
|
||
</Field>
|
||
)}
|
||
{zoneExtensionsAvailable && (
|
||
<Field label="Disponibilidade para instalação">
|
||
<select
|
||
className={input}
|
||
value={form.data.availability_status}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'availability_status',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="not_informed">
|
||
Não informada
|
||
</option>
|
||
<option value="confirmed">
|
||
Confirmada
|
||
</option>
|
||
<option value="unavailable">
|
||
Indisponível
|
||
</option>
|
||
<option value="reported_unverified">
|
||
Reportada, por verificar
|
||
</option>
|
||
</select>
|
||
</Field>
|
||
)}
|
||
<Field label="Área documentada">
|
||
<input
|
||
className={input}
|
||
type="number"
|
||
min="0"
|
||
step="0.0001"
|
||
value={form.data.area_value}
|
||
onChange={(e) =>
|
||
form.setData('area_value', e.target.value)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="Unidade da área">
|
||
<select
|
||
className={input}
|
||
value={form.data.area_unit}
|
||
onChange={(e) =>
|
||
form.setData('area_unit', e.target.value)
|
||
}
|
||
>
|
||
<option value="">Por confirmar</option>
|
||
<option value="ha">hectares (ha)</option>
|
||
<option value="km2">
|
||
quilómetros quadrados (km²)
|
||
</option>
|
||
</select>
|
||
</Field>
|
||
{zoneExtensionsAvailable && (
|
||
<section className="space-y-3 md:col-span-2">
|
||
<h2 className="font-semibold">
|
||
Áreas por âmbito e fonte
|
||
</h2>
|
||
<p>Não somar âmbitos nem inferir área livre.</p>
|
||
{form.data.area_components.map(
|
||
(area, index) => (
|
||
<div
|
||
key={index}
|
||
className="grid gap-2 md:grid-cols-3"
|
||
>
|
||
{(
|
||
[
|
||
'type',
|
||
'value',
|
||
'unit',
|
||
'source_reference',
|
||
'source_date',
|
||
'status',
|
||
] as const
|
||
).map((key) => (
|
||
<label
|
||
key={key}
|
||
className="grid gap-1"
|
||
>
|
||
{
|
||
{
|
||
type: 'Âmbito',
|
||
value: 'Valor (vazio se desconhecido)',
|
||
unit: 'Unidade',
|
||
source_reference:
|
||
'Fonte da área',
|
||
source_date:
|
||
'Data da fonte',
|
||
status: 'Estado',
|
||
}[key]
|
||
}
|
||
{(
|
||
[
|
||
'type',
|
||
'unit',
|
||
'status',
|
||
] as string[]
|
||
).includes(key) ? (
|
||
<select
|
||
className={input}
|
||
value={String(
|
||
area[key] ?? '',
|
||
)}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'area_components',
|
||
form.data.area_components.map(
|
||
(
|
||
item,
|
||
i,
|
||
) =>
|
||
i ===
|
||
index
|
||
? {
|
||
...item,
|
||
[key]: e
|
||
.target
|
||
.value,
|
||
}
|
||
: item,
|
||
),
|
||
)
|
||
}
|
||
>
|
||
{(key === 'type'
|
||
? [
|
||
'total',
|
||
'legal',
|
||
'developed',
|
||
'pilot',
|
||
'available',
|
||
]
|
||
: key === 'unit'
|
||
? [
|
||
'ha',
|
||
'km2',
|
||
'm2',
|
||
]
|
||
: [
|
||
'reported',
|
||
'confirmed',
|
||
'disputed',
|
||
]
|
||
).map((value) => (
|
||
<option
|
||
key={value}
|
||
value={
|
||
value
|
||
}
|
||
>
|
||
{label(
|
||
value,
|
||
)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
) : (
|
||
<input
|
||
className={input}
|
||
type={
|
||
key ===
|
||
'source_date'
|
||
? 'date'
|
||
: key ===
|
||
'value'
|
||
? 'number'
|
||
: 'text'
|
||
}
|
||
step={
|
||
key === 'value'
|
||
? 'any'
|
||
: undefined
|
||
}
|
||
value={
|
||
area[key] ?? ''
|
||
}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'area_components',
|
||
form.data.area_components.map(
|
||
(
|
||
item,
|
||
i,
|
||
) =>
|
||
i ===
|
||
index
|
||
? {
|
||
...item,
|
||
[key]:
|
||
key ===
|
||
'value'
|
||
? e
|
||
.target
|
||
.value ===
|
||
''
|
||
? null
|
||
: Number(
|
||
e
|
||
.target
|
||
.value,
|
||
)
|
||
: e
|
||
.target
|
||
.value ||
|
||
null,
|
||
}
|
||
: item,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
)}
|
||
</label>
|
||
))}
|
||
</div>
|
||
),
|
||
)}
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
onClick={() =>
|
||
form.setData('area_components', [
|
||
...form.data.area_components,
|
||
{
|
||
type: 'total',
|
||
value: null,
|
||
unit: 'ha',
|
||
source_reference: '',
|
||
source_date: null,
|
||
status: 'reported',
|
||
},
|
||
])
|
||
}
|
||
>
|
||
Adicionar área documentada
|
||
</button>
|
||
</section>
|
||
)}
|
||
{zoneExtensionsAvailable && (
|
||
<Field label="Evidência e fontes (JSON; tipo e o que comprova)">
|
||
<textarea
|
||
className={input}
|
||
rows={6}
|
||
value={form.data.source_evidence_json}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'source_evidence_json',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
)}
|
||
<Field label="Designações alternativas (uma por linha)">
|
||
<textarea
|
||
className={input}
|
||
rows={2}
|
||
value={form.data.aliases_text}
|
||
onChange={(e) =>
|
||
form.setData('aliases_text', e.target.value)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="Localização histórica">
|
||
<input
|
||
className={input}
|
||
value={form.data.historical_name}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'historical_name',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="Distrito histórico">
|
||
<input
|
||
className={input}
|
||
value={form.data.historical_district}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'historical_district',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="Província histórica">
|
||
<input
|
||
className={input}
|
||
value={form.data.historical_province}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'historical_province',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<Field label="Fonte da localização histórica">
|
||
<input
|
||
className={input}
|
||
value={form.data.historical_source_reference}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'historical_source_reference',
|
||
e.target.value,
|
||
)
|
||
}
|
||
/>
|
||
</Field>
|
||
<section
|
||
className="space-y-3 md:col-span-2"
|
||
aria-label="Actividades documentadas"
|
||
>
|
||
<h2 className="font-semibold">
|
||
Actividades e sectores
|
||
</h2>
|
||
{form.data.activities.map((activity, index) => (
|
||
<div key={activity.id ?? index}>
|
||
<DetailFields
|
||
detail={activity}
|
||
kind="activities"
|
||
economicActivities={economicActivities}
|
||
documents={attachments
|
||
.filter((a) => !!a.document_id)
|
||
.map((a) => ({
|
||
id: a.document_id!,
|
||
title: a.caption,
|
||
}))}
|
||
onChange={(next) =>
|
||
form.setData(
|
||
'activities',
|
||
form.data.activities.map(
|
||
(item, i) =>
|
||
i === index
|
||
? next
|
||
: item,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<p>
|
||
{activity.name} · {activity.status} ·{' '}
|
||
{activity.source_reference ??
|
||
'fonte por registar'}
|
||
</p>
|
||
</div>
|
||
))}
|
||
<div className="grid gap-2 md:grid-cols-3">
|
||
<input
|
||
className={input}
|
||
aria-label="Actividade"
|
||
placeholder="Actividade"
|
||
value={activityName}
|
||
onChange={(e) =>
|
||
setActivityName(e.target.value)
|
||
}
|
||
/>
|
||
<select
|
||
className={input}
|
||
aria-label="Estado da actividade"
|
||
value={activityStatus}
|
||
onChange={(e) =>
|
||
setActivityStatus(e.target.value)
|
||
}
|
||
>
|
||
<option value="potential">
|
||
Potencial referido pela fonte
|
||
</option>
|
||
<option value="proposed">Proposta</option>
|
||
<option value="authorized">
|
||
Autorizada
|
||
</option>
|
||
<option value="conditional">
|
||
Condicionada
|
||
</option>
|
||
<option value="excluded">Excluída</option>
|
||
</select>
|
||
<input
|
||
className={input}
|
||
aria-label="Fonte da actividade"
|
||
placeholder="URL ou referência"
|
||
value={activitySource}
|
||
onChange={(e) =>
|
||
setActivitySource(e.target.value)
|
||
}
|
||
/>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={!activityName.trim()}
|
||
onClick={() => {
|
||
form.setData('activities', [
|
||
...form.data.activities,
|
||
{
|
||
name: activityName.trim(),
|
||
status: activityStatus,
|
||
source_reference:
|
||
activitySource.trim() || null,
|
||
},
|
||
]);
|
||
setActivityName('');
|
||
setActivitySource('');
|
||
}}
|
||
>
|
||
Adicionar actividade
|
||
</button>
|
||
</section>
|
||
<section
|
||
className="space-y-3 md:col-span-2"
|
||
aria-label="Infra-estruturas e recursos"
|
||
>
|
||
<h2 className="font-semibold">
|
||
Infra-estruturas e recursos
|
||
</h2>
|
||
{form.data.resources.map((resource, index) => (
|
||
<div key={resource.id ?? index}>
|
||
<DetailFields
|
||
detail={resource}
|
||
kind="resources"
|
||
economicActivities={economicActivities}
|
||
documents={attachments
|
||
.filter((a) => !!a.document_id)
|
||
.map((a) => ({
|
||
id: a.document_id!,
|
||
title: a.caption,
|
||
}))}
|
||
onChange={(next) =>
|
||
form.setData(
|
||
'resources',
|
||
form.data.resources.map(
|
||
(item, i) =>
|
||
i === index
|
||
? next
|
||
: item,
|
||
),
|
||
)
|
||
}
|
||
/>
|
||
<p>
|
||
{resource.name} · {resource.status} ·{' '}
|
||
{resource.source_reference ??
|
||
'fonte por registar'}
|
||
</p>
|
||
</div>
|
||
))}
|
||
<div className="grid gap-2 md:grid-cols-3">
|
||
<input
|
||
className={input}
|
||
aria-label="Recurso"
|
||
placeholder="Estrada, energia, água…"
|
||
value={resourceName}
|
||
onChange={(e) =>
|
||
setResourceName(e.target.value)
|
||
}
|
||
/>
|
||
<select
|
||
className={input}
|
||
aria-label="Estado do recurso"
|
||
value={resourceStatus}
|
||
onChange={(e) =>
|
||
setResourceStatus(e.target.value)
|
||
}
|
||
>
|
||
<option value="existing">
|
||
Existente, fonte confirmada
|
||
</option>
|
||
<option value="planned">Planeado</option>
|
||
<option value="unconfirmed">
|
||
Não confirmado
|
||
</option>
|
||
</select>
|
||
<input
|
||
className={input}
|
||
aria-label="Fonte do recurso"
|
||
placeholder="URL ou referência"
|
||
value={resourceSource}
|
||
onChange={(e) =>
|
||
setResourceSource(e.target.value)
|
||
}
|
||
/>
|
||
</div>
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={!resourceName.trim()}
|
||
onClick={() => {
|
||
form.setData('resources', [
|
||
...form.data.resources,
|
||
{
|
||
name: resourceName.trim(),
|
||
status: resourceStatus,
|
||
source_reference:
|
||
resourceSource.trim() || null,
|
||
},
|
||
]);
|
||
setResourceName('');
|
||
setResourceSource('');
|
||
}}
|
||
>
|
||
Adicionar recurso
|
||
</button>
|
||
</section>
|
||
{(
|
||
[
|
||
['description', 'Descrição PT'],
|
||
['description_en', 'Descrição EN'],
|
||
] as const
|
||
).map(([key, label]) => (
|
||
<Field key={key} label={label}>
|
||
<textarea
|
||
className={input}
|
||
value={form.data[key]}
|
||
onChange={(e) =>
|
||
form.setData(key, e.target.value)
|
||
}
|
||
/>
|
||
</Field>
|
||
))}
|
||
{z.category === 'industrial_park' &&
|
||
(z.details_available ? (
|
||
<ParkDetailsEditor
|
||
key={z.version_no}
|
||
geometries={geometries.map((g, i) => ({
|
||
id: g.geometry_id,
|
||
name: `Geometria ${i + 1} — ${g.purpose} · ${g.validation_status} · v${g.version_no}`,
|
||
}))}
|
||
links={links.map((l, i) => ({
|
||
id: l.id,
|
||
name: `Relação ${i + 1} — ${l.association_type} · ${l.validation_status} · v${l.version_no}`,
|
||
}))}
|
||
value={form.data.operational_details}
|
||
onChange={(value) =>
|
||
form.setData(
|
||
'operational_details',
|
||
value,
|
||
)
|
||
}
|
||
organizations={operators}
|
||
documents={attachments
|
||
.filter((a) => !!a.document_id)
|
||
.map((a) => ({
|
||
id: a.document_id!,
|
||
title: a.caption,
|
||
}))}
|
||
/>
|
||
) : (
|
||
<p role="status">
|
||
Complemento L1 ainda não instalado. Os
|
||
campos anteriores continuam disponíveis; a
|
||
versão pública está preservada.
|
||
</p>
|
||
))}
|
||
<Field label="Operador cadastrado">
|
||
<select
|
||
className={input}
|
||
value={form.data.operator_id}
|
||
onChange={(e) =>
|
||
form.setData('operator_id', e.target.value)
|
||
}
|
||
>
|
||
<option value="">Por confirmar</option>
|
||
{operators.map((o) => (
|
||
<option key={o.id} value={o.id}>
|
||
{o.name}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</Field>
|
||
<Field label="Fonte jurídica">
|
||
<select
|
||
className={input}
|
||
value={form.data.legal_source_id}
|
||
onChange={(e) =>
|
||
form.setData(
|
||
'legal_source_id',
|
||
e.target.value,
|
||
)
|
||
}
|
||
>
|
||
<option value="">Por confirmar</option>
|
||
{legalSources.map((s) => (
|
||
<option key={s.id} value={s.id}>
|
||
{s.title} · {s.validation_status}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</Field>
|
||
<button
|
||
disabled={
|
||
busy ||
|
||
(z.category === 'industrial_park' &&
|
||
!profileAvailable)
|
||
}
|
||
className={button}
|
||
>
|
||
{z.category === 'industrial_park'
|
||
? 'Guardar preparação privada'
|
||
: 'Guardar rascunho'}
|
||
</button>
|
||
</form>
|
||
<ZoneAttachments
|
||
zoneId={z.id}
|
||
attachments={attachments}
|
||
management={true}
|
||
zonePublished={z.publication_status === 'published'}
|
||
/>
|
||
<section
|
||
className={card + ' space-y-4'}
|
||
aria-label="Localizações documentadas"
|
||
>
|
||
<h2 className="text-xl font-bold">
|
||
Localizações documentadas
|
||
</h2>
|
||
<p>
|
||
As localizações acrescentadas ficam pendentes até
|
||
revisão independente. Não são inferidas pelo nome.
|
||
</p>
|
||
{locations.map((location) => (
|
||
<div
|
||
key={location.id}
|
||
className="rounded border p-3"
|
||
>
|
||
<p>
|
||
{location.name} · {location.scope_type} ·{' '}
|
||
{location.validation_status}
|
||
</p>
|
||
<p className="text-sm">
|
||
{location.source_reference}
|
||
</p>
|
||
{location.validation_status === 'pending' && (
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={busy}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/zone-locations/${location.id}/validate`,
|
||
{ version_no: 1 },
|
||
)
|
||
}
|
||
>
|
||
Rever localização
|
||
</button>
|
||
)}
|
||
</div>
|
||
))}
|
||
<TerritoryFields
|
||
endpoint="/management/territory-options"
|
||
onChange={setLocationPath}
|
||
/>
|
||
<Field label="Tipo de abrangência">
|
||
<select
|
||
className={input}
|
||
value={locationScope}
|
||
onChange={(event) =>
|
||
setLocationScope(event.target.value)
|
||
}
|
||
>
|
||
<option value="legal_scope">
|
||
Perímetro legal
|
||
</option>
|
||
<option value="administrative">
|
||
Unidade administrativa
|
||
</option>
|
||
<option value="site">Instalação/local</option>
|
||
<option value="influence">
|
||
Área de influência
|
||
</option>
|
||
</select>
|
||
</Field>
|
||
<Field label="Fonte e fundamento da associação">
|
||
<input
|
||
className={input}
|
||
minLength={10}
|
||
maxLength={2000}
|
||
value={locationSource}
|
||
onChange={(event) =>
|
||
setLocationSource(event.target.value)
|
||
}
|
||
/>
|
||
</Field>
|
||
<button
|
||
type="button"
|
||
className={button}
|
||
disabled={
|
||
busy ||
|
||
!locationPath.length ||
|
||
locationSource.length < 10
|
||
}
|
||
onClick={() => {
|
||
const selected =
|
||
locationPath[locationPath.length - 1];
|
||
void action(
|
||
`/api/v2/investment/admin/zones/${z.id}`,
|
||
{
|
||
...form.data,
|
||
locations: [
|
||
{
|
||
geo_location_id: selected.id,
|
||
scope_type: locationScope,
|
||
source_reference:
|
||
locationSource,
|
||
},
|
||
],
|
||
_method: 'PUT',
|
||
},
|
||
);
|
||
}}
|
||
>
|
||
Guardar outra localização
|
||
</button>
|
||
</section>
|
||
{z.editorial_enabled && (
|
||
<ZoneReview
|
||
zone={z}
|
||
busy={busy}
|
||
dirty={form.isDirty}
|
||
action={action}
|
||
/>
|
||
)}
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Publicação informativa
|
||
</h2>
|
||
<p>
|
||
Versão {z.version_no}. Confirme os dados, a fonte e
|
||
a localização antes de publicar. A publicação não
|
||
confirma estado operacional, disponibilidade para
|
||
investimento ou benefícios fiscais. Guarde primeiro
|
||
as alterações.
|
||
</p>
|
||
<div className="flex gap-4">
|
||
<button
|
||
className={button}
|
||
disabled={
|
||
busy ||
|
||
form.isDirty ||
|
||
(z.editorial_enabled &&
|
||
(z.editorial_workflow?.state !==
|
||
'approved' ||
|
||
!z.editorial_workflow?.fresh ||
|
||
(z.editorial_workflow
|
||
?.independent_required &&
|
||
!z.editorial_workflow
|
||
?.can_approve))) ||
|
||
(z.category === 'industrial_park' &&
|
||
!profileAvailable)
|
||
}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/zones/${z.id}/publish`,
|
||
{
|
||
version_no: z.version_no,
|
||
},
|
||
)
|
||
}
|
||
>
|
||
Publicar zona
|
||
</button>
|
||
<button
|
||
className={button}
|
||
disabled={busy}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/zones/${z.id}/suspend`,
|
||
{
|
||
version_no: z.version_no,
|
||
},
|
||
)
|
||
}
|
||
>
|
||
Suspender publicação
|
||
</button>
|
||
</div>
|
||
</section>
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">Fontes por rever</h2>
|
||
{legalSources.map((s) => (
|
||
<article key={s.id} className="my-4">
|
||
<p>
|
||
{s.title} · {s.diploma} · {s.article} ·{' '}
|
||
{s.validation_status}
|
||
</p>
|
||
<a
|
||
className="underline"
|
||
href={s.url}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
>
|
||
Consultar documento
|
||
</a>
|
||
<div className="flex gap-4">
|
||
{s.validation_status === 'pending' && (
|
||
<button
|
||
className={button}
|
||
disabled={busy}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/legal-sources/${s.id}/validate`,
|
||
{
|
||
version_no:
|
||
s.version_no,
|
||
},
|
||
)
|
||
}
|
||
>
|
||
Validar fonte
|
||
</button>
|
||
)}
|
||
{s.validation_status !== 'revoked' && (
|
||
<button
|
||
className={button}
|
||
disabled={busy}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/legal-sources/${s.id}/revoke`,
|
||
{
|
||
version_no:
|
||
s.version_no,
|
||
},
|
||
)
|
||
}
|
||
>
|
||
Revogar referência
|
||
</button>
|
||
)}
|
||
</div>
|
||
</article>
|
||
))}
|
||
</section>
|
||
<form
|
||
className={card + ' grid gap-4 md:grid-cols-2'}
|
||
onSubmit={(e) => {
|
||
e.preventDefault();
|
||
void action(
|
||
'/api/v2/investment/admin/legal-sources',
|
||
Object.fromEntries(
|
||
new FormData(e.currentTarget),
|
||
),
|
||
);
|
||
}}
|
||
>
|
||
<h2 className="text-xl font-bold md:col-span-2">
|
||
Registar fonte jurídica
|
||
</h2>
|
||
{(
|
||
[
|
||
['title', 'Título', 'text'],
|
||
['url', 'URL HTTPS', 'url'],
|
||
['diploma', 'Diploma', 'text'],
|
||
['article', 'Artigo', 'text'],
|
||
[
|
||
'competent_entity',
|
||
'Entidade competente indicada no diploma',
|
||
'text',
|
||
],
|
||
['valid_from', 'Início de vigência', 'date'],
|
||
[
|
||
'valid_until',
|
||
'Fim de vigência, se aplicável',
|
||
'date',
|
||
],
|
||
] as const
|
||
).map(([name, label, type]) => (
|
||
<Field key={name} label={label}>
|
||
<input
|
||
className={input}
|
||
name={name}
|
||
type={type}
|
||
required={name !== 'valid_until'}
|
||
/>
|
||
</Field>
|
||
))}
|
||
<button className={button} disabled={busy}>
|
||
Registar para revisão
|
||
</button>
|
||
</form>
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Associações para revisão
|
||
</h2>
|
||
{links.map((l) => (
|
||
<div key={l.id}>
|
||
<p>
|
||
{l.item_id} · {l.association_type} ·{' '}
|
||
{l.validation_status}
|
||
</p>
|
||
<button
|
||
className={button}
|
||
disabled={busy}
|
||
onClick={() =>
|
||
action(
|
||
`/api/v2/investment/admin/zone-links/${l.id}/${l.validation_status === 'pending' ? 'validate' : 'revoke'}`,
|
||
{ version_no: l.version_no },
|
||
)
|
||
}
|
||
>
|
||
{l.validation_status === 'pending'
|
||
? 'Validar associação'
|
||
: 'Revogar associação'}
|
||
</button>
|
||
</div>
|
||
))}
|
||
</section>
|
||
<ZoneHistory id={z.id} revisions={revisions} />
|
||
{targets && (
|
||
<ZoneRelations
|
||
id={z.id}
|
||
targets={targets}
|
||
sources={legalSources}
|
||
relations={relations}
|
||
geometries={geometries}
|
||
busy={busy}
|
||
action={action}
|
||
/>
|
||
)}
|
||
</>
|
||
) : (
|
||
<>
|
||
<p className="whitespace-pre-line">{z.description}</p>
|
||
<p>
|
||
Categoria física: {label(z.physical_category)} · Regime
|
||
jurídico: {label(z.legal_regime)}
|
||
{zoneExtensionsAvailable
|
||
? ` · Desenvolvimento: ${label(z.development_status)} · Disponibilidade: ${label(z.availability_status)}`
|
||
: ''}
|
||
</p>
|
||
{z.area_value && (
|
||
<p>
|
||
Área documentada: {z.area_value} {z.area_unit}
|
||
</p>
|
||
)}
|
||
{zoneExtensionsAvailable && !!z.area_components?.length && (
|
||
<section className={card}>
|
||
<h2 className="font-bold">Áreas por âmbito</h2>
|
||
<ul>
|
||
{z.area_components.map((area, index) => (
|
||
<li key={index}>
|
||
{label(area.type)}:{' '}
|
||
{area.value ?? 'Não informado'}{' '}
|
||
{area.value == null ? '' : area.unit} ·{' '}
|
||
{label(area.status)} · Fonte:{' '}
|
||
{area.source_reference ||
|
||
'Não informada'}{' '}
|
||
·{' '}
|
||
{area.source_date ??
|
||
'Data não informada'}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
)}
|
||
{zoneExtensionsAvailable && !!z.source_evidence?.length && (
|
||
<section className={card}>
|
||
<h2 className="font-bold">
|
||
Fontes e o que comprovam
|
||
</h2>
|
||
<ul>
|
||
{z.source_evidence.map((evidence) => (
|
||
<li key={evidence.url}>
|
||
<a
|
||
className="underline"
|
||
href={evidence.url}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
>
|
||
{evidence.title}
|
||
</a>
|
||
{evidence.source_date
|
||
? ` · ${evidence.source_date}`
|
||
: ' · data não indicada'}{' '}
|
||
· {evidence.source_type} ·{' '}
|
||
{evidence.supports}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
<p>
|
||
Esta informação descreve o que a fonte declara;
|
||
não confirma vigência legal, benefícios, estado
|
||
operacional ou disponibilidade para
|
||
investimento.
|
||
</p>
|
||
</section>
|
||
)}
|
||
{z.historical_territory?.name && (
|
||
<p>
|
||
Localização histórica: {z.historical_territory.name}
|
||
{z.historical_territory.district
|
||
? ` · ${z.historical_territory.district}`
|
||
: ''}
|
||
{z.historical_territory.province
|
||
? ` · ${z.historical_territory.province}`
|
||
: ''}
|
||
</p>
|
||
)}
|
||
{z.activities?.length ? (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Actividades e sectores referidos
|
||
</h2>
|
||
<ul>
|
||
{z.activities.map((activity, index) => (
|
||
<li key={`${activity.name}-${index}`}>
|
||
{activity.name} ·{' '}
|
||
{activity.status === 'potential'
|
||
? 'potencial referido; não confirmado como autorizado'
|
||
: activity.status === 'proposed'
|
||
? 'proposto; não confirmado como autorizado'
|
||
: activity.status === 'authorized'
|
||
? 'autorizado segundo a fonte indicada'
|
||
: activity.status ===
|
||
'conditional'
|
||
? 'condicionado segundo a fonte indicada'
|
||
: 'excluído segundo a fonte indicada'}
|
||
{' · '}
|
||
{label(activity.focus)} ·{' '}
|
||
{activity.source_date ??
|
||
'Data não informada'}
|
||
{activity.source_reference
|
||
? ` · ${activity.source_reference}`
|
||
: ''}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
) : null}
|
||
{!z.activities?.length && (
|
||
<p>Atividades: não informadas.</p>
|
||
)}
|
||
{!z.resources?.length && (
|
||
<p>
|
||
Infraestruturas, serviços e acessos: não informados.
|
||
Capacidades: não informadas.
|
||
</p>
|
||
)}
|
||
{!z.area_components?.length && (
|
||
<p>Áreas por âmbito: não informadas.</p>
|
||
)}
|
||
{!related.length && (
|
||
<p>Sem relações publicadas com âncoras ou clusters.</p>
|
||
)}
|
||
{z.resources?.length ? (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Infra-estruturas e recursos
|
||
</h2>
|
||
{z.resources.map((resource, index) => (
|
||
<p key={`${resource.name}-${index}`}>
|
||
{resource.name} · {label(resource.status)} ·{' '}
|
||
{label(resource.kind)} ·{' '}
|
||
{label(resource.scope)} · Capacidade:{' '}
|
||
{resource.capacity_value ?? 'Não informada'}{' '}
|
||
{resource.capacity_value == null
|
||
? ''
|
||
: resource.capacity_unit}{' '}
|
||
·{' '}
|
||
{resource.source_date ??
|
||
'Data não informada'}
|
||
{resource.source_reference
|
||
? ` · ${resource.source_reference}`
|
||
: ''}
|
||
</p>
|
||
))}
|
||
</section>
|
||
) : null}
|
||
{locations.length > 0 && (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Abrangência territorial
|
||
</h2>
|
||
<ul>
|
||
{locations.map((location) => (
|
||
<li key={location.id}>
|
||
{location.name} (
|
||
{location.location_type}) ·{' '}
|
||
{location.scope_type}
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</section>
|
||
)}
|
||
<ZoneMap id={z.id} />
|
||
{z.description_en && (
|
||
<details>
|
||
<summary>English description</summary>
|
||
<p lang="en" className="whitespace-pre-line">
|
||
{z.description_en}
|
||
</p>
|
||
</details>
|
||
)}
|
||
<p>
|
||
Operador:{' '}
|
||
{operator ?? 'Informação pública por disponibilizar'}
|
||
</p>
|
||
<ZoneAttachments
|
||
zoneId={z.id}
|
||
attachments={attachments}
|
||
management={false}
|
||
zonePublished={z.publication_status === 'published'}
|
||
/>
|
||
{source && (
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Fonte e vigência
|
||
</h2>
|
||
{source.validation_status !== 'validated' && (
|
||
<p role="status">
|
||
Referência documental registada; validação
|
||
jurídica da fonte pendente. A ficha não
|
||
confirma vigência, benefício,
|
||
operacionalidade ou disponibilidade.
|
||
</p>
|
||
)}
|
||
{source.validation_status !== 'validated' && (
|
||
<p role="status">
|
||
Referência documental registada; validação
|
||
jurídica da fonte pendente. A ficha não
|
||
confirma vigência, benefício fiscal,
|
||
operacionalidade ou disponibilidade.
|
||
</p>
|
||
)}
|
||
<a
|
||
className="underline"
|
||
href={source.url}
|
||
target="_blank"
|
||
rel="noreferrer"
|
||
>
|
||
{source.title}
|
||
</a>
|
||
<p>
|
||
{source.diploma} · {source.article} ·{' '}
|
||
{source.competent_entity}
|
||
</p>
|
||
<p>
|
||
{source.valid_from} —{' '}
|
||
{source.valid_until ??
|
||
'Sem fim indicado na referência'}{' '}
|
||
· Versão {source.version_no}
|
||
</p>
|
||
</section>
|
||
)}
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Investimentos relacionados
|
||
</h2>
|
||
{opportunities?.data.map((o) => (
|
||
<p key={o.id}>
|
||
<Link
|
||
className="underline"
|
||
href={searchTerritoryHref(
|
||
`/oportunidades/${o.slug}?zone_id=${z.id}`,
|
||
pageUrl,
|
||
)}
|
||
>
|
||
{o.title}
|
||
</Link>
|
||
</p>
|
||
))}
|
||
{!opportunities?.data.length && (
|
||
<p>Sem investimentos publicados associados.</p>
|
||
)}
|
||
<nav aria-label="Paginação">
|
||
{opportunities?.prev_page_url && (
|
||
<Link href={opportunities.prev_page_url}>
|
||
Anterior
|
||
</Link>
|
||
)}{' '}
|
||
{opportunities?.next_page_url && (
|
||
<Link href={opportunities.next_page_url}>
|
||
Seguinte
|
||
</Link>
|
||
)}
|
||
</nav>
|
||
</section>
|
||
<div className="flex flex-wrap gap-3">
|
||
{(
|
||
[
|
||
['interest', 'Manifestar interesse'],
|
||
['dossier', 'Solicitar dossier'],
|
||
['meeting', 'Pedir reunião'],
|
||
] as const
|
||
).map(([intent, label]) => (
|
||
<button
|
||
key={intent}
|
||
className={button}
|
||
onClick={() =>
|
||
router.post('/investidor/manifestacoes', {
|
||
zone_id: z.id,
|
||
intent,
|
||
})
|
||
}
|
||
>
|
||
{label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
<p>
|
||
Pedido assistido com conta e consentimento. Não inicia
|
||
prazo de decisão administrativa nem confirma uma
|
||
reunião.
|
||
</p>
|
||
<section className={card}>
|
||
<h2 className="text-xl font-bold">
|
||
Clusters, corredores e projectos relacionados
|
||
</h2>
|
||
{related.map((r) => (
|
||
<p key={r.id}>
|
||
<Link
|
||
className="underline"
|
||
href={searchTerritoryHref(
|
||
`/carteira/${r.id}`,
|
||
pageUrl,
|
||
)}
|
||
>
|
||
{r.title}
|
||
</Link>
|
||
</p>
|
||
))}
|
||
{!related.length && (
|
||
<p>Sem relações territoriais publicadas.</p>
|
||
)}
|
||
</section>
|
||
</>
|
||
)}
|
||
{management && <InvestmentTerritory kind="zones" id={z.id} />}
|
||
{!management &&
|
||
['zee', 'zfi', 'industrial_park'].includes(z.category) && (
|
||
<InvestmentMapPanel
|
||
filters={{
|
||
[z.category === 'zee'
|
||
? 'zee_id'
|
||
: z.category === 'zfi'
|
||
? 'zfi_id'
|
||
: 'park_id']: z.id,
|
||
}}
|
||
/>
|
||
)}
|
||
</Frame>
|
||
);
|
||
}
|
||
|
||
function DetailFields({
|
||
detail,
|
||
kind,
|
||
onChange,
|
||
economicActivities,
|
||
documents,
|
||
}: {
|
||
detail: OperationalDetail;
|
||
kind: string;
|
||
economicActivities: { id: string; display_label: string }[];
|
||
documents: { id: string; title: string }[];
|
||
onChange: (next: OperationalDetail) => void;
|
||
}) {
|
||
const select = (
|
||
key: 'kind' | 'scope' | 'focus',
|
||
title: string,
|
||
values: string[],
|
||
) => (
|
||
<label className="grid gap-1">
|
||
{title}
|
||
<select
|
||
className={input}
|
||
value={detail[key] ?? ''}
|
||
onChange={(e) =>
|
||
onChange({ ...detail, [key]: e.target.value || null })
|
||
}
|
||
>
|
||
<option value="">Não informado</option>
|
||
{values.map((value) => (
|
||
<option key={value} value={value}>
|
||
{label(value)}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
);
|
||
return (
|
||
<fieldset className="my-3 grid gap-2 rounded border p-3 md:grid-cols-3">
|
||
<legend>{detail.name}</legend>
|
||
{kind === 'resources' && (
|
||
<>
|
||
{select('kind', 'Natureza', [
|
||
'infrastructure',
|
||
'service',
|
||
'access',
|
||
'other',
|
||
])}
|
||
{select('scope', 'Âmbito', [
|
||
'inside',
|
||
'regional',
|
||
'unknown',
|
||
])}
|
||
</>
|
||
)}
|
||
{kind === 'activities' &&
|
||
select('focus', 'Foco (distinto de autorização legal)', [
|
||
'promotional',
|
||
'potential',
|
||
'installed',
|
||
'unknown',
|
||
])}
|
||
<label className="grid gap-1">
|
||
Data da fonte
|
||
<input
|
||
className={input}
|
||
type="date"
|
||
value={detail.source_date ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
source_date: e.target.value || null,
|
||
})
|
||
}
|
||
/>
|
||
</label>
|
||
{kind === 'resources' && (
|
||
<>
|
||
<label className="grid gap-1">
|
||
Tipo de capacidade
|
||
<input
|
||
className={input}
|
||
value={detail.capacity_type ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
capacity_type: e.target.value || null,
|
||
})
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="grid gap-1">
|
||
Capacidade (vazio se desconhecida)
|
||
<input
|
||
className={input}
|
||
type="number"
|
||
min="0"
|
||
step="any"
|
||
value={detail.capacity_value ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
capacity_value:
|
||
e.target.value === ''
|
||
? null
|
||
: Number(e.target.value),
|
||
})
|
||
}
|
||
/>
|
||
</label>
|
||
<label className="grid gap-1">
|
||
Unidade
|
||
<input
|
||
className={input}
|
||
value={detail.capacity_unit ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
capacity_unit: e.target.value || null,
|
||
})
|
||
}
|
||
/>
|
||
</label>
|
||
</>
|
||
)}
|
||
{kind === 'activities' && (
|
||
<label className="grid gap-1">
|
||
Atividade económica documentada
|
||
<select
|
||
className={input}
|
||
value={detail.economic_activity_id ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
economic_activity_id: e.target.value || null,
|
||
})
|
||
}
|
||
>
|
||
<option value="">
|
||
Sem correspondência fundamentada
|
||
</option>
|
||
{economicActivities.map((a) => (
|
||
<option key={a.id} value={a.id}>
|
||
{a.display_label}
|
||
</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
)}
|
||
{!!documents.length && (
|
||
<fieldset>
|
||
<legend>Suporte privado já associado</legend>
|
||
{documents.map((d) => (
|
||
<label key={d.id} className="flex gap-2">
|
||
<input
|
||
type="checkbox"
|
||
checked={
|
||
detail.support_document_ids?.includes(
|
||
d.id,
|
||
) ?? false
|
||
}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
support_document_ids: e.target.checked
|
||
? [
|
||
...(detail.support_document_ids ??
|
||
[]),
|
||
d.id,
|
||
]
|
||
: (
|
||
detail.support_document_ids ??
|
||
[]
|
||
).filter((id) => id !== d.id),
|
||
})
|
||
}
|
||
/>
|
||
{d.title}
|
||
</label>
|
||
))}
|
||
</fieldset>
|
||
)}
|
||
<label className="grid gap-1">
|
||
Nota privada (não divulgada)
|
||
<input
|
||
className={input}
|
||
value={detail.private_note ?? ''}
|
||
onChange={(e) =>
|
||
onChange({
|
||
...detail,
|
||
private_note: e.target.value || null,
|
||
})
|
||
}
|
||
/>
|
||
</label>
|
||
</fieldset>
|
||
);
|
||
}
|