146 lines
6.2 KiB
TypeScript
146 lines
6.2 KiB
TypeScript
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 = {
|
|
id: string;
|
|
code: string;
|
|
name: string;
|
|
category: string;
|
|
description: string | null;
|
|
province: string | null;
|
|
version_no: number;
|
|
publication_status: string;
|
|
validation_status: string;
|
|
};
|
|
export default function Zones({
|
|
records,
|
|
filters,
|
|
management,
|
|
territorySelection = [],
|
|
}: {
|
|
records: {
|
|
data: Zone[];
|
|
total: number;
|
|
next_page_url: string | null;
|
|
prev_page_url: string | null;
|
|
};
|
|
filters: { q?: string; category?: string };
|
|
management: boolean;
|
|
territorySelection?: TerritoryOption[];
|
|
}) {
|
|
const [error, setError] = useState("");
|
|
const [busy, setBusy] = useState(false);
|
|
return (
|
|
<Frame
|
|
title={management ? "Gestão de ZEE, ZFI e parques" : "ZEE, ZFI e parques industriais"}
|
|
>
|
|
<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>
|
|
<TerritoryFields initial={territorySelection} />
|
|
<button className={button}>Pesquisar</button>
|
|
</form>
|
|
<p role="status">{records.total} registos disponíveis</p>
|
|
{!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.province ?? "Localização por confirmar"}
|
|
</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>
|
|
{error && <p role="alert">{error}</p>}
|
|
<button className={button} disabled={busy}>
|
|
Guardar rascunho
|
|
</button>
|
|
</form>
|
|
)}
|
|
</Frame>
|
|
);
|
|
}
|