import { Link, router, useForm } from "@inertiajs/react"; import InvestmentTerritory from "@/components/investment-territory"; import InvestmentMapPanel from "@/components/investment-map-panel"; 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 ; } 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 ?? "", 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 (

{z.code} · {z.category.toUpperCase()} · {z.validation_status} · {z.province}{" "} {z.district}

A ficha é informativa. A associação territorial não atribui benefícios, licenças ou autorização aduaneira.

{message && (

{message}

)} {management ? ( <>
{ 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"], ] as const ).map(([key, label]) => ( form.setData(key, e.target.value)} /> ))} {( [ ["description", "Descrição PT"], ["description_en", "Descrição EN"], ] as const ).map(([key, label]) => (