768 lines
35 KiB
TypeScript
768 lines
35 KiB
TypeScript
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<Payload>; 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 <Editor key={props.submission.version} {...props} step={step} setStep={setStep} />;
|
|
}
|
|
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 = <K extends keyof Payload>(key: K, value: Payload[K]) =>
|
|
form.setData("payload", { ...form.data.payload, [key]: value });
|
|
const text = (key: keyof Payload, label: string, required = false, type = "text") => (
|
|
<Field label={label}>
|
|
<input
|
|
className={input}
|
|
type={type}
|
|
required={required}
|
|
disabled={readonly}
|
|
name={key}
|
|
min={type === "number" ? 0 : undefined}
|
|
minLength={key === "objective" ? 20 : key === "full_name" ? 3 : undefined}
|
|
onBlur={(e) => {
|
|
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}
|
|
/>
|
|
</Field>
|
|
);
|
|
const option = (
|
|
key: "profile_id" | "participation_id" | "partnership_id",
|
|
group: string,
|
|
label: string,
|
|
) => (
|
|
<Field label={label}>
|
|
<select
|
|
className={input}
|
|
disabled={readonly}
|
|
value={form.data.payload[key] ?? ""}
|
|
onChange={(e) => update(key, e.target.value)}
|
|
>
|
|
<option value="">Seleccionar</option>
|
|
{r.options
|
|
.filter(
|
|
(o) =>
|
|
o.group === group &&
|
|
(o.active || String(o.id) === String(form.data.payload[key])),
|
|
)
|
|
.map((o) => (
|
|
<option value={o.id} key={o.id} disabled={!o.active}>
|
|
{o.label}
|
|
{!o.active ? " (inactiva)" : ""}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
);
|
|
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 (
|
|
<Frame
|
|
title={
|
|
receipt ? "Manifestação " + receipt.reference : "Preparar manifestação de interesse"
|
|
}
|
|
>
|
|
<p>
|
|
{target ??
|
|
(zone_origin
|
|
? "Pedido relativo a zona de investimento"
|
|
: "Interesse geral")}{" "}
|
|
· Versão {s.version} · {s.status === "draft" ? "Rascunho privado" : "Submetido"}
|
|
</p>
|
|
{zone_origin && (
|
|
<p className={card}>
|
|
<Link className="underline" href={`/zonas/${zone_origin.zone_id}`}>
|
|
Consultar zona de origem
|
|
</Link>{" "}
|
|
· 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.
|
|
</p>
|
|
)}
|
|
{receipt && (
|
|
<p role="status" className={card}>
|
|
Protocolo: <strong>{receipt.reference}</strong> · Estado:{" "}
|
|
{(
|
|
{
|
|
received: "Recebido",
|
|
in_review: "Em análise",
|
|
contacted: "Contactado",
|
|
closed: "Encerrado",
|
|
} as Record<string, string>
|
|
)[receipt.status] ?? receipt.status}
|
|
</p>
|
|
)}
|
|
<nav aria-label="Etapas da manifestação" className="flex flex-wrap gap-2">
|
|
{["Identificação", "Investimento", "Necessidades", "Anexos", "Rever e enviar"].map(
|
|
(label, i) => (
|
|
<button
|
|
key={label}
|
|
type="button"
|
|
aria-current={step === i ? "step" : undefined}
|
|
className={step === i ? button : "rounded border px-4 py-2"}
|
|
onClick={() => setStep(i)}
|
|
>
|
|
{i + 1}. {label}
|
|
</button>
|
|
),
|
|
)}
|
|
</nav>
|
|
<p className="text-sm">
|
|
Etapa {step + 1} de 5. Guarde antes de sair. A informação declarada não é publicada.
|
|
</p>
|
|
<form
|
|
className={card + " space-y-5"}
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
form.put(base, { preserveScroll: true });
|
|
}}
|
|
>
|
|
{step === 0 && (
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{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",
|
|
)}
|
|
</div>
|
|
)}
|
|
{step === 1 && (
|
|
<div className="space-y-5">
|
|
{text(
|
|
"objective",
|
|
"Objectivo do investimento (mínimo 20 caracteres)",
|
|
true,
|
|
)}
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{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")}
|
|
</div>
|
|
<div className="grid gap-4 md:grid-cols-3">
|
|
{(["clusters", "corridors", "projects"] as const).map((group, i) => {
|
|
const key = (
|
|
["cluster_ids", "corridor_ids", "project_ids"] as const
|
|
)[i];
|
|
return (
|
|
<fieldset
|
|
className="max-h-64 space-y-2 overflow-auto rounded border p-3"
|
|
key={group}
|
|
>
|
|
<legend>
|
|
{["Clusters", "Corredores", "Projectos âncora"][i]}
|
|
</legend>
|
|
{r[group].map((entity) => (
|
|
<label key={entity.id} className="flex gap-2">
|
|
<input
|
|
type="checkbox"
|
|
disabled={readonly}
|
|
checked={(
|
|
form.data.payload[key] ?? []
|
|
).includes(entity.id)}
|
|
onChange={(e) =>
|
|
update(
|
|
key,
|
|
e.target.checked
|
|
? [
|
|
...(form.data.payload[key] ??
|
|
[]),
|
|
entity.id,
|
|
]
|
|
: form.data.payload[key].filter(
|
|
(id) => id !== entity.id,
|
|
),
|
|
)
|
|
}
|
|
/>
|
|
{entity.name}
|
|
</label>
|
|
))}
|
|
</fieldset>
|
|
);
|
|
})}
|
|
</div>
|
|
</div>
|
|
)}
|
|
{step === 2 && (
|
|
<section className="space-y-5">
|
|
<h2 className="text-xl font-bold">
|
|
Mão de obra, infraestruturas, formação e apoios
|
|
</h2>
|
|
<p>
|
|
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.
|
|
</p>
|
|
{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,
|
|
) => (
|
|
<Field label={label}>
|
|
<select
|
|
className={input}
|
|
disabled={readonly}
|
|
value={need[field] ?? ""}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
[field]: e.target.value,
|
|
...(field === "category_id"
|
|
? { option_id: "" }
|
|
: {}),
|
|
})
|
|
}
|
|
>
|
|
<option value="">Seleccionar</option>
|
|
{r.options
|
|
.filter(
|
|
(o) =>
|
|
o.group === optionGroup &&
|
|
(o.active ||
|
|
String(o.id) === String(need[field])),
|
|
)
|
|
.map((o) => (
|
|
<option value={o.id} key={o.id}>
|
|
{o.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</Field>
|
|
);
|
|
return (
|
|
<fieldset key={index} className="space-y-4 rounded-lg border p-4">
|
|
<legend className="font-bold">Necessidade {index + 1}</legend>
|
|
<div className="grid gap-4 md:grid-cols-2">
|
|
{needSelect("category_id", "need_category", "Categoria")}
|
|
{needSelect("option_id", group, "Tipo")}
|
|
{needSelect("unit_id", "unit", "Unidade")}
|
|
{needSelect("priority_id", "priority", "Prioridade")}
|
|
<Field label="Quantidade">
|
|
<input
|
|
className={input}
|
|
type="number"
|
|
min="0"
|
|
step="0.01"
|
|
disabled={readonly}
|
|
value={need.quantity ?? ""}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
quantity: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
<Field label="Prazo">
|
|
<input
|
|
className={input}
|
|
type="date"
|
|
disabled={readonly}
|
|
value={need.deadline ?? ""}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
deadline: e.target.value,
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
</div>
|
|
{(
|
|
[
|
|
"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) => (
|
|
<Field
|
|
key={field}
|
|
label={
|
|
{
|
|
description: "Descrição / especificação",
|
|
location: "Localização",
|
|
observations:
|
|
"Observações e referência dos anexos de suporte",
|
|
qualification: "Nível de qualificação",
|
|
specialty: "Profissão / especialidade",
|
|
experience: "Experiência",
|
|
certifications: "Certificações",
|
|
availability: "Disponibilidade",
|
|
institution:
|
|
"Instituições ou centros de formação",
|
|
training_mode: "Modalidade de formação",
|
|
duration: "Duração",
|
|
status: "Estado",
|
|
}[field]
|
|
}
|
|
>
|
|
<textarea
|
|
className={input}
|
|
rows={2}
|
|
disabled={readonly}
|
|
value={need.details[field] ?? ""}
|
|
onChange={(e) =>
|
|
updateNeed(index, {
|
|
...need,
|
|
details: {
|
|
...need.details,
|
|
[field]: e.target.value,
|
|
},
|
|
})
|
|
}
|
|
/>
|
|
</Field>
|
|
))}
|
|
{!readonly && (
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() =>
|
|
form.setData(
|
|
"needs",
|
|
form.data.needs.filter((_, i) => i !== index),
|
|
)
|
|
}
|
|
>
|
|
Retirar esta necessidade
|
|
</button>
|
|
)}
|
|
</fieldset>
|
|
);
|
|
})}
|
|
{!readonly && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={form.data.needs.length >= 40}
|
|
onClick={() =>
|
|
form.setData("needs", [...form.data.needs, emptyNeed()])
|
|
}
|
|
>
|
|
Acrescentar necessidade
|
|
</button>
|
|
)}
|
|
</section>
|
|
)}
|
|
{step === 3 && (
|
|
<p>
|
|
Guarde primeiro o rascunho e carregue os anexos no formulário abaixo.
|
|
Identifique o nome do ficheiro nas observações da necessidade a que
|
|
corresponde.
|
|
</p>
|
|
)}
|
|
{step === 4 && (
|
|
<section className="space-y-5">
|
|
<h2 className="text-xl font-bold">Rever antes de enviar</h2>
|
|
<dl className="space-y-3">
|
|
{[
|
|
["Investidor", form.data.payload.full_name],
|
|
["Email", form.data.payload.email],
|
|
["Organização", form.data.payload.organisation],
|
|
["Objectivo", form.data.payload.objective],
|
|
["Prazo", form.data.payload.horizon],
|
|
["Necessidades", String(form.data.needs.length)],
|
|
["Anexos", String(attachments.length)],
|
|
].map(([label, value]) => (
|
|
<div key={label}>
|
|
<dt className="font-semibold">{label}</dt>
|
|
<dd className="whitespace-pre-line">
|
|
{value || "Não indicado"}
|
|
</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
<label className="flex gap-3">
|
|
<input
|
|
type="checkbox"
|
|
disabled={readonly}
|
|
checked={form.data.payload.contact_consent}
|
|
onChange={(e) => update("contact_consent", e.target.checked)}
|
|
/>
|
|
Autorizo o tratamento destes dados e o contacto pela equipa para
|
|
analisar e acompanhar esta manifestação. Os anexos são privados. Não
|
|
constitui consentimento para utilização em IA.
|
|
</label>
|
|
</section>
|
|
)}
|
|
{r.options.some(
|
|
(o) =>
|
|
o.requires_description &&
|
|
[
|
|
form.data.payload.profile_id,
|
|
form.data.payload.participation_id,
|
|
form.data.payload.partnership_id,
|
|
]
|
|
.map(String)
|
|
.includes(String(o.id)),
|
|
) &&
|
|
text(
|
|
"other_details",
|
|
"Outro — especifique o perfil, participação ou parceria seleccionados",
|
|
true,
|
|
)}
|
|
{Object.entries(form.errors).map(([key, value]) => (
|
|
<p key={key} role="alert" className="text-red-700">
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => setStep(errorStep(key))}
|
|
>
|
|
Corrigir na etapa {errorStep(key) + 1}
|
|
</button>
|
|
: {value}
|
|
</p>
|
|
))}
|
|
{note && <p role="status">{note}</p>}
|
|
<div className="flex flex-wrap gap-4">
|
|
{step > 0 && (
|
|
<button
|
|
type="button"
|
|
className="underline"
|
|
onClick={() => setStep(step - 1)}
|
|
>
|
|
Anterior
|
|
</button>
|
|
)}
|
|
{step < 4 && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
onClick={() => {
|
|
setNote("");
|
|
setStep(step + 1);
|
|
}}
|
|
>
|
|
Continuar
|
|
</button>
|
|
)}
|
|
{!readonly && (
|
|
<button
|
|
formNoValidate
|
|
className="rounded border px-4 py-2"
|
|
disabled={form.processing}
|
|
>
|
|
Guardar rascunho
|
|
</button>
|
|
)}
|
|
{step === 4 && !readonly && (
|
|
<button
|
|
type="button"
|
|
className={button}
|
|
disabled={form.processing || !form.data.payload.contact_consent}
|
|
onClick={() =>
|
|
form.post(base + "/submit", {
|
|
preserveScroll: true,
|
|
onError: (errors) =>
|
|
setStep(errorStep(Object.keys(errors)[0] ?? "")),
|
|
})
|
|
}
|
|
>
|
|
Submeter manifestação
|
|
</button>
|
|
)}
|
|
</div>
|
|
</form>
|
|
{step === 3 && (
|
|
<section className={card + " space-y-4"}>
|
|
<h2 className="text-xl font-bold">Anexos privados</h2>
|
|
<p>
|
|
PDF ou TXT, até 10 MiB cada, máximo de dez anexos. Guardar um anexo
|
|
actualiza a versão do rascunho.
|
|
</p>
|
|
{attachments.map((a) => (
|
|
<p key={a.id}>
|
|
<a className="underline" href={base + "/attachments/" + a.id}>
|
|
{a.file_name}
|
|
</a>
|
|
</p>
|
|
))}
|
|
{!readonly && (
|
|
<form
|
|
className="space-y-4"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
if (form.isDirty) {
|
|
setNote(
|
|
"Guarde as alterações do formulário antes de carregar o anexo.",
|
|
);
|
|
return;
|
|
}
|
|
upload.post(base + "/attachments", {
|
|
forceFormData: true,
|
|
preserveScroll: true,
|
|
});
|
|
}}
|
|
>
|
|
<Field label="Documento de suporte">
|
|
<input
|
|
type="file"
|
|
accept="application/pdf,text/plain"
|
|
required
|
|
onChange={(e) =>
|
|
upload.setData("file", e.target.files?.[0] ?? null)
|
|
}
|
|
/>
|
|
</Field>
|
|
{Object.entries(upload.errors).map(([key, value]) => (
|
|
<p role="alert" key={key}>
|
|
{value}
|
|
</p>
|
|
))}
|
|
<button className={button} disabled={upload.processing}>
|
|
Carregar anexo
|
|
</button>
|
|
</form>
|
|
)}
|
|
</section>
|
|
)}
|
|
<details className={card}>
|
|
<summary className="cursor-pointer font-bold">Histórico do pedido</summary>
|
|
<ol className="mt-3 space-y-2">
|
|
{events.map((e, i) => (
|
|
<li key={i}>
|
|
{new Date(e.created_at).toLocaleString("pt-MZ")} —{" "}
|
|
{(
|
|
{
|
|
draft_created: "Rascunho criado",
|
|
draft_saved: "Rascunho guardado",
|
|
attachment_added: "Anexo acrescentado",
|
|
submitted: "Submetido",
|
|
} as Record<string, string>
|
|
)[e.action] ?? e.action}{" "}
|
|
· versão {e.version}
|
|
</li>
|
|
))}
|
|
</ol>
|
|
</details>
|
|
<Conversation
|
|
id={s.id}
|
|
messages={messages}
|
|
revisions={revisions}
|
|
submitted={s.status === "submitted"}
|
|
/>
|
|
</Frame>
|
|
);
|
|
}
|