feat(investment): prepare evidence-led territorial needs and ideas in existing workflows

This commit is contained in:
2026-10-27 09:35:20 +02:00
parent f8d57bddf9
commit 3439f35038
22 changed files with 605 additions and 14 deletions
@@ -1,19 +1,21 @@
import {ProactivePublicationFields,ProactiveSummary,newPublicProactive,type ProactivePublic,type ProactiveEvidence,type ProactiveOptions} from '@/components/proactive-investment';
import { Link, router } from '@inertiajs/react';
import { useState } from 'react';
import { createOperationKey } from '@/lib/operation-key';
import { profileJson, ProfileValidationError } from '@/lib/profile-json';
import { Management, Field, control, button } from './shared';
type Draft = {title: string; summary: string; description: string; limitations: string; source_reference: string; edition: string; source_date: string; sector_id: number | null; territory_ids: string[]};
type Projection = {title: string; summary: string; description: string; sector_id: number | null; maturity_label: string; territories: {id: string; label: string}[]};
type Draft = {proactive_public?:ProactivePublic;proactive_reviewed?:boolean;title: string; summary: string; description: string; limitations: string; source_reference: string; edition: string; source_date: string; sector_id: number | null; territory_ids: string[]};
type Projection = {title: string; summary: string; description: string; sector_id: number | null; maturity_label: string; territories: {id: string; label: string}[];proactive?:ProactivePublic};
type Preview = {token: string; action: 'disclose' | 'withdraw'; projection: Projection; current: {title: string; summary: string; description: string; status: string}};
export default function OpportunityPromotion({record, initial, etag, publicNow, reauthenticationRequired, sectors, territories, history}: {
export default function OpportunityPromotion({proactiveEnabled=false,proactiveKind,proactiveRelations=[],proactiveEvidence=[],proactiveOptions,record, initial, etag, publicNow, reauthenticationRequired, sectors, territories, history}: {
proactiveRelations?:{id:string;label:string;relationship:string}[];proactiveEnabled?:boolean;proactiveKind?:string;proactiveEvidence?:ProactiveEvidence[];proactiveOptions?:ProactiveOptions;
record: {id: number; reference: string}; initial: Draft; etag: string; publicNow: boolean; reauthenticationRequired: boolean;
sectors: {id: number; name: string}[]; territories: {id: string; name: string; location_type: string}[];
history: {id: string; action: string; actor_user_id: number; occurred_at: string}[];
}) {
const [draft, setDraft] = useState<Draft>({...initial, source_date: initial.source_date ?? ''});
const [draft, setDraft] = useState<Draft>({...initial, source_date: initial.source_date ?? '',...(proactiveEnabled?{proactive_public:initial.proactive_public??{...newPublicProactive(),group:proactiveKind??'ideas'},proactive_reviewed:false}:{})});
const [preview, setPreview] = useState<Preview | null>(null);
const [operationKey, setOperationKey] = useState(createOperationKey);
const [reason, setReason] = useState('');
@@ -45,6 +47,7 @@ export default function OpportunityPromotion({record, initial, etag, publicNow,
{needsMfa && <p role="alert">Entre novamente com a sua conta e MFA para confirmar esta operação. O cadastro guardado permanece disponível; a prévia ainda não confirmada terá de ser preparada novamente. <button className="underline" onClick={renewAuthentication}>Renovar entrada com MFA</button></p>}
{Object.entries(errors).map(([key,value]) => <p role="alert" key={key}>{key}: {value}</p>)}
<form className="space-y-4 rounded border p-5" onSubmit={e=>{e.preventDefault(); void prepare('disclose');}}>
{proactiveEnabled&&draft.proactive_public&&<ProactivePublicationFields value={draft.proactive_public} onChange={v=>{change('proactive_public',v);change('proactive_reviewed',false);}} evidence={proactiveEvidence} relations={proactiveRelations} options={proactiveOptions} reviewed={Boolean(draft.proactive_reviewed)} onReview={v=>change('proactive_reviewed',v)}/>}
<Field label="Título público"><input required className={control} maxLength={255} value={draft.title} onChange={e=>change('title',e.target.value)}/></Field>
<Field label="Resumo público"><textarea required className={control} maxLength={499} value={draft.summary} onChange={e=>change('summary',e.target.value)}/></Field>
<Field label="Descrição pública"><textarea className={control} maxLength={6000} value={draft.description} onChange={e=>change('description',e.target.value)}/></Field>
@@ -62,6 +65,7 @@ export default function OpportunityPromotion({record, initial, etag, publicNow,
{preview && <section className="space-y-4 rounded border p-5" aria-label="Prévia da divulgação">
<h2 className="text-xl font-semibold">{preview.action === 'withdraw' ? 'Rever retirada do catálogo' : 'Prévia do conteúdo público'}</h2>
<p><strong>{preview.projection.maturity_label}</strong></p>
<ProactiveSummary value={preview.projection.proactive}/>
<h3>{preview.projection.title}</h3><p>{preview.projection.summary}</p><p className="whitespace-pre-wrap">{preview.projection.description}</p>
<p>Sector: {sectors.find(s=>s.id===preview.projection.sector_id)?.name ?? 'Por indicar'}</p>
<ul>{preview.projection.territories.map(t=><li key={t.id}>{t.label}</li>)}</ul>