import { Link, useForm } from "@inertiajs/react"; import InvestmentTerritory, { TerritoryFields } from "@/components/investment-territory"; import { Management, Field, button, control } from "../management/shared"; import { titles, statuses, stages, roles } from "./types"; import type { Structure, StructureRecord, Chain } from "./types"; import ValueNetwork from "./value-network"; import type { ChainLink, Gap } from "./value-network"; function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) { const form = useForm({ code: chain?.code ?? "", name: chain?.name ?? "", stage: chain?.stage ?? "input", }); return (
{ e.preventDefault(); const url = `/management/clusters/${clusterId}/chains`; if (chain) form.put(`${url}/${chain.id}`, { preserveScroll: true }); else form.post(url, { preserveScroll: true, onSuccess: () => form.reset(), }); }} >

{chain ? chain.name : "Nova etapa"}

form.setData("code", e.target.value)} /> form.setData("name", e.target.value)} />
); } export default function Editor({ structure, record, projects, chains, memberships, chainLinks, gaps, }: { structure: Structure; record: StructureRecord | null; projects: { id: string; name: string; code: string }[]; chains: Chain[]; chainLinks: ChainLink[]; gaps: Gap[]; memberships: { id: string; project_id: string; name: string; role: string; }[]; }) { const isProject = structure === "projects"; const form = useForm({ code: record?.code ?? "", name: record?.name ?? "", status: record?.status ?? (isProject ? "draft" : "planned"), sector: record?.sector ?? "", description: record?.description ?? "", budget_amount: record?.budget_amount ?? "", budget_currency: record?.budget_currency ?? "", start_date: record?.start_date?.slice(0, 10) ?? "", end_date: record?.end_date?.slice(0, 10) ?? "", province_id: "", district_id: "", admin_post_id: "", locality_id: "", }); const association = useForm({ project_id: "", role: "complementary" }); return ( Voltar a {titles[structure].toLowerCase()}

Registo interno de gestão. O estado activo não publica este conteúdo no portal.

{!record && ( form.setData((data) => ({ ...data, province_id: path[0]?.id ?? "", district_id: path[1]?.id ?? "", admin_post_id: path[2]?.id ?? "", locality_id: path[3]?.id ?? "", })) } /> )}
{ e.preventDefault(); if (record) form.put(`/management/${structure}/${record.id}`); else form.post(`/management/${structure}`); }} > form.setData("code", e.target.value)} /> form.setData("name", e.target.value)} /> {!isProject && ( form.setData("sector", e.target.value)} /> )} {isProject && ( <>