@@ -0,0 +1,489 @@
|
||||
import { Link, router, useForm } from "@inertiajs/react";
|
||||
import { useState } from "react";
|
||||
import { Frame, Field, input, button, card, api } from "./shared";
|
||||
import ZoneRelations from "./zone-relations";
|
||||
import ZoneMap from "./zone-map";
|
||||
import type { ZoneTargets } from "./zone-relations";
|
||||
|
||||
type Zone = {
|
||||
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;
|
||||
};
|
||||
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 Props = {
|
||||
targets: ZoneTargets | null;
|
||||
related: { id: string; title: string }[];
|
||||
relations: {
|
||||
id: string;
|
||||
version_no: number;
|
||||
association_type: string;
|
||||
validation_status: string;
|
||||
}[];
|
||||
geometries: { id: string; version_no: number; purpose: string; validation_status: string }[];
|
||||
record: Zone;
|
||||
management: boolean;
|
||||
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 }[];
|
||||
opportunities: {
|
||||
data: { id: number; title: string; slug: string }[];
|
||||
next_page_url: string | null;
|
||||
prev_page_url: string | null;
|
||||
} | null;
|
||||
};
|
||||
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,
|
||||
management,
|
||||
source,
|
||||
operator,
|
||||
operators,
|
||||
legalSources,
|
||||
links,
|
||||
revisions,
|
||||
opportunities,
|
||||
}: Props) {
|
||||
const [message, setMessage] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
const form = useForm({
|
||||
version_no: z.version_no,
|
||||
code: z.code,
|
||||
category: z.category,
|
||||
name: z.name,
|
||||
name_en: z.name_en ?? "",
|
||||
description: z.description ?? "",
|
||||
description_en: z.description_en ?? "",
|
||||
province: z.province ?? "",
|
||||
district: z.district ?? "",
|
||||
operator_id: z.operator_id ?? "",
|
||||
legal_source_id: z.legal_source_id ?? "",
|
||||
});
|
||||
async function action(url: string, data: unknown) {
|
||||
setBusy(true);
|
||||
setMessage("");
|
||||
try {
|
||||
await api(url, data);
|
||||
router.reload();
|
||||
} catch (e) {
|
||||
setMessage(e instanceof Error ? e.message : "Falha na operação.");
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<Frame title={z.name}>
|
||||
<p>
|
||||
{z.code} · {z.category.toUpperCase()} · {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 ? (
|
||||
<>
|
||||
<form
|
||||
className={card + " grid gap-4 md:grid-cols-2"}
|
||||
onSubmit={async (e) => {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setMessage("");
|
||||
try {
|
||||
await api(`/api/v2/investment/admin/zones/${z.id}`, {
|
||||
...form.data,
|
||||
_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"],
|
||||
["province", "Província"],
|
||||
["district", "Distrito"],
|
||||
] 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>
|
||||
{(
|
||||
[
|
||||
["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>
|
||||
))}
|
||||
<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} className={button}>
|
||||
Guardar rascunho
|
||||
</button>
|
||||
</form>
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-bold">Revisão independente</h2>
|
||||
<p>
|
||||
Versão {z.version_no}. Outra pessoa gestora deve rever antes da
|
||||
publicação. Guarde primeiro as alterações.
|
||||
</p>
|
||||
<div className="flex gap-4">
|
||||
<button
|
||||
className={button}
|
||||
disabled={busy || form.isDirty}
|
||||
onClick={() =>
|
||||
action(`/api/v2/investment/admin/zones/${z.id}/publish`, {
|
||||
version_no: z.version_no,
|
||||
})
|
||||
}
|
||||
>
|
||||
Validar e publicar
|
||||
</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>
|
||||
<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}
|
||||
</p>
|
||||
))}
|
||||
</section>
|
||||
{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>
|
||||
<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>
|
||||
{source && (
|
||||
<section className={card}>
|
||||
<h2 className="text-xl font-bold">Fonte e vigência</h2>
|
||||
<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={`/oportunidades/${o.slug}?zone_id=${z.id}`}
|
||||
>
|
||||
{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={`/carteira/${r.id}`}>
|
||||
{r.title}
|
||||
</Link>
|
||||
</p>
|
||||
))}
|
||||
{!related.length && <p>Sem relações territoriais publicadas.</p>}
|
||||
</section>
|
||||
</>
|
||||
)}
|
||||
</Frame>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user