resolvemos o problema dos ZEE e ZFI
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-10-07 19:46:35 +02:00
parent 0a086c3fa5
commit bdd766c68a
74 changed files with 6401 additions and 32 deletions
@@ -0,0 +1,179 @@
import { Link, router } from "@inertiajs/react";
import { useState } from "react";
import InteractiveInvestmentMap, {
type InvestmentMapFeature,
} from "@/components/interactive-investment-map";
import {
Frame,
Field,
control,
button,
type Catalogues,
type Partnership,
} from "./shared";
type Result = Pick<
Partnership,
"id" | "title" | "kind" | "partnership_type" | "deadline"
> & { summary: string | null; province: string; sector: string };
export default function Catalogue(
p: Catalogues & {
results: {
data: Result[];
total: number;
prev_page_url: string | null;
next_page_url: string | null;
};
filters: Record<string, string>;
mapPoints: InvestmentMapFeature[];
},
) {
const [filters, setFilters] = useState(p.filters);
const set = (key: string, value: string) =>
setFilters({ ...filters, [key]: value });
return (
<Frame title="Bolsa de Parcerias">
<p className="mb-5">
Explore ofertas e procuras de colaboração. Pode preparar uma
ideia com os dados disponíveis; a publicação passa por
moderação.
</p>
<form
className="grid gap-4 rounded border p-5 md:grid-cols-3"
onSubmit={(e) => {
e.preventDefault();
router.get("/parcerias", filters);
}}
>
<Field label="Pesquisar">
<input
className={control}
value={filters.q ?? ""}
onChange={(e) => set("q", e.target.value)}
/>
</Field>
<Field label="Tipo de parceria">
<select
className={control}
value={filters.partnership_type ?? ""}
onChange={(e) =>
set("partnership_type", e.target.value)
}
>
<option value="">Todos</option>
{Object.entries(p.types).map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
))}
</select>
</Field>
<Field label="Oferta ou procura">
<select
className={control}
value={filters.kind ?? ""}
onChange={(e) => set("kind", e.target.value)}
>
<option value="">Ambas</option>
<option value="offering">Oferta</option>
<option value="seeking">Procura</option>
</select>
</Field>
<Field label="Setor">
<select
className={control}
value={filters.sector_id ?? ""}
onChange={(e) => set("sector_id", e.target.value)}
>
<option value="">Todos</option>
{p.sectors.map((x) => (
<option key={x.id} value={x.id}>
{x.name}
</option>
))}
</select>
</Field>
<Field label="Território">
<select
className={control}
value={filters.territory_id ?? ""}
onChange={(e) => set("territory_id", e.target.value)}
>
<option value="">Todos</option>
{p.territories.map((x) => (
<option key={x.id} value={x.id}>
{x.name} · {x.location_type}
</option>
))}
</select>
</Field>
<div className="self-end">
<button className={button}>Pesquisar parcerias</button>
</div>
</form>
<p className="my-5">{p.results.total} parcerias publicadas</p>
<div className="grid gap-5 md:grid-cols-2">
{p.results.data.map((item) => (
<article
key={item.id}
className="space-y-3 rounded border p-5"
>
<h2 className="text-xl font-bold">
<Link href={"/parcerias/" + item.id}>
{item.title}
</Link>
</h2>
<p>
{item.partnership_type
? p.types[item.partnership_type]
: "Tipo por completar"}{" "}
· {item.kind === "offering" ? "Oferta" : "Procura"}
</p>
<p>{item.summary}</p>
<p>
{item.sector || "Setor por completar"} ·{" "}
{item.province || "Território na ficha"}
</p>
{item.deadline && <p>Prazo: {item.deadline}</p>}
<Link
href={"/parcerias/" + item.id}
className="underline"
>
Consultar parceria
</Link>
</article>
))}
</div>
{!p.results.data.length && (
<p className="my-8">
Nenhuma parceria corresponde aos filtros.
</p>
)}
<section className="my-6 space-y-3 rounded border p-5">
<h2 className="text-xl font-bold">
Mapa dos resultados desta página
</h2>
<p>
Localizações próprias e contexto documental das origens são
identificados separadamente. Um cluster pode apresentar
vários locais dos membros; estes pontos não confirmam a
implantação da parceria.
</p>
<InteractiveInvestmentMap points={p.mapPoints} />
{!p.mapPoints.length && (
<p>
Sem coordenadas documentadas nos resultados. As fichas e
os filtros territoriais continuam disponíveis.
</p>
)}
</section>
<nav className="mt-6 flex gap-4">
{p.results.prev_page_url && (
<Link href={p.results.prev_page_url}>Anterior</Link>
)}
{p.results.next_page_url && (
<Link href={p.results.next_page_url}>Seguinte</Link>
)}
</nav>
</Frame>
);
}
@@ -0,0 +1,124 @@
import { Link, router } from "@inertiajs/react";
import { Frame, labels, button, type Partnership } from "./shared";
type Props = {
mine: Pick<Partnership, "id" | "title" | "status">[];
interests: {
id: number;
partnership_id: number;
title: string;
status: string;
decision_reason: string | null;
room_id: number | null;
}[];
moderation: Pick<Partnership, "id" | "title" | "status">[];
notifications: {
id: number;
title: string;
href: string;
read_at: string | null;
}[];
};
export default function Dashboard(p: Props) {
return (
<Frame title="O meu painel de parcerias">
<div className="space-y-8">
<section>
<h2 className="mb-4 text-xl font-bold">
Ideias e propostas
</h2>
<Link className={button} href="/parcerias/criar">
Preparar uma parceria
</Link>
{p.mine.map((x) => (
<article className="mt-4 rounded border p-4" key={x.id}>
<Link
className="font-semibold underline"
href={"/parcerias/" + x.id}
>
{x.title || "Ideia sem título"}
</Link>
<p>{labels[x.status] ?? x.status}</p>
<p>
Próxima ação:{" "}
{["draft", "returned", "rejected"].includes(
x.status,
)
? "Completar e pré-visualizar para submissão"
: x.status === "published"
? "Consultar candidatos e esclarecer pendências"
: "Acompanhar a decisão"}
</p>
</article>
))}
</section>
<section>
<h2 className="text-xl font-bold">
As minhas candidaturas
</h2>
{p.interests.map((x) => (
<article className="my-4 rounded border p-4" key={x.id}>
<Link
className="underline"
href={"/parcerias/" + x.partnership_id}
>
{x.title}
</Link>
<p>
{labels[x.status]} · {x.decision_reason}
</p>
{x.room_id && (
<Link
className={button}
href={"/parcerias/salas/" + x.room_id}
>
Abrir conexão privada
</Link>
)}
</article>
))}
</section>
{p.moderation.length > 0 && (
<section>
<h2 className="text-xl font-bold">Fila de moderação</h2>
{p.moderation.map((x) => (
<p key={x.id}>
<Link
className="underline"
href={"/parcerias/" + x.id}
>
{x.title} · {labels[x.status]}
</Link>
</p>
))}
</section>
)}
<section>
<h2 className="text-xl font-bold">
Notificações no portal
</h2>
{p.notifications.map((n) => (
<article className="my-3 rounded border p-3" key={n.id}>
<Link href={n.href} className="underline">
{n.title}
</Link>
{!n.read_at && (
<button
className="ml-4 underline"
onClick={() =>
router.post(
"/parcerias/notificacoes/" +
n.id +
"/ler",
)
}
>
Marcar como lida
</button>
)}
</article>
))}
</section>
</div>
</Frame>
);
}
+628
View File
@@ -0,0 +1,628 @@
import { Link, useForm, usePage } from "@inertiajs/react";
import StructureGeographyPanel, {
type StructureGeography,
} from "@/components/structure-geography";
import {
Frame,
Errors,
Field,
control,
button,
labels,
type Catalogues,
type Interest,
type Partnership,
type Source,
} from "./shared";
type Props = Catalogues & {
record: Partnership;
owner: boolean;
canEdit: boolean;
moderator: boolean;
origins: (Source & { geography: StructureGeography | null })[];
locations: {
id: string;
name: string;
role: string;
source_reference: string;
path: { name: string }[];
}[];
interests: Interest[];
history: {
event_type: string;
actor_id: number;
occurred_at: string;
payload: string;
}[];
};
function Publication({ p }: { p: Props }) {
const form = useForm({ version: p.record.version, action: "", reason: "" });
const action = (value: string) => {
form.transform((data) => ({ ...data, action: value }));
form.post("/parcerias/" + p.record.id + "/estado", {
preserveScroll: true,
});
};
return (
<section className="space-y-4 rounded border p-5">
<h2 className="text-xl font-bold">Pré-visualização e publicação</h2>
<p>
Estado: {labels[p.record.status] ?? p.record.status}.
Verificação da organização, setor e localização permanecem por
confirmar quando não há evidência.
</p>
<Field label="Motivo da ação">
<textarea
className={control}
value={form.data.reason}
onChange={(e) => form.setData("reason", e.target.value)}
/>
</Field>
<Errors errors={form.errors} />
<div className="flex flex-wrap gap-3">
{p.canEdit &&
["draft", "returned", "rejected"].includes(
p.record.status,
) && (
<button
className={button}
disabled={form.processing || !form.data.reason}
onClick={() => action("submit")}
>
Submeter para publicação
</button>
)}
{p.moderator &&
!p.owner &&
["submitted", "pending"].includes(p.record.status) &&
["publish", "return", "reject"].map((value) => (
<button
className={button}
key={value}
disabled={form.processing || !form.data.reason}
onClick={() => action(value)}
>
{
{
publish: "Publicar",
return: "Devolver para correção",
reject: "Rejeitar com fundamento",
}[value]
}
</button>
))}
{p.canEdit &&
["published", "suspended", "archived"].includes(
p.record.status,
) && (
<button
className={button}
disabled={form.processing || !form.data.reason}
onClick={() => action("renew")}
>
Renovar em rascunho
</button>
)}
{p.canEdit &&
["draft", "published", "suspended", "rejected"].includes(
p.record.status,
) && (
<button
className={button}
disabled={form.processing || !form.data.reason}
onClick={() => action("archive")}
>
Arquivar publicação
</button>
)}
{p.canEdit && (
<Link
className="underline"
href={"/parcerias/" + p.record.id + "/editar"}
>
Editar rascunho
</Link>
)}
</div>
</section>
);
}
function InterestForm({
record,
interest,
organizations,
}: {
record: Partnership;
interest?: Interest;
organizations: Catalogues["organizations"];
}) {
const form = useForm({
version: interest?.version ?? null,
organization_id: interest?.organization_id ?? "",
proposal: interest?.proposal ?? "",
payload: {
capacity: interest?.payload.capacity ?? "",
availability: interest?.payload.availability ?? "",
contribution: interest?.payload.contribution ?? "",
conflicts: interest?.payload.conflicts ?? "",
consent: interest?.payload.consent ?? false,
},
});
return (
<form
className="space-y-4 rounded border p-5"
onSubmit={(e) => {
e.preventDefault();
form.post("/parcerias/" + record.id + "/interesses", {
preserveScroll: true,
});
}}
>
<h2 className="text-xl font-bold">
{interest
? "Atualizar manifestação de interesse"
: "Manifestar interesse"}
</h2>
<p>
Declarações são informações comunicadas por si; não atribuem
verificação. Dados desconhecidos podem ser esclarecidos no
processo.
</p>
<Errors errors={form.errors} />
<Field label="Participação">
<select
className={control}
value={form.data.organization_id}
onChange={(e) =>
form.setData("organization_id", e.target.value)
}
>
<option value="">Participação pessoal</option>
{organizations.map((o) => (
<option key={o.id} value={o.id}>
{o.name}
</option>
))}
</select>
</Field>
<Field label="Proposta curta">
<textarea
className={control}
value={form.data.proposal}
onChange={(e) => form.setData("proposal", e.target.value)}
/>
</Field>
{(
[
"capacity",
"availability",
"contribution",
"conflicts",
] as const
).map((key) => (
<Field
key={key}
label={
{
capacity: "Capacidade disponível",
availability: "Disponibilidade",
contribution: "Contribuição proposta",
conflicts: "Conflitos de interesse declarados",
}[key]
}
>
<textarea
className={control}
value={form.data.payload[key]}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
[key]: e.target.value,
})
}
/>
</Field>
))}
<label className="block">
<input
type="checkbox"
checked={form.data.payload.consent}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
consent: e.target.checked,
})
}
/>{" "}
Autorizo a partilha desta candidatura com o responsável pela
parceria.
</label>
<button className={button} disabled={form.processing}>
Guardar interesse
</button>
</form>
);
}
function Candidacy({
interest,
owner,
canEdit,
record,
organizations,
}: {
interest: Interest;
owner: boolean;
canEdit: boolean;
record: Partnership;
organizations: Catalogues["organizations"];
}) {
const assessment = Object.fromEntries(
interest.match.criteria.map((c) => [
c.code,
{
state: interest.assessment[c.code]?.state ?? "unknown",
evidence: interest.assessment[c.code]?.evidence ?? "",
},
]),
);
const form = useForm({
version: interest.version,
action: "",
reason: "",
assessment,
});
const act = (action: string) => {
form.transform((data) => ({
...data,
action,
assessment: action === "assess" ? data.assessment : {},
}));
form.post("/parcerias/candidaturas/" + interest.id, {
preserveScroll: true,
});
};
return (
<article className="space-y-4 rounded border p-5">
<h3 className="text-lg font-bold">
Candidatura {interest.id} · {labels[interest.status]}
</h3>
<p>{interest.proposal}</p>
<p>{interest.payload.capacity}</p>
<p>
Disponibilidade:{" "}
{interest.payload.availability || "Por esclarecer"}
</p>
<p>
Contribuição:{" "}
{interest.payload.contribution || "Por esclarecer"}
</p>
<p>
Conflitos declarados:{" "}
{interest.payload.conflicts || "Sem informação"}
</p>
{interest.decision_reason && (
<p>Última decisão: {interest.decision_reason}</p>
)}
<p>
Correspondência: {interest.match.score_min}–
{interest.match.score_max}% · Elegibilidade:{" "}
{labels[interest.match.eligibility]}. O intervalo distingue
dados desconhecidos de incumprimentos; não é uma aprovação.
</p>
<ul className="space-y-2">
{interest.match.criteria.map((c) => (
<li key={c.code}>
{c.label} · peso {c.weight} · {labels[c.state]}
{c.mandatory ? " · Obrigatório" : ""}
{c.evidence && <> · Evidência: {c.evidence}</>}
<p className="text-sm">{c.explanation}</p>
</li>
))}
</ul>
{interest.room_id && (
<Link
className={button}
href={"/parcerias/salas/" + interest.room_id}
>
Abrir conexão privada
</Link>
)}
{owner &&
canEdit &&
["submitted", "clarification", "shortlisted"].includes(
interest.status,
) && (
<>
<details className="space-y-4">
<summary>Registar avaliação fundamentada</summary>
{interest.match.criteria.map((c) => (
<div
className="my-3 grid gap-3 md:grid-cols-2"
key={c.code}
>
<Field label={c.label}>
<select
className={control}
value={
form.data.assessment[c.code]
.state
}
onChange={(e) =>
form.setData("assessment", {
...form.data.assessment,
[c.code]: {
...form.data.assessment[
c.code
],
state: e.target.value,
},
})
}
>
{["unknown", "met", "unmet"].map(
(state) => (
<option
key={state}
value={state}
>
{labels[state]}
</option>
),
)}
</select>
</Field>
<Field label="Referência da evidência">
<input
className={control}
value={
form.data.assessment[c.code]
.evidence
}
onChange={(e) =>
form.setData("assessment", {
...form.data.assessment,
[c.code]: {
...form.data.assessment[
c.code
],
evidence:
e.target.value,
},
})
}
/>
</Field>
</div>
))}
</details>
<Field label="Motivo da decisão ou pedido de esclarecimento">
<textarea
className={control}
value={form.data.reason}
onChange={(e) =>
form.setData("reason", e.target.value)
}
/>
</Field>
<div className="flex flex-wrap gap-3">
{[
"assess",
"clarify",
"shortlist",
"reject",
...(interest.status === "shortlisted"
? ["connect"]
: []),
].map((action) => (
<button
key={action}
className={button}
disabled={
form.processing || !form.data.reason
}
onClick={() => act(action)}
>
{
{
assess: "Guardar avaliação",
clarify: "Pedir esclarecimento",
shortlist:
"Adicionar à lista curta",
reject: "Não selecionar",
connect: "Abrir negociação",
}[action]
}
</button>
))}
</div>
</>
)}
{!owner &&
["submitted", "clarification", "shortlisted"].includes(
interest.status,
) && (
<>
<Field label="Motivo da retirada">
<textarea
className={control}
value={form.data.reason}
onChange={(e) =>
form.setData("reason", e.target.value)
}
/>
</Field>
<button
className={button}
disabled={form.processing || !form.data.reason}
onClick={() => act("withdraw")}
>
Retirar candidatura
</button>
</>
)}
{!owner &&
["submitted", "clarification", "withdrawn"].includes(
interest.status,
) && (
<InterestForm
record={record}
interest={interest}
organizations={organizations}
/>
)}
<Errors errors={form.errors} />
</article>
);
}
export default function Detail(p: Props) {
const { auth } = usePage<{ auth: { user: unknown } }>().props;
return (
<Frame title={p.record.title || "Pré-visualização da ideia"}>
<div className="space-y-6">
<p>
{p.record.partnership_type
? p.types[p.record.partnership_type]
: "Tipo por completar"}{" "}
· {p.record.kind === "offering" ? "Oferta" : "Procura"} ·{" "}
{labels[p.record.status] ?? p.record.status}
</p>
<p className="whitespace-pre-wrap">
{p.record.payload.summary}
</p>
<section className="space-y-3 rounded border p-5">
<h2 className="text-xl font-bold">Oferta e procura</h2>
<p className="whitespace-pre-wrap">{p.record.offer}</p>
<p className="whitespace-pre-wrap">{p.record.seeking}</p>
{p.record.offer === null && (
<p>
O conteúdo detalhado está reservado à conexão
privada.
</p>
)}
<p>{p.record.payload.requirements}</p>
<p>Prazo: {p.record.deadline ?? "Por definir"}</p>
</section>
<section className="space-y-3 rounded border p-5">
<h2 className="text-xl font-bold">
Localizações próprias da parceria
</h2>
{p.locations.length ? (
p.locations.map((l, i) => (
<p key={i}>
{l.path.map((n) => n.name).join(" → ")} ·{" "}
{
{
primary: "Principal",
operating: "Área de atuação",
coverage: "Abrangência",
}[l.role]
}{" "}
· Fonte: {l.source_reference}. Validação
independente pendente.
</p>
))
) : (
<p>Localização própria não indicada.</p>
)}
</section>
{p.origins.map((source, i) => (
<section key={i} className="space-y-3 rounded border p-5">
<h2 className="text-xl font-bold">
Origem:{" "}
<Link className="underline" href={source.href}>
{source.title}
</Link>
</h2>
<p>
As localizações do registo de origem são contexto
documental; não confirmam a implantação da parceria.
</p>
{source.geography && (
<StructureGeographyPanel
geography={source.geography}
cluster={source.type === "cluster"}
dossierId={"partnership-source-" + i}
/>
)}
</section>
))}
{(p.owner || p.moderator) && (
<Publication key={p.record.version} p={p} />
)}
{p.owner && p.interests.length > 0 && (
<section className="overflow-x-auto rounded border p-4">
<h2 className="text-xl font-bold">
Comparação de candidatos
</h2>
<table className="w-full text-left">
<thead>
<tr>
<th>Candidatura</th>
<th>Estado</th>
<th>Correspondência</th>
<th>Pendências</th>
</tr>
</thead>
<tbody>
{p.interests.map((i) => (
<tr key={i.id}>
<td>{i.id}</td>
<td>{labels[i.status]}</td>
<td>
{i.match.score_min}–
{i.match.score_max}%
</td>
<td>
{i.match.criteria
.filter(
(c) =>
c.state === "unknown",
)
.map((c) => c.label)
.join(", ")}
</td>
</tr>
))}
</tbody>
</table>
</section>
)}
{p.interests.map((i) => (
<Candidacy
key={i.id + ":" + i.version}
interest={i}
owner={p.owner}
canEdit={p.canEdit}
record={p.record}
organizations={p.organizations}
/>
))}
{!p.owner &&
p.record.status === "published" &&
auth.user &&
!p.interests.length && (
<InterestForm
record={p.record}
organizations={p.organizations}
/>
)}
{!auth.user && p.record.status === "published" && (
<Link className={button} href="/login">
Entrar para manifestar interesse
</Link>
)}
{p.history.length > 0 && (
<details>
<summary>Histórico e decisões</summary>
{p.history.map((h, i) => (
<p key={i}>
{h.occurred_at} · Autor {h.actor_id} ·{" "}
{h.event_type}
</p>
))}
</details>
)}
</div>
</Frame>
);
}
+447
View File
@@ -0,0 +1,447 @@
import { Link, useForm } from "@inertiajs/react";
import { useState } from "react";
import {
Frame,
Field,
Errors,
control,
button,
type Partnership,
type Catalogues,
} from "./shared";
type Location = {
geo_location_id: string;
role: string;
source_reference: string;
};
type Origin = { type: string; target_id: string };
type Props = Catalogues & {
record: Partnership | null;
locations: Location[];
origins: Origin[];
};
function Editor(p: Props) {
const form = useForm({
client_key: crypto.randomUUID(),
version: p.record?.version ?? null,
title: p.record?.title ?? "",
offer: p.record?.offer ?? "",
seeking: p.record?.seeking ?? "",
organization_id: p.record?.organization_id ?? "",
sector_id: p.record?.sector_id?.toString() ?? "",
kind: p.record?.kind ?? "seeking",
partnership_type: p.record?.partnership_type ?? "",
deadline: p.record?.deadline ?? "",
payload: {
summary: p.record?.payload.summary ?? "",
requirements: p.record?.payload.requirements ?? "",
mandatory: p.record?.payload.mandatory ?? ([] as string[]),
confidentiality: p.record?.payload.confidentiality ?? "public",
consent: p.record?.payload.consent ?? false,
},
locations: p.locations.map((x) => ({
geo_location_id: x.geo_location_id,
role: x.role,
source_reference: x.source_reference,
})),
origins: p.origins.map((x) => ({
type: x.type,
target_id: x.target_id,
})),
});
const [place, setPlace] = useState("");
const [role, setRole] = useState("primary");
const [source, setSource] = useState("Declaração do proponente");
const [origin, setOrigin] = useState("");
return (
<Frame title={p.record ? "Editar parceria" : "Preparar parceria"}>
<p className="mb-5">
Guarde uma ideia e retome-a no seu painel. Empresa constituída,
NUIT, documentos e verificação não são exigidos para preparar o
rascunho. As informações desconhecidas ficam pendentes.
</p>
<form
className="space-y-5"
onSubmit={(e) => {
e.preventDefault();
if (p.record) form.put("/parcerias/" + p.record.id);
else form.post("/parcerias/rascunhos");
}}
>
<Errors errors={form.errors} />
<Field label="Título">
<input
className={control}
value={form.data.title}
onChange={(e) => form.setData("title", e.target.value)}
/>
</Field>
<div className="grid gap-5 md:grid-cols-2">
<Field label="Participação">
<select
className={control}
value={form.data.organization_id}
onChange={(e) =>
form.setData("organization_id", e.target.value)
}
>
<option value="">
Ideia pessoal — sem organização indicada
</option>
{p.organizations.map((x) => (
<option key={x.id} value={x.id}>
{x.name}
</option>
))}
</select>
</Field>
<Field label="Oferta ou procura">
<select
className={control}
value={form.data.kind}
onChange={(e) =>
form.setData("kind", e.target.value)
}
>
<option value="seeking">Procura</option>
<option value="offering">Oferta</option>
</select>
</Field>
<Field label="Tipo de parceria">
<select
className={control}
value={form.data.partnership_type}
onChange={(e) =>
form.setData("partnership_type", e.target.value)
}
>
<option value="">Por definir</option>
{Object.entries(p.types).map(([k, v]) => (
<option key={k} value={k}>
{v}
</option>
))}
</select>
</Field>
<Field label="Setor">
<select
className={control}
value={form.data.sector_id}
onChange={(e) =>
form.setData("sector_id", e.target.value)
}
>
<option value="">Por definir</option>
{p.sectors.map((x) => (
<option key={x.id} value={x.id}>
{x.name}
</option>
))}
</select>
</Field>
</div>
<Field label="Resumo público">
<textarea
className={control}
value={form.data.payload.summary}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
summary: e.target.value,
})
}
/>
</Field>
<Field label="O que oferece">
<textarea
className={control}
value={form.data.offer}
onChange={(e) => form.setData("offer", e.target.value)}
/>
</Field>
<Field label="O que procura">
<textarea
className={control}
value={form.data.seeking}
onChange={(e) =>
form.setData("seeking", e.target.value)
}
/>
</Field>
<Field label="Requisitos e critérios desejáveis">
<textarea
className={control}
value={form.data.payload.requirements}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
requirements: e.target.value,
})
}
/>
</Field>
<fieldset className="space-y-2 rounded border p-4">
<legend>
Critérios obrigatórios expressos da proposta
</legend>
<p>
Marque apenas condições necessárias. Critérios
desejáveis servem a pontuação. Informação desconhecida
exige esclarecimento e não constitui incumprimento
comprovado.
</p>
{Object.entries(p.criteria).map(([k, v]) => (
<label className="block" key={k}>
<input
type="checkbox"
checked={form.data.payload.mandatory.includes(
k,
)}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
mandatory: e.target.checked
? [
...form.data.payload
.mandatory,
k,
]
: form.data.payload.mandatory.filter(
(x) => x !== k,
),
})
}
/>{" "}
{v}
</label>
))}
</fieldset>
<div className="grid gap-4 md:grid-cols-2">
<Field label="Prazo para interesses">
<input
type="date"
className={control}
value={form.data.deadline}
onChange={(e) =>
form.setData("deadline", e.target.value)
}
/>
</Field>
<Field label="Visibilidade do conteúdo detalhado">
<select
className={control}
value={form.data.payload.confidentiality}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
confidentiality: e.target.value,
})
}
>
<option value="public">
Público após moderação
</option>
<option value="private">
Resumo público; detalhes privados
</option>
</select>
</Field>
</div>
<section className="space-y-4 rounded border p-5">
<h2 className="font-bold">Localizações e abrangência</h2>
<p>
A localização de uma origem fica como contexto. Só
acrescente uma localização própria com fonte; não se
deduz por proximidade ou pertença a cluster.
</p>
<div className="grid gap-3 md:grid-cols-3">
<Field label="Localização do cadastro">
<select
className={control}
value={place}
onChange={(e) => setPlace(e.target.value)}
>
<option value="">Escolher território</option>
{p.territories.map((x) => (
<option key={x.id} value={x.id}>
{x.name} · {x.location_type}
</option>
))}
</select>
</Field>
<Field label="Papel">
<select
className={control}
value={role}
onChange={(e) => setRole(e.target.value)}
>
<option value="primary">Principal</option>
<option value="operating">
Área de atuação
</option>
<option value="coverage">Abrangência</option>
</select>
</Field>
<Field label="Fonte da localização">
<input
className={control}
value={source}
onChange={(e) => setSource(e.target.value)}
/>
</Field>
</div>
<button
type="button"
className={button}
disabled={!place || !source}
onClick={() => {
if (
!form.data.locations.some(
(x) =>
x.geo_location_id === place &&
x.role === role,
)
)
form.setData("locations", [
...form.data.locations,
{
geo_location_id: place,
role,
source_reference: source,
},
]);
}}
>
Acrescentar localização
</button>
{form.data.locations.map((l, i) => (
<p key={i}>
{
p.territories.find(
(t) => t.id === l.geo_location_id,
)?.name
}{" "}
· {l.role} · {l.source_reference}{" "}
<button
type="button"
className="underline"
onClick={() =>
form.setData(
"locations",
form.data.locations.filter(
(_, j) => j !== i,
),
)
}
>
Remover
</button>
</p>
))}
</section>
<section className="space-y-3 rounded border p-5">
<h2 className="font-bold">Registos de origem</h2>
<Field label="Adicionar origem existente">
<select
className={control}
value={origin}
onChange={(e) => setOrigin(e.target.value)}
>
<option value="">
Escolher empresa, investimento, projeto,
cluster, zona ou ficha
</option>
{p.sources?.map((x) => (
<option
key={x.type + ":" + x.target_id}
value={x.type + ":" + x.target_id}
>
{x.title}
</option>
))}
</select>
</Field>
<button
type="button"
className={button}
disabled={!origin}
onClick={() => {
const [type, target_id] = origin.split(":");
if (
!form.data.origins.some(
(x) =>
x.type === type &&
x.target_id === target_id,
)
)
form.setData("origins", [
...form.data.origins,
{ type, target_id },
]);
}}
>
Ligar origem
</button>
{form.data.origins.map((o, i) => (
<p key={i}>
{p.sources?.find(
(x) =>
x.type === o.type &&
x.target_id === o.target_id,
)?.title ?? "Origem documental ligada"}{" "}
<button
type="button"
className="underline"
onClick={() =>
form.setData(
"origins",
form.data.origins.filter(
(_, j) => j !== i,
),
)
}
>
Remover
</button>
</p>
))}
</section>
<label className="block">
<input
type="checkbox"
checked={form.data.payload.consent}
onChange={(e) =>
form.setData("payload", {
...form.data.payload,
consent: e.target.checked,
})
}
/>{" "}
Autorizo submeter o conteúdo indicado para divulgação no
âmbito escolhido. Não confirma verificação ou certificação.
</label>
<div className="flex flex-wrap gap-4">
<button className={button} disabled={form.processing}>
Guardar rascunho
</button>
{p.record && (
<Link
className="underline"
href={"/parcerias/" + p.record.id}
>
Pré-visualizar e submeter
</Link>
)}
</div>
</form>
</Frame>
);
}
export default function Page(p: Props) {
return (
<Editor
key={`${p.record?.id ?? "new"}:${p.record?.version ?? 0}`}
{...p}
/>
);
}
@@ -0,0 +1,74 @@
import { useForm, Link } from "@inertiajs/react";
import { Management } from "../management/shared";
import { Errors, button, labels } from "./shared";
type Props = {
hash: string;
installed: boolean;
target: { database: string; port: number };
records: { id: number; title: string; user_id: number; status: string }[];
backupVerified: boolean;
qaVerified: boolean;
backupDate: string | null;
changes: string[];
};
export default function Installation(p: Props) {
const form = useForm({ hash: p.hash });
return (
<Management title="Aplicação da Bolsa de Parcerias">
<div className="space-y-5">
<p>
Destino: {p.target.database}:{p.target.port}. Estado:{" "}
{p.installed
? "Instalada"
: "Preparada para aplicação autenticada"}
.
</p>
<p>
Backup e restauro:{" "}
{p.backupVerified ? "Comprovados" : "Pendentes"} ·{" "}
{p.backupDate}. QA desta versão:{" "}
{p.qaVerified ? "Comprovada" : "Pendente"}.
</p>
<ul className="list-disc pl-5">
{p.changes.map((change) => (
<li key={change}>{change}</li>
))}
</ul>
<h2 className="text-xl font-bold">
Propostas antigas a preservar: {p.records.length}
</h2>
{p.records.map((record) => (
<p key={record.id}>
{record.id} · {record.title} · Autor {record.user_id} ·{" "}
{labels[record.status] ?? record.status}
</p>
))}
{!p.installed && (
<form
onSubmit={(e) => {
e.preventDefault();
form.post("/management/partnerships-install");
}}
>
<Errors errors={form.errors} />
<button
className={button}
disabled={
form.processing ||
!p.backupVerified ||
!p.qaVerified
}
>
Aplicar módulo preservando propostas
</button>
</form>
)}
{p.installed && (
<Link href="/parcerias/painel" className="underline">
Abrir painel da Bolsa
</Link>
)}
</div>
</Management>
);
}
+505
View File
@@ -0,0 +1,505 @@
import { useForm, usePage, Link, router } from "@inertiajs/react";
import {
Frame,
Field,
Errors,
control,
button,
labels,
type Partnership,
} from "./shared";
type Room = {
id: number;
status: string;
version: number;
agreement: {
title: string;
terms: string;
confirmations: Record<string, { actor_id: number; date: string }>;
legal_signature_status: string;
} | null;
};
type Milestone = {
id: number;
title: string;
responsible_id: number;
due_date: string | null;
status: string;
evidence: string | null;
version: number;
};
type Props = {
room: Room;
partnership: Partnership & { user_id: number };
interest: { id: number; user_id: number };
canWrite: boolean;
messages: {
id: number;
name: string;
author_id: number;
body: string;
created_at: string;
}[];
documents: {
id: number;
owner_id: number;
file_name: string;
shared: boolean;
status: string;
malware_scan_status: string;
}[];
milestones: Milestone[];
};
function MilestoneForm({ p, item }: { p: Props; item?: Milestone }) {
const form = useForm({
title: item?.title ?? "",
responsible_id: item?.responsible_id ?? p.partnership.user_id,
due_date: item?.due_date ?? "",
status: item?.status ?? "pending",
evidence: item?.evidence ?? "",
version: item?.version ?? null,
});
return (
<form
className="space-y-3 rounded border p-4"
onSubmit={(e) => {
e.preventDefault();
if (item)
form.put(
`/parcerias/salas/${p.room.id}/marcos/${item.id}`,
{ preserveScroll: true },
);
else
form.post(`/parcerias/salas/${p.room.id}/marcos`, {
preserveScroll: true,
});
}}
>
<h3 className="font-bold">
{item ? "Atualizar marco" : "Acrescentar marco"}
</h3>
<Field label="Entregável">
<input
className={control}
value={form.data.title}
onChange={(e) => form.setData("title", e.target.value)}
/>
</Field>
<Field label="Responsável">
<select
className={control}
value={form.data.responsible_id}
onChange={(e) =>
form.setData("responsible_id", Number(e.target.value))
}
>
<option value={p.partnership.user_id}>Proponente</option>
<option value={p.interest.user_id}>Candidato</option>
</select>
</Field>
<Field label="Data prevista">
<input
className={control}
type="date"
value={form.data.due_date}
onChange={(e) => form.setData("due_date", e.target.value)}
/>
</Field>
<Field label="Estado">
<select
className={control}
value={form.data.status}
onChange={(e) => form.setData("status", e.target.value)}
>
{["pending", "progress", "completed"].map((x) => (
<option key={x} value={x}>
{x === "pending" ? "Pendente" : labels[x]}
</option>
))}
</select>
</Field>
<Field label="Evidência ou referência do resultado">
<textarea
className={control}
value={form.data.evidence}
onChange={(e) => form.setData("evidence", e.target.value)}
/>
</Field>
<Errors errors={form.errors} />
<button className={button} disabled={form.processing}>
Guardar marco
</button>
</form>
);
}
export default function Page(p: Props) {
return <RoomPage key={p.room.id + ":" + p.room.version} {...p} />;
}
function RoomPage(p: Props) {
const { auth } = usePage<{ auth: { user: { id: number } } }>().props;
const message = useForm({ body: "", client_key: crypto.randomUUID() });
const agreement = useForm({
version: p.room.version,
action: "record",
title: p.room.agreement?.title ?? "",
terms: p.room.agreement?.terms ?? "",
reason: "",
});
const upload = useForm<{ file: File | null; shared: boolean }>({
file: null,
shared: false,
});
const act = (action: string) => {
agreement.transform((data) => ({ ...data, action }));
agreement.post(`/parcerias/salas/${p.room.id}/acordo`, {
preserveScroll: true,
});
};
const mutable =
p.canWrite && !["closed", "cancelled"].includes(p.room.status);
return (
<Frame title={"Conexão privada — " + p.partnership.title}>
<div className="space-y-6">
<Link
className="underline"
href={"/parcerias/" + p.partnership.id}
>
Regressar à parceria
</Link>
<p>
Estado da conexão: {labels[p.room.status]}. Esta sala
pertence apenas às partes autorizadas; não encerra outras
candidaturas.
</p>
<section className="space-y-4 rounded border p-5">
<h2 className="text-xl font-bold">
Mensagens e esclarecimentos
</h2>
{p.messages.map((m) => (
<article className="rounded bg-muted p-4" key={m.id}>
<p className="font-semibold">
{m.name} · {m.created_at}
</p>
<p className="whitespace-pre-wrap">{m.body}</p>
</article>
))}
{mutable && (
<form
className="space-y-3"
onSubmit={(e) => {
e.preventDefault();
message.post(
`/parcerias/salas/${p.room.id}/mensagens`,
{
preserveScroll: true,
onSuccess: () => {
message.setData({
body: "",
client_key: crypto.randomUUID(),
});
},
},
);
}}
>
<Field label="Mensagem privada">
<textarea
className={control}
value={message.data.body}
onChange={(e) =>
message.setData("body", e.target.value)
}
/>
</Field>
<Errors errors={message.errors} />
<button
className={button}
disabled={message.processing}
>
Enviar mensagem
</button>
</form>
)}
</section>
<section className="space-y-4 rounded border p-5">
<h2 className="text-xl font-bold">
Documentos autorizados
</h2>
<p>
O original fica no repositório privado. A partilha exige
autorização explícita; o download exige análise
antimalware limpa e hash correspondente. Anexar não
confirma autenticidade nem vigência.
</p>
{p.documents.map((d) => (
<article key={d.id}>
<p>
{d.file_name} ·{" "}
{d.shared
? "Partilhado com a contraparte"
: "Privado do autor"}{" "}
· Análise: {d.malware_scan_status}
</p>
{mutable && d.owner_id === auth.user.id && (
<button
className="underline"
onClick={() =>
router.post(
`/parcerias/salas/${p.room.id}/documentos/${d.id}/partilha`,
{ shared: !d.shared },
{ preserveScroll: true },
)
}
>
{d.shared
? "Retirar autorização de partilha"
: "Autorizar partilha com a contraparte"}
</button>
)}
{d.status === "active" &&
d.malware_scan_status === "clean" && (
<a
className="underline"
href={`/parcerias/salas/${p.room.id}/documentos/${d.id}`}
>
Descarregar documento
</a>
)}
</article>
))}
{mutable && (
<form
className="space-y-3"
onSubmit={(e) => {
e.preventDefault();
upload.post(
`/parcerias/salas/${p.room.id}/documentos`,
{
forceFormData: true,
preserveScroll: true,
},
);
}}
>
<Field label="Anexar PDF ou imagem">
<input
type="file"
className="w-full min-w-0 max-w-full"
accept=".pdf,.jpg,.jpeg,.png"
onChange={(e) =>
upload.setData(
"file",
e.target.files?.[0] ?? null,
)
}
/>
</Field>
<label className="block">
<input
type="checkbox"
checked={upload.data.shared}
onChange={(e) =>
upload.setData(
"shared",
e.target.checked,
)
}
/>{" "}
Autorizo a consulta pela contraparte desta sala.
</label>
<Errors errors={upload.errors} />
<button
className={button}
disabled={
upload.processing || !upload.data.file
}
>
Guardar documento privado
</button>
</form>
)}
</section>
<section className="space-y-4 rounded border p-5">
<h2 className="text-xl font-bold">
Acordo e plano conjunto
</h2>
<p>
Registe o instrumento, objetivos, contribuições,
responsabilidades, indicadores, riscos, dependências e
condições de saída. A confirmação no portal regista a
concordância comunicada pelas partes; não certifica
assinatura jurídica ou due diligence.
</p>
{p.room.agreement && (
<>
<h3 className="font-bold">
{p.room.agreement.title}
</h3>
<p className="whitespace-pre-wrap">
{p.room.agreement.terms}
</p>
<p>
Confirmações:{" "}
{Object.entries(p.room.agreement.confirmations)
.map(
([party, c]) =>
`${party}: autor ${c.actor_id}, ${c.date}`,
)
.join("; ") || "Pendentes"}
</p>
</>
)}
{mutable && (
<>
<Field label="Motivo da ação">
<textarea
className={control}
value={agreement.data.reason}
onChange={(e) =>
agreement.setData(
"reason",
e.target.value,
)
}
/>
</Field>
{["negotiation", "agreement_recorded"].includes(
p.room.status,
) && (
<>
<Field label="Título do instrumento">
<input
className={control}
value={agreement.data.title}
onChange={(e) =>
agreement.setData(
"title",
e.target.value,
)
}
/>
</Field>
<Field label="Condições e plano de valor">
<textarea
className={control}
rows={6}
value={agreement.data.terms}
onChange={(e) =>
agreement.setData(
"terms",
e.target.value,
)
}
/>
</Field>
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("record")}
>
Registar versão do acordo
</button>
</>
)}
<div className="flex flex-wrap gap-3">
{p.room.status === "agreement_recorded" && (
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("confirm")}
>
Confirmar pela minha parte
</button>
)}
{p.room.status === "agreed" && (
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("start")}
>
Iniciar acompanhamento
</button>
)}
{p.room.status === "execution" && (
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("complete")}
>
Concluir após os marcos
</button>
)}
{["agreed", "execution"].includes(
p.room.status,
) && (
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("renew")}
>
Registar renovação
</button>
)}
<button
className={button}
disabled={
agreement.processing ||
!agreement.data.reason
}
onClick={() => act("cancel")}
>
Cancelar conexão com motivo
</button>
</div>
<Errors errors={agreement.errors} />
</>
)}
</section>
<section className="space-y-4">
<h2 className="text-xl font-bold">Marcos e responsáveis</h2>
<p>
Participação atual:{" "}
{auth.user.id === p.partnership.user_id
? "Proponente"
: auth.user.id === p.interest.user_id
? "Candidato"
: "Representante autorizado"}
.
</p>
{p.milestones.map((m) => (
<article
key={m.id + ":" + m.version}
className="space-y-3"
>
<p>
{m.title} · {m.status === "pending" ? "Pendente" : labels[m.status]} · Prazo:{" "}
{m.due_date ?? "Pendente"} · Responsável ID{" "}
{m.responsible_id}
</p>
{mutable && <MilestoneForm p={p} item={m} />}
</article>
))}
{mutable &&
["agreement_recorded", "agreed", "execution"].includes(
p.room.status,
) && <MilestoneForm p={p} />}
</section>
</div>
</Frame>
);
}
+159
View File
@@ -0,0 +1,159 @@
import { Link } from "@inertiajs/react";
import { cloneElement, isValidElement, useId, type ReactNode } from "react";
import { Layout } from "../portfolio/shared";
export type Option = { id: string | number; name: string };
export type Territory = {
id: string;
name: string;
location_type: string;
parent_id: string | null;
};
export type Source = {
type: string;
target_id: string;
title: string;
href: string;
};
export type Catalogues = {
types: Record<string, string>;
criteria: Record<string, string>;
sectors: Option[];
territories: Territory[];
organizations: Option[];
sources?: Source[];
};
export type Partnership = {
id: number;
title: string;
status: string;
version: number;
kind: string;
partnership_type: string | null;
sector_id: number | null;
organization_id?: string | null;
deadline: string | null;
offer: string | null;
seeking: string | null;
payload: {
summary?: string;
requirements?: string;
mandatory?: string[];
confidentiality?: string;
consent?: boolean;
availability?: string;
};
};
export type Match = {
score_min: number | null;
score_max: number | null;
eligibility: string;
criteria: {
code: string;
label: string;
weight: number;
state: string;
mandatory: boolean;
evidence: string | null;
explanation: string;
}[];
};
export type Interest = {
id: number;
user_id: number;
partnership_id: number;
version: number;
proposal: string;
status: string;
decision_reason: string | null;
organization_id: string | null;
payload: {
capacity?: string;
availability?: string;
contribution?: string;
conflicts?: string;
consent?: boolean;
};
assessment: Record<string, { state: string; evidence?: string }>;
match: Match;
room_id: number | null;
};
export const labels: Record<string, string> = {
draft: "Rascunho",
pending: "Submetida — legado",
submitted: "Submetida",
returned: "Devolvida",
rejected: "Rejeitada",
published: "Publicada",
suspended: "Suspensa",
archived: "Arquivada",
withdrawn: "Retirada",
clarification: "Em esclarecimento",
shortlisted: "Lista curta",
negotiation: "Em negociação",
agreement_recorded: "Acordo registado",
agreed: "Confirmado pelas partes",
execution: "Em execução",
closed: "Concluída",
cancelled: "Cancelada",
progress: "Em curso",
completed: "Concluído",
met: "Comprovadamente cumprido",
unmet: "Comprovadamente incumprido",
unknown: "Informação insuficiente",
};
export const control = "w-full rounded border bg-background p-2";
export const button =
"inline-flex rounded bg-emerald-800 px-4 py-2 text-white disabled:opacity-50";
export function Frame({
title,
children,
}: {
title: string;
children: ReactNode;
}) {
return (
<Layout title={title}>
<nav className="mb-6 flex flex-wrap gap-5 underline">
<Link href="/parcerias">Catálogo</Link>
<Link href="/parcerias/painel">O meu painel</Link>
<Link href="/parcerias/criar">Preparar parceria</Link>
<Link href="/como-investir">Como investir</Link>
<Link href="/simulador-fiscal">
Simulador e ficha de projeto
</Link>
</nav>
{children}
</Layout>
);
}
export function Errors({ errors }: { errors: Record<string, string> }) {
return (
<>
{Object.entries(errors).map(([key, message]) => (
<p role="alert" className="text-red-700" key={key}>
{message}
</p>
))}
</>
);
}
export function Field({
label,
children,
}: {
label: string;
children: ReactNode;
}) {
const id = useId();
return (
<label className="block space-y-2">
<span id={id} className="font-medium">
{label}
</span>
{isValidElement<{ "aria-labelledby"?: string }>(children)
? cloneElement(children, { "aria-labelledby": id })
: children}
</label>
);
}