import { Link, useForm } from "@inertiajs/react"; import { useState } from "react"; import { Frame, Field, input, button, card } from "./shared"; import type { References } from "./shared"; import { Conversation } from "./conversation"; import type { Message } from "./conversation"; type Payload = { full_name: string; email: string; phone: string; country: string; organisation: string; representative_role: string; experience: string; investment_capacity: string; other_details: string; profile_id: string; sector: string; objective: string; participation_id: string; partnership_id: string; estimated_amount: string; currency: string; horizon: string; location: string; cluster_ids: string[]; corridor_ids: string[]; project_ids: string[]; contact_consent: boolean; }; type Need = { category_id: string; option_id: string; unit_id: string; priority_id: string; quantity: string; deadline: string; details: { description: string; location: string; observations: string; qualification: string; specialty: string; experience: string; certifications: string; availability: string; institution: string; training_mode: string; duration: string; status: string; }; }; type Props = { zone_origin?: { zone_id: string; zone_version: number; intent: "interest" | "dossier" | "meeting"; } | null; submission: { id: string; version: number; payload: Partial; status: string }; references: References; needs: Need[]; attachments: { id: string; file_name: string }[]; events: { action: string; version: number; created_at: string }[]; receipt: { reference: string; status: string } | null; target: string | null; management: boolean; messages: Message[]; revisions: { version: number; created_at: string }[]; }; const emptyNeed = (): Need => ({ category_id: "", option_id: "", unit_id: "", priority_id: "", quantity: "", deadline: "", details: { description: "", location: "", observations: "", qualification: "", specialty: "", experience: "", certifications: "", availability: "", institution: "", training_mode: "", duration: "", status: "", }, }); export default function Submission(props: Props) { const [step, setStep] = useState(0); return ; } function Editor({ zone_origin, submission: s, references: r, needs, attachments, events, receipt, target, management, messages, revisions, step, setStep, }: Props & { step: number; setStep: (step: number) => void }) { const initial: Payload = { full_name: "", email: "", phone: "", country: "", organisation: "", representative_role: "", experience: "", investment_capacity: "", other_details: "", profile_id: "", sector: "", objective: "", participation_id: "", partnership_id: "", estimated_amount: "", currency: "", horizon: "", location: "", cluster_ids: [], corridor_ids: [], project_ids: [], contact_consent: false, ...s.payload, }; const form = useForm({ version: s.version, payload: initial, needs: needs.map((n) => ({ ...emptyNeed(), ...Object.fromEntries( Object.entries(n).filter(([k]) => [ "category_id", "option_id", "unit_id", "priority_id", "quantity", "deadline", "details", ].includes(k), ), ), details: { ...emptyNeed().details, ...n.details }, })) as Need[], }); const upload = useForm<{ version: number; file: File | null }>({ version: s.version, file: null, }); const [note, setNote] = useState(""); const readonly = s.status !== "draft" || management; const base = "/investidor/manifestacoes/" + s.id; const update = (key: K, value: Payload[K]) => form.setData("payload", { ...form.data.payload, [key]: value }); const text = (key: keyof Payload, label: string, required = false, type = "text") => ( { if (!e.target.validity.valid) setNote(`Verifique o campo ${label}: ${e.target.validationMessage}`); else setNote(""); }} value={String(form.data.payload[key] ?? "")} onChange={(e) => update(key, e.target.value as never)} maxLength={key === "objective" ? 5000 : 2000} /> ); const option = ( key: "profile_id" | "participation_id" | "partnership_id", group: string, label: string, ) => ( ); const updateNeed = (index: number, value: Need) => form.setData( "needs", form.data.needs.map((n, i) => (i === index ? value : n)), ); const errorStep = (key: string) => key.startsWith("needs.") ? 2 : /payload\.(full_name|email|phone|country|profile_id|organisation|representative_role|sector|experience|investment_capacity)/.test( key, ) ? 0 : key === "payload.contact_consent" ? 4 : 1; return (

{target ?? (zone_origin ? "Pedido relativo a zona de investimento" : "Interesse geral")}{" "} · Versão {s.version} · {s.status === "draft" ? "Rascunho privado" : "Submetido"}

{zone_origin && (

Consultar zona de origem {" "} · Versão da ficha {zone_origin.zone_version} ·{" "} { { interest: "Manifestação de interesse", dossier: "Pedido de dossier", meeting: "Pedido de reunião", }[zone_origin.intent] } . Atendimento assistido, sem decisão administrativa automática.

)} {receipt && (

Protocolo: {receipt.reference} · Estado:{" "} {( { received: "Recebido", in_review: "Em análise", contacted: "Contactado", closed: "Encerrado", } as Record )[receipt.status] ?? receipt.status}

)}

Etapa {step + 1} de 5. Guarde antes de sair. A informação declarada não é publicada.

{ e.preventDefault(); form.put(base, { preserveScroll: true }); }} > {step === 0 && (
{text("full_name", "Nome completo", true)} {text("email", "Email", true, "email")} {text("phone", "Telefone")} {text("country", "País", true)} {option("profile_id", "investor_profile", "Perfil do investidor")} {text("organisation", "Organização / empresa")} {text("representative_role", "Função do representante")} {text("sector", "Sector de interesse", true)} {text("experience", "Experiência relevante")} {text( "investment_capacity", "Capacidade de investimento / especificação do perfil", )}
)} {step === 1 && (
{text( "objective", "Objectivo do investimento (mínimo 20 caracteres)", true, )}
{option( "participation_id", "participation", "Modalidade de participação", )} {option("partnership_id", "partnership", "Modelo de parceria")} {text("estimated_amount", "Investimento estimado", false, "number")} {text("currency", "Moeda (código de três letras)")} {text("horizon", "Prazo / horizonte", true)} {text("location", "Localização pretendida")}
{(["clusters", "corridors", "projects"] as const).map((group, i) => { const key = ( ["cluster_ids", "corridor_ids", "project_ids"] as const )[i]; return (
{["Clusters", "Corredores", "Projectos âncora"][i]} {r[group].map((entity) => ( ))}
); })}
)} {step === 2 && (

Mão de obra, infraestruturas, formação e apoios

Acrescente o que existe no local e o que necessita. As opções são mantidas pela gestão; use Outro para especificar casos adicionais.

{form.data.needs.map((need, index) => { const category = r.options.find((o) => String(o.id) === String(need.category_id)) ?.code ?? ""; const group = category.startsWith("labour") ? "labour" : category.startsWith("infrastructure") ? "infrastructure" : category === "education" ? "education" : "support"; const needSelect = ( field: "category_id" | "option_id" | "unit_id" | "priority_id", optionGroup: string, label: string, ) => ( ); return (
Necessidade {index + 1}
{needSelect("category_id", "need_category", "Categoria")} {needSelect("option_id", group, "Tipo")} {needSelect("unit_id", "unit", "Unidade")} {needSelect("priority_id", "priority", "Prioridade")} updateNeed(index, { ...need, quantity: e.target.value, }) } /> updateNeed(index, { ...need, deadline: e.target.value, }) } />
{( [ "description", "location", "observations", ...(group === "labour" ? [ "qualification", "specialty", "experience", "certifications", "availability", "institution", ] : []), ...(group === "education" ? [ "qualification", "institution", "training_mode", "duration", "certifications", ] : []), ] as (keyof Need["details"])[] ).map((field) => (