This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user