feat: verify active opportunity management and prepare versioned resources

This commit is contained in:
2026-10-09 13:16:41 +02:00
parent 60784a2ed2
commit 9d6176f55b
16 changed files with 419 additions and 43 deletions
@@ -24,6 +24,7 @@ export default function OpportunityDraft({
categories,
history,
territoryPath,
resourcesInstalled = false,
}: {
record: Entry | null;
values: Values;
@@ -34,6 +35,7 @@ export default function OpportunityDraft({
sectors: { id: number; name: string }[];
categories: string[];
territoryPath: TerritoryOption[];
resourcesInstalled?: boolean;
history: {
id: string;
action: string;
@@ -466,8 +468,16 @@ export default function OpportunityDraft({
)}
</form>
{record && (
<Link href={`/management/opportunities/${record.id}/resources`}>
Imagens, documentos e localizações
<Link
href={
resourcesInstalled
? `/management/opportunities/${record.id}/resources`
: "/management/opportunity-resources-install"
}
>
{resourcesInstalled
? "Imagens, documentos e localizações"
: "Plano de ativação de imagens, documentos e localizações"}
</Link>
)}
{record && (
@@ -13,6 +13,12 @@ type Resource = {
deleted_at: string | null;
payload: Payload;
territoryPath?: TerritoryOption[];
derivativePreviews?: {
document_id: string;
url: string;
width: number;
height: number;
}[];
file?: {
file_name: string;
malware_scan_status: string;
@@ -58,6 +64,14 @@ const fields: Record<Kind, string[]> = {
],
};
const labels: Record<string, string> = {
role: "Papel da localização",
imageRole: "Tipo de imagem",
territorial_purpose: "Natureza da relação territorial",
rights_status: "Direitos de utilização",
visibility: "Âmbito de consulta",
classification: "Classificação documental",
location_id: "Localização associada",
rights_document_id: "Comprovativo de direitos",
title: "Título",
address: "Referência física",
operational_unit: "Unidade operacional",
@@ -156,7 +170,7 @@ export default function OpportunityResources({
setConfirm(false);
setErrors({});
}
async function execute(action: "save" | "delete" | "restore") {
async function execute(action: "save" | "delete" | "restore" | "prepare") {
if (busy) return;
setBusy(true);
setErrors({});
@@ -187,7 +201,7 @@ export default function OpportunityResources({
form.set("action", action);
form.set("confirm", confirm ? "1" : "0");
}
const url = `/management/opportunities/${opportunity.id}/resources/${kind}${editing ? `/${editing.id}` : ""}${action === "save" ? "" : "/lifecycle"}`;
const url = `/management/opportunities/${opportunity.id}/resources/${kind}${editing ? `/${editing.id}` : ""}${action === "save" ? "" : action === "prepare" ? "/prepare" : "/lifecycle"}`;
const csrf =
document.cookie
.split("; ")
@@ -316,12 +330,32 @@ export default function OpportunityResources({
: "rascunho"}
</p>
{r.file && (
<p>
<p className="break-all">
Scan: {r.file.malware_scan_status} · motor:{" "}
{r.file.malware_engine ?? "não executado"} ·
hash: {r.file.sha256}
</p>
)}
{kind === "images" &&
!r.deleted_at &&
!!r.derivativePreviews?.length && (
<img
className="max-w-full"
src={r.derivativePreviews[0].url}
srcSet={r.derivativePreviews
.map((p) => `${p.url} ${p.width}w`)
.join(", ")}
alt={String(
r.payload.alt_text ??
"Pré-visualização interna pendente de descrição",
)}
onError={() =>
setMessage(
"Pré-visualização indisponível ou endereço expirado; recarregue. Dados preservados.",
)
}
/>
)}
<button
className={button}
onClick={() => select(kind, r)}
@@ -389,6 +423,7 @@ export default function OpportunityResources({
error={errors.file}
>
<input
key={key}
aria-label="Original / substituir por nova versão"
type="file"
accept={
@@ -437,8 +472,9 @@ export default function OpportunityResources({
).map((name) => (
<Field
key={name}
label={name}
label={labels[name] ?? name}
error={
errors[name === "imageRole" ? "role" : name] ??
errors[
`payload.${name === "imageRole" ? "role" : name}`
]
@@ -446,7 +482,7 @@ export default function OpportunityResources({
>
<select
className={control}
aria-label={name}
aria-label={labels[name] ?? name}
value={String(
payload[name === "imageRole" ? "role" : name] ??
"",
@@ -488,8 +524,10 @@ export default function OpportunityResources({
(name) => (
<Field
key={name}
label={name}
error={errors[`payload.${name}`]}
label={labels[name] ?? name}
error={
errors[name] ?? errors[`payload.${name}`]
}
>
<select
className={control}
@@ -521,6 +559,7 @@ export default function OpportunityResources({
{kind !== "documents" && (
<label>
<input
key={key}
type="checkbox"
checked={
!!payload[
@@ -567,6 +606,16 @@ export default function OpportunityResources({
</label>
)}
<div className="flex flex-wrap gap-3">
{kind === "images" && editing && !editing.deleted_at && (
<button
type="button"
className={button}
disabled={busy || unavailable}
onClick={() => void execute("prepare")}
>
Preparar WebP e miniaturas
</button>
)}
<button
className={button}
disabled={busy || unavailable || !!editing?.deleted_at}