583 lines
26 KiB
TypeScript
583 lines
26 KiB
TypeScript
import InvestmentZoneInstallation, { type ParkInstallationPlan } from '@/components/investment-zone-installation';
|
|
import { Link, router } from '@inertiajs/react';
|
|
import { useState } from 'react';
|
|
import {
|
|
TerritoryFields,
|
|
type TerritoryOption,
|
|
} from '@/components/investment-territory';
|
|
import { Frame, Field, input, button, card, api } from './shared';
|
|
|
|
type Zone = {
|
|
resources?: { name: string }[];
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
category: string;
|
|
description: string | null;
|
|
province: string | null;
|
|
district: string | null;
|
|
version_no: number;
|
|
publication_status: string;
|
|
validation_status: string;
|
|
territory_path?: { id: string; name: string; location_type: string }[];
|
|
legal_regime?: string | null;
|
|
operational_status?: string;
|
|
development_status?: string;
|
|
availability_status?: string;
|
|
source_evidence?: {
|
|
title: string;
|
|
url: string;
|
|
source_type: string;
|
|
supports: string;
|
|
source_date?: string | null;
|
|
}[];
|
|
area_value?: string | null;
|
|
area_unit?: string | null;
|
|
activities?: { name: string; status: string }[];
|
|
locations?: {
|
|
id: string;
|
|
name: string;
|
|
location_type: string;
|
|
scope_type: string;
|
|
}[];
|
|
};
|
|
const parkLabels: Record<string,string> = { pending:'Por confirmar', general:'Geral', not_applicable:'Não aplicável', unknown:'Não informado', not_informed:'Não informada', announced:'Anunciado', planned:'Planeado', in_development:'Em desenvolvimento', partially_operational:'Parcialmente operacional', operational:'Operacional segundo o cadastro', suspended:'Suspenso', confirmed:'Confirmada segundo o cadastro', unavailable:'Indisponível', reported_unverified:'Declarada, não confirmada' };
|
|
export default function Zones({
|
|
installation,
|
|
detailsInstallation,
|
|
records,
|
|
filters,
|
|
management,
|
|
zoneExtensionsAvailable = false,
|
|
territorySelection = [],
|
|
}: {
|
|
installation?: ParkInstallationPlan | null;
|
|
detailsInstallation?: ParkInstallationPlan | null;
|
|
records: {
|
|
data: Zone[];
|
|
total: number;
|
|
next_page_url: string | null;
|
|
prev_page_url: string | null;
|
|
};
|
|
filters: {
|
|
q?: string;
|
|
category?: string;
|
|
physical_category?: string;
|
|
legal_regime?: string;
|
|
development_status?: string;
|
|
availability_status?: string;
|
|
activity?: string;
|
|
};
|
|
management: boolean;
|
|
zoneExtensionsAvailable?: boolean;
|
|
territorySelection?: TerritoryOption[];
|
|
}) {
|
|
const [error, setError] = useState('');
|
|
const [busy, setBusy] = useState(false);
|
|
const exportParams = new URLSearchParams();
|
|
for (const key of [
|
|
'q',
|
|
'category',
|
|
'physical_category',
|
|
'legal_regime',
|
|
'development_status',
|
|
'availability_status',
|
|
'activity',
|
|
] as const) {
|
|
const value = filters[key];
|
|
if (value) exportParams.set(key, value);
|
|
}
|
|
const territoryKeys: Record<string, string> = {
|
|
province: 'province_id',
|
|
district: 'district_id',
|
|
admin_post: 'admin_post_id',
|
|
locality: 'locality_id',
|
|
};
|
|
territorySelection.forEach((item) => {
|
|
const key = territoryKeys[item.location_type];
|
|
if (key) exportParams.set(key, item.id);
|
|
});
|
|
return (
|
|
<Frame
|
|
title={
|
|
management
|
|
? 'Gestão de ZEE, ZFI e parques'
|
|
: 'ZEE, ZFI e parques industriais'
|
|
}
|
|
>
|
|
{management && installation && <InvestmentZoneInstallation initial={installation} />}
|
|
{management && detailsInstallation && <InvestmentZoneInstallation initial={detailsInstallation} endpoint="/management/investment/zones/operational-install" title="Complemento operacional L1 dos parques" summary="Uma coluna de detalhes, com dados privados cifrados e projeção pública separada. Sem importação ou publicação de fichas." />}
|
|
<p>
|
|
A informação territorial não atribui benefícios nem substitui
|
|
certificados ou decisões das entidades competentes.
|
|
</p>
|
|
<nav
|
|
aria-label="Dimensões de investimento"
|
|
className="flex flex-wrap gap-4 underline"
|
|
>
|
|
<Link href="/clusters">Por Cluster</Link>
|
|
<Link href="/corredores">Por Corredor</Link>
|
|
<Link href="/zonas?category=zee">Por ZEE</Link>
|
|
<Link href="/zonas?category=zfi">Por ZFI</Link>
|
|
<Link href="/zonas?category=industrial_park">
|
|
Parques industriais
|
|
</Link>
|
|
</nav>
|
|
<form method="get" className={card + ' grid gap-4 md:grid-cols-3'}>
|
|
<Field label="Pesquisar por nome ou código">
|
|
<input
|
|
className={input}
|
|
name="q"
|
|
defaultValue={filters.q}
|
|
maxLength={120}
|
|
/>
|
|
</Field>
|
|
<Field label="Categoria">
|
|
<select
|
|
className={input}
|
|
name="category"
|
|
defaultValue={filters.category ?? ''}
|
|
>
|
|
<option value="">Todas</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}
|
|
name="physical_category"
|
|
defaultValue={filters.physical_category ?? ''}
|
|
>
|
|
<option value="">Todas</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">ZFI</option>
|
|
<option value="economic_zone">ZEE</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Actividade documentada">
|
|
<input
|
|
className={input}
|
|
name="activity"
|
|
defaultValue={filters.activity}
|
|
maxLength={120}
|
|
/>
|
|
</Field>
|
|
<Field label="Regime jurídico">
|
|
<select
|
|
className={input}
|
|
name="legal_regime"
|
|
defaultValue={filters.legal_regime ?? ''}
|
|
>
|
|
<option value="">Todos</option>
|
|
<option value="zee">ZEE</option>
|
|
<option value="zfi">ZFI</option>
|
|
<option value="general">Regime geral</option>
|
|
<option value="pending">Por confirmar</option>
|
|
</select>
|
|
</Field>
|
|
{zoneExtensionsAvailable && (
|
|
<Field label="Desenvolvimento">
|
|
<select
|
|
className={input}
|
|
name="development_status"
|
|
defaultValue={filters.development_status ?? ''}
|
|
>
|
|
<option value="">Todos</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="unknown">Por confirmar</option>
|
|
</select>
|
|
</Field>
|
|
)}
|
|
{zoneExtensionsAvailable && (
|
|
<Field label="Disponibilidade">
|
|
<select
|
|
className={input}
|
|
name="availability_status"
|
|
defaultValue={filters.availability_status ?? ''}
|
|
>
|
|
<option value="">Todas</option>
|
|
<option value="confirmed">Confirmada</option>
|
|
<option value="unavailable">Indisponível</option>
|
|
<option value="reported_unverified">
|
|
Reportada, por verificar
|
|
</option>
|
|
<option value="not_informed">Não informada</option>
|
|
</select>
|
|
</Field>
|
|
)}
|
|
<TerritoryFields initial={territorySelection} />
|
|
<button className={button}>Pesquisar</button>
|
|
</form>
|
|
<p role="status">{records.total} registos disponíveis</p>
|
|
{!management && (
|
|
<a
|
|
className="underline"
|
|
href={`/api/v2/investment/zones/export.csv?${exportParams.toString()}`}
|
|
>
|
|
Exportar resultados filtrados (CSV)
|
|
</a>
|
|
)}
|
|
{!records.total && (
|
|
<p className={card}>
|
|
Sem registos disponíveis para estes filtros. As zonas
|
|
aguardam cadastro e validação documental.
|
|
</p>
|
|
)}
|
|
{records.data.map((zone) => (
|
|
<article className={card} key={zone.id}>
|
|
<h2 className="text-xl font-bold">
|
|
<Link
|
|
className="underline"
|
|
href={`${management ? '/management/investment/zones' : '/zonas'}/${zone.id}`}
|
|
>
|
|
{zone.name}
|
|
</Link>
|
|
</h2>
|
|
<p>
|
|
{zone.code} · {zone.category.toUpperCase()} ·{' '}
|
|
{[zone.district, zone.province]
|
|
.filter(Boolean)
|
|
.join(', ') || 'Localização por confirmar'}
|
|
</p>
|
|
{zone.legal_regime && (
|
|
<p>
|
|
Regime jurídico: {zone.category === 'industrial_park' ? (parkLabels[zone.legal_regime] ?? zone.legal_regime.toUpperCase()) : zone.legal_regime.toUpperCase()}
|
|
</p>
|
|
)}
|
|
{zoneExtensionsAvailable && zone.development_status && (
|
|
<p>
|
|
Desenvolvimento:{' '}
|
|
{zone.category === 'industrial_park' ? (parkLabels[zone.development_status] ?? 'Por confirmar') : zone.development_status.replaceAll('_', ' ')}
|
|
</p>
|
|
)}
|
|
{zoneExtensionsAvailable && zone.availability_status && (
|
|
<p>
|
|
Disponibilidade para instalação:{' '}
|
|
{zone.category === 'industrial_park' ? (parkLabels[zone.availability_status] ?? 'Não informada') : zone.availability_status.replaceAll('_', ' ')}
|
|
</p>
|
|
)}
|
|
{zone.area_value && (
|
|
<p>
|
|
Área indicada: {zone.area_value} {zone.area_unit}
|
|
</p>
|
|
)}
|
|
{zone.locations?.length ? (
|
|
<p>
|
|
Abrangência:{' '}
|
|
{zone.locations
|
|
.map((location) => location.name)
|
|
.join(' · ')}
|
|
</p>
|
|
) : null}
|
|
{zone.activities?.length ? (
|
|
<p>
|
|
Actividades:{' '}
|
|
{zone.activities
|
|
.map(
|
|
(activity) =>
|
|
`${activity.name} (${activity.status})`,
|
|
)
|
|
.join(' · ')}
|
|
</p>
|
|
) : null}
|
|
{!!zone.source_evidence?.length && (
|
|
<p>
|
|
Fonte:{' '}
|
|
{zone.source_evidence.map((source, index) => (
|
|
<span key={source.url}>
|
|
{index > 0 ? ' · ' : ''}
|
|
<a
|
|
className="underline"
|
|
href={source.url}
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
>
|
|
{source.title}
|
|
</a>
|
|
{source.source_date
|
|
? ` (${source.source_date})`
|
|
: ' (data da fonte não informada)'}{' '}
|
|
— {source.supports}
|
|
</span>
|
|
))}
|
|
</p>
|
|
)}
|
|
{zone.category === 'industrial_park' && <p>{zone.resources?.length ? `${zone.resources.length} recursos descritos; consulte o âmbito e a fonte na ficha.` : 'Infraestruturas, serviços, acessos e capacidades: não informados.'} {!zone.activities?.length && 'Atividades: não informadas.'}</p>}
|
|
<p>{zone.description}</p>
|
|
<p>Validação: {zone.validation_status}</p>
|
|
{management && (
|
|
<p>
|
|
Versão {zone.version_no} · {zone.publication_status}
|
|
</p>
|
|
)}
|
|
</article>
|
|
))}
|
|
<nav aria-label="Paginação" className="flex gap-4 underline">
|
|
{records.prev_page_url && (
|
|
<Link href={records.prev_page_url}>Anterior</Link>
|
|
)}
|
|
{records.next_page_url && (
|
|
<Link href={records.next_page_url}>Seguinte</Link>
|
|
)}
|
|
</nav>
|
|
{management && (
|
|
<form
|
|
className={card + ' space-y-4'}
|
|
onSubmit={async (event) => {
|
|
event.preventDefault();
|
|
const data = Object.fromEntries(
|
|
new FormData(event.currentTarget),
|
|
);
|
|
setBusy(true);
|
|
setError('');
|
|
try {
|
|
await api('/api/v2/investment/admin/zones', data);
|
|
router.reload();
|
|
} catch (failure) {
|
|
setError(
|
|
failure instanceof Error
|
|
? failure.message
|
|
: 'Não foi possível guardar. Tente novamente.',
|
|
);
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}}
|
|
>
|
|
<h2 className="text-xl font-bold">Criar rascunho</h2>
|
|
<TerritoryFields endpoint="/management/territory-options" />
|
|
<Field label="Código">
|
|
<input
|
|
name="code"
|
|
className={input}
|
|
required
|
|
maxLength={80}
|
|
/>
|
|
</Field>
|
|
<Field label="Nome">
|
|
<input
|
|
name="name"
|
|
className={input}
|
|
required
|
|
maxLength={255}
|
|
/>
|
|
</Field>
|
|
<Field label="Categoria proposta">
|
|
<select name="category" className={input}>
|
|
<option value="pending">
|
|
Pendente de enquadramento
|
|
</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
|
|
name="physical_category"
|
|
className={input}
|
|
defaultValue="unknown"
|
|
>
|
|
<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>
|
|
)}
|
|
{zoneExtensionsAvailable && (
|
|
<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>
|
|
</select>
|
|
</Field>
|
|
{zoneExtensionsAvailable && (
|
|
<Field label="Estado de desenvolvimento">
|
|
<select
|
|
name="development_status"
|
|
className={input}
|
|
defaultValue="unknown"
|
|
>
|
|
<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
|
|
name="availability_status"
|
|
className={input}
|
|
defaultValue="not_informed"
|
|
>
|
|
<option value="not_informed">
|
|
Não informada
|
|
</option>
|
|
<option value="confirmed">
|
|
Confirmada por fonte
|
|
</option>
|
|
<option value="unavailable">
|
|
Indisponível
|
|
</option>
|
|
<option value="reported_unverified">
|
|
Reportada, por verificar
|
|
</option>
|
|
</select>
|
|
</Field>
|
|
)}
|
|
<Field label="Regime jurídico">
|
|
<select
|
|
name="legal_regime"
|
|
className={input}
|
|
defaultValue="pending"
|
|
>
|
|
<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="Área (valor) — se documentada">
|
|
<input
|
|
name="area_value"
|
|
className={input}
|
|
type="number"
|
|
min="0"
|
|
step="0.0001"
|
|
/>
|
|
</Field>
|
|
<Field label="Unidade da área">
|
|
<select
|
|
name="area_unit"
|
|
className={input}
|
|
defaultValue=""
|
|
>
|
|
<option value="">Por confirmar</option>
|
|
<option value="ha">hectares (ha)</option>
|
|
<option value="km2">
|
|
quilómetros quadrados (km²)
|
|
</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Actividade documentada (opcional)">
|
|
<input
|
|
name="activity_name"
|
|
className={input}
|
|
maxLength={300}
|
|
/>
|
|
</Field>
|
|
<Field label="Estado da actividade">
|
|
<select
|
|
name="activity_status"
|
|
className={input}
|
|
defaultValue="potential"
|
|
>
|
|
<option value="potential">
|
|
Potencial referido pela fonte
|
|
</option>
|
|
<option value="proposed">Proposta</option>
|
|
<option value="authorized">
|
|
Autorizada por documento
|
|
</option>
|
|
<option value="conditional">Condicionada</option>
|
|
<option value="excluded">Excluída</option>
|
|
</select>
|
|
</Field>
|
|
<Field label="Designações alternativas">
|
|
<textarea
|
|
name="aliases_text"
|
|
className={input}
|
|
rows={2}
|
|
placeholder="Uma por linha"
|
|
/>
|
|
</Field>
|
|
<Field label="Localização histórica (se diferente da actual)">
|
|
<input
|
|
name="historical_name"
|
|
className={input}
|
|
maxLength={255}
|
|
/>
|
|
</Field>
|
|
<Field label="Distrito histórico">
|
|
<input
|
|
name="historical_district"
|
|
className={input}
|
|
maxLength={120}
|
|
/>
|
|
</Field>
|
|
<Field label="Província histórica">
|
|
<input
|
|
name="historical_province"
|
|
className={input}
|
|
maxLength={120}
|
|
/>
|
|
</Field>
|
|
<Field label="Fonte da localização histórica">
|
|
<input
|
|
name="historical_source_reference"
|
|
className={input}
|
|
maxLength={2000}
|
|
/>
|
|
</Field>
|
|
{error && <p role="alert">{error}</p>}
|
|
<button className={button} disabled={busy}>
|
|
Guardar rascunho
|
|
</button>
|
|
</form>
|
|
)}
|
|
</Frame>
|
|
);
|
|
}
|