fix: connect documentary anchors to investment preparation and recover accepted territories
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -34,6 +34,7 @@ export type ContextReference = {
|
||||
version: number | string | null;
|
||||
sha256: string;
|
||||
fields: Record<string, string>;
|
||||
analysis?: {documented_sector?: string | null; documented_location?: string | null; [key:string]:unknown};
|
||||
documents?: ContextDocument[];
|
||||
visibility?: 'private' | 'public';
|
||||
state?: string | null;
|
||||
@@ -63,7 +64,7 @@ export type DossierContext = {
|
||||
revision: number;
|
||||
selection: Partial<
|
||||
Record<
|
||||
'opportunity' | 'sector' | 'territory' | 'park',
|
||||
'portfolio' | 'opportunity' | 'sector' | 'territory' | 'park',
|
||||
ContextReference
|
||||
>
|
||||
>;
|
||||
|
||||
@@ -285,6 +285,7 @@ function makeSections(
|
||||
);
|
||||
if (context.version === 1) {
|
||||
const section = sections.get('sources');
|
||||
if (context.portfolio_origin) section?.rows.push({field:'Projecto ou carteira de origem', value:context.portfolio_origin.title, origin:`${context.portfolio_origin.key}; versão ${context.portfolio_origin.version}; ${context.portfolio_origin.href}`, classification:'Origem documental; localização e oferta não presumidas'});
|
||||
if (context.consumer_opportunity) section?.rows.push({field:'Oportunidade em tratamento', value:context.consumer_opportunity, origin:context.opportunity_choices?.[0]?.opportunity?.title ?? 'Escolha guardada no dossier', classification:'Âmbito desta análise'});
|
||||
for (const step of context.path?.steps ?? []) {
|
||||
if (step.applicability === 'not_needed_for_preparation') section?.paragraphs.push(`${step.code} — preparação não necessária neste âmbito: ${step.reason || 'Decisão guardada do promotor'}. Histórico conservado; não constitui dispensa legal.`);
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
const levels = ['province_id', 'district_id', 'admin_post_id', 'locality_id'];
|
||||
const searchRoutes = ['/carteira', '/oportunidades', '/zonas', '/educacao'];
|
||||
|
||||
/** Keep search geography explicit; a documentary origin is never an invented offer. */
|
||||
export function portfolioPreparationHref(id: string, pageUrl: string): string {
|
||||
const source = new URL(pageUrl, 'https://portal.invalid');
|
||||
const inherited = source.searchParams.has('catalogue_query') ? new URLSearchParams(source.searchParams.get('catalogue_query')!) : source.searchParams;
|
||||
const query = new URLSearchParams({source: `portfolio:${id}`});
|
||||
for (const field of levels) if (inherited.get(field)) query.set(field, inherited.get(field)!);
|
||||
return '/investimentos/iniciar?' + query.toString();
|
||||
}
|
||||
|
||||
/** Preserve an explicit complementary selection while consulting its canonical public fiche. */
|
||||
export function complementPreparationHref(pageUrl: string, target?: string): string | null {
|
||||
const params = new URL(pageUrl, 'https://portal.invalid').searchParams;
|
||||
|
||||
@@ -82,6 +82,7 @@ type Props = {
|
||||
version: number;
|
||||
payload: Partial<Payload>;
|
||||
opportunity_id?: number | null;
|
||||
dossier_id?: string | null;
|
||||
status: string;
|
||||
};
|
||||
references: References;
|
||||
@@ -395,6 +396,7 @@ function Editor({
|
||||
dossier. Associar reutiliza o contexto autorizado;
|
||||
campos já editados conservam-se.
|
||||
</p>
|
||||
{s.dossier_id && <p><Link className="underline" href={'/investimentos/iniciar?source=' + encodeURIComponent('portfolio:' + s.dossier_id) + '&submission=' + encodeURIComponent(s.id)}>Preparar investimento com a ficha de origem</Link>. A manifestação ficará ligada ao dossier que escolher.</p>}
|
||||
<label className="grid gap-1">
|
||||
Dossier autorizado para esta manifestação
|
||||
<select
|
||||
|
||||
@@ -12,6 +12,7 @@ export default function ContextStart({
|
||||
step = null,
|
||||
entryQuery = {},
|
||||
entryComplements = [],
|
||||
entrySubmission = null,
|
||||
}: {
|
||||
contexts: { id: string; title: string; version: number }[];
|
||||
source: ContextReference | null;
|
||||
@@ -19,6 +20,7 @@ export default function ContextStart({
|
||||
step?: string | null;
|
||||
entryQuery?: Record<string, string>;
|
||||
entryComplements?: Complement[];
|
||||
entrySubmission?: {id:string;version:number} | null;
|
||||
}) {
|
||||
const [chosen, setChosen] = useState('');
|
||||
const [title, setTitle] = useState(entryComplements[0]?.kind === 'need' ? `Preparação de ${entryComplements[0].title} — ${entryComplements[0].origin.title}`.slice(0,200) : source?.title ?? opportunityChoices[0]?.opportunity.title ?? '');
|
||||
@@ -28,6 +30,13 @@ export default function ContextStart({
|
||||
const [key] = useState(createOperationKey);
|
||||
const sourceSuffix = opportunityChoices.length ? '?' + opportunityChoices.map(c => `opportunities[]=${encodeURIComponent(c.opportunity.id)}`).join('&') : source ? '?source=' + encodeURIComponent(source.key) : '';
|
||||
const suffix = sourceSuffix || Object.keys(entryQuery).length ? (sourceSuffix || '?')+(sourceSuffix ? '&' : '')+'selection_key='+encodeURIComponent(key)+'&'+new URLSearchParams(entryQuery).toString() : '';
|
||||
const continueIn = async (id: string) => {
|
||||
if (entrySubmission) {
|
||||
const view = await contextApi<{case:{version:number}}>(`/investimentos/${id}/contexto`);
|
||||
await contextApi(`/investidor/manifestacoes/${entrySubmission.id}/contexto`, {case_id:id,case_version:view.case.version,version:entrySubmission.version});
|
||||
}
|
||||
window.location.assign(`/investimentos/${id}/contexto/editar${suffix}`);
|
||||
};
|
||||
return (
|
||||
<Frame title="Iniciar ou continuar um investimento">
|
||||
<SelectedComplements items={entryComplements}/>
|
||||
@@ -44,9 +53,11 @@ export default function ContextStart({
|
||||
<Link className="underline" href={source.href}>
|
||||
{source.title}
|
||||
</Link>
|
||||
{source.kind === 'portfolio' && <p>Sector documentado: {source.analysis?.documented_sector ?? 'Por definir'}. Cobertura documental: {source.analysis?.documented_location ?? 'Por definir'}. Confirme o enquadramento e a localização do seu investimento no dossier.</p>}
|
||||
</section>
|
||||
)}
|
||||
<section className={card + ' space-y-3'}>
|
||||
{entrySubmission && <p>Ao continuar, esta manifestação será associada ao dossier escolhido, conservando a ficha de origem. Nenhum pedido será submetido.</p>}
|
||||
<h2 className="text-xl font-bold">
|
||||
Continuar um dossier existente
|
||||
</h2>
|
||||
@@ -65,20 +76,23 @@ export default function ContextStart({
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
{chosen && (
|
||||
<Link
|
||||
{chosen && entrySubmission && (
|
||||
<button
|
||||
className={button}
|
||||
href={
|
||||
step && !source && !opportunityChoices.length
|
||||
? `/investimentos/${chosen}#${step}`
|
||||
: `/investimentos/${chosen}/contexto/editar${suffix}`
|
||||
}
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
if (step && !source && !opportunityChoices.length) {window.location.assign(`/investimentos/${chosen}#${step}`);return;}
|
||||
setBusy(true);setError('');void continueIn(chosen).catch(e=>{setError(e.message);setBusy(false);});
|
||||
}}
|
||||
>
|
||||
{step && !source && !opportunityChoices.length
|
||||
? 'Abrir ' + step + ' no mesmo dossier'
|
||||
: 'Preparar neste dossier'}
|
||||
</Link>
|
||||
</button>
|
||||
)}
|
||||
{chosen && !entrySubmission && <Link className={button} href={step && !source && !opportunityChoices.length ? `/investimentos/${chosen}#${step}` : `/investimentos/${chosen}/contexto/editar${suffix}`}>
|
||||
{step && !source && !opportunityChoices.length ? 'Abrir ' + step + ' no mesmo dossier' : 'Preparar neste dossier'}
|
||||
</Link>}
|
||||
<p>
|
||||
Se já preparou este investimento, continue nele. Não é
|
||||
necessário criar outro dossier.
|
||||
@@ -95,11 +109,7 @@ export default function ContextStart({
|
||||
client_key: key,
|
||||
reuse_consent: consent,
|
||||
})
|
||||
.then((r) =>
|
||||
window.location.assign(
|
||||
`/investimentos/${r.id}/contexto/editar${suffix}`,
|
||||
),
|
||||
)
|
||||
.then((r) => continueIn(r.id))
|
||||
.catch((e) => setError(e.message))
|
||||
.finally(() => setBusy(false));
|
||||
}}
|
||||
|
||||
@@ -30,7 +30,7 @@ type Options = {
|
||||
parks: { id: string; name: string; version_no: number }[];
|
||||
search_limited: boolean;
|
||||
};
|
||||
type Slot = 'opportunity' | 'sector' | 'territory' | 'park';
|
||||
type Slot = 'portfolio' | 'opportunity' | 'sector' | 'territory' | 'park';
|
||||
export default function ContextEditor({
|
||||
initial,
|
||||
options: initialOptions,
|
||||
@@ -41,6 +41,7 @@ export default function ContextEditor({
|
||||
entrySources = [],
|
||||
entryLocationDifferences = [],
|
||||
entryComplements = [],
|
||||
entryTerritory = null,
|
||||
}: {
|
||||
initial: ContextView;
|
||||
options: Options;
|
||||
@@ -49,6 +50,7 @@ export default function ContextEditor({
|
||||
requestedChoices?: OpportunityChoice[] | null;
|
||||
entrySources?: string[];
|
||||
entryComplements?: Complement[];
|
||||
entryTerritory?: ContextReference | null;
|
||||
entryLocationDifferences?: {title:string;saved:string;requested:string}[];
|
||||
draft?: {draft_sequence?:number;needs_review?:boolean;selection?:Partial<Record<Slot,string>>;declarations?:Record<string,string>;replace_fields?:string[];document_links?:Record<string,string|null>}|null;
|
||||
}) {
|
||||
@@ -81,12 +83,12 @@ export default function ContextEditor({
|
||||
const [options, setOptions] = useState(initialOptions);
|
||||
const [query, setQuery] = useState('');
|
||||
const [changes, setChanges] = useState<Partial<Record<Slot, string>>>(() =>
|
||||
draft?.selection ?? (source
|
||||
({...(draft?.selection ?? {}), ...(entryTerritory && !draft?.selection?.territory && !initial.context.selection.territory ? {territory: entryTerritory.key} : {}), ...(source?.kind === 'portfolio' ? {portfolio: source.key} : draft?.selection ? {} : source
|
||||
? {
|
||||
[source.kind === 'business' ? 'opportunity' : source.kind]:
|
||||
source.key,
|
||||
}
|
||||
: {}),
|
||||
: {})}),
|
||||
);
|
||||
const [declarations, setDeclarations] = useState<Record<string, string>>(
|
||||
draft?.declarations ?? {},
|
||||
@@ -311,6 +313,11 @@ export default function ContextEditor({
|
||||
{draft?.needs_review&&<p role="status">O rascunho foi recuperado, mas o dossier recebeu outras alterações. Reveja os dados antes de confirmar.</p>}
|
||||
{draftStatus.startsWith('Rascunho não guardado')&&<button type="button" className="underline" onClick={()=>setDraftRetry(v=>v+1)}>Tentar guardar novamente</button>}
|
||||
<OpportunityChoices corridors={corridors} choices={choices} disabled={busy||corridorLoading||!!corridorError} onChange={next=>{setChoices(next);setManageChoices(true);setPlan(null);}}/>
|
||||
{(changes.portfolio || view.context.selection.portfolio) && <p className="rounded border p-3">
|
||||
Origem documental: <a className="underline" href={source?.kind === 'portfolio' ? source.href : view.context.selection.portfolio?.href}>{source?.kind === 'portfolio' ? source.title : view.context.selection.portfolio?.title}</a>.
|
||||
{' '}A ficha é conservada como origem. Escolha o sector e a localização do investimento abaixo; a cobertura documental não é uma implantação atribuída.
|
||||
</p>}
|
||||
{entryTerritory && view.context.selection.territory && entryTerritory.key !== view.context.selection.territory.key && <p role="status">A pesquisa indicava {entryTerritory.title}. Conservou-se a localização guardada, {view.context.selection.territory.title}; pode alterá-la explicitamente abaixo e conferir os impactos.</p>}
|
||||
<ContextDocuments source={source ?? view.context.selection.opportunity} />
|
||||
{view.context.revision > 0 && !Object.keys(changes).length && JSON.stringify(choices) === JSON.stringify(view.context.opportunity_choices ?? []) && <InvestmentRequirements assessment={view.context.requirements_assessment} contextId={view.case.id}/>}
|
||||
<label className="block">Acrescentar uma oportunidade à escolha<select className={input} value="" onChange={e=>{const o=options.opportunities.find(o=>o.key===e.target.value);if(o && !choices.some(c=>c.opportunity.key===o.key)){setChoices([...choices,{opportunity:{...o,id:o.key.split(':')[1],href:'/oportunidades',version:null,sha256:'',fields:{}},territory:null,location_reason:'',location_state:'undetermined'}]);setManageChoices(true);setPlan(null);}}}><option value="">Seleccionar ficha</option>{options.opportunities.filter(o=>o.kind==='opportunity'&&!choices.some(c=>c.opportunity.key===o.key)).map(o=><option key={o.key} value={o.key}>{o.title}</option>)}</select></label>
|
||||
|
||||
@@ -444,6 +444,10 @@ export default function InvestmentPath(path: Path) {
|
||||
Os meus investimentos
|
||||
</Link>
|
||||
<h1 className="text-2xl font-semibold">{path.case.title}</h1>
|
||||
{path.investment_context?.selection.portfolio && <p className="rounded border p-4">
|
||||
Origem documental: <Link className="underline" href={path.investment_context.selection.portfolio.href}>{path.investment_context.selection.portfolio.title}</Link>.
|
||||
{' '}A localização do investimento é escolhida no contexto.
|
||||
</p>}
|
||||
{!!path.opportunity_options?.length && <label className="block rounded border p-4">Oportunidade em tratamento
|
||||
<select className="ml-2 rounded border p-2" value={path.context_opportunity ?? ''} onChange={event => router.get(`/investimentos/${path.case.id}`, event.target.value ? {opportunity:event.target.value} : {}, {preserveState:false})}>
|
||||
<option value="">Escolha a oportunidade</option>
|
||||
|
||||
@@ -14,12 +14,15 @@ export default function Index({
|
||||
management,
|
||||
filters,
|
||||
territorySelection = [],
|
||||
sectors = [],
|
||||
}: {
|
||||
records: Paginated<Dossier>;
|
||||
management: boolean;
|
||||
sectors?: string[];
|
||||
filters: {
|
||||
q?: string;
|
||||
kind?: string;
|
||||
sector?: string;
|
||||
province_id?: string;
|
||||
district_id?: string;
|
||||
admin_post_id?: string;
|
||||
@@ -30,6 +33,7 @@ export default function Index({
|
||||
const form = useForm({
|
||||
q: filters.q ?? '',
|
||||
kind: filters.kind ?? '',
|
||||
sector: filters.sector ?? '',
|
||||
province_id: filters.province_id ?? '',
|
||||
district_id: filters.district_id ?? '',
|
||||
admin_post_id: filters.admin_post_id ?? '',
|
||||
@@ -77,6 +81,12 @@ export default function Index({
|
||||
<option value="project">Projectos âncora</option>
|
||||
</select>
|
||||
</Field>
|
||||
<Field label="Sector documentado">
|
||||
<select className={control} value={form.data.sector} onChange={(e) => form.setData('sector', e.target.value)}>
|
||||
<option value="">Todos os sectores</option>
|
||||
{sectors.map((sector) => <option key={sector} value={sector}>{sector}</option>)}
|
||||
</select>
|
||||
</Field>
|
||||
<TerritoryFields
|
||||
initial={territorySelection}
|
||||
onChange={(path) =>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Link, useForm, router, usePage } from '@inertiajs/react';
|
||||
import { useState } from 'react';
|
||||
import { catalogueReturnHref } from '@/lib/catalogue-context';
|
||||
import { searchTerritoryHref } from '@/lib/search-territory';
|
||||
import { searchTerritoryHref, portfolioPreparationHref } from '@/lib/search-territory';
|
||||
import InvestmentMapPanel from '@/components/investment-map-panel';
|
||||
import StructureGeographyPanel, {
|
||||
type StructureGeography,
|
||||
@@ -94,6 +94,14 @@ function Editor({
|
||||
{kind(record)} · {record.content.code}
|
||||
</p>
|
||||
<p className="text-sm">Fonte: {record.source}</p>
|
||||
{!management && (
|
||||
<div className="space-y-2 rounded-xl border p-4">
|
||||
<Link className="underline" href={portfolioPreparationHref(record.id, pageUrl)}>
|
||||
Preparar investimento a partir desta ficha
|
||||
</Link>
|
||||
<p>A ficha acompanha o dossier como origem documental. A localização do investimento e as ofertas associadas são escolhas próprias.</p>
|
||||
</div>
|
||||
)}
|
||||
{(record.project_id || record.cluster_id) && (
|
||||
<PartnershipSourceLinks
|
||||
type={record.project_id ? 'project' : 'cluster'}
|
||||
@@ -270,7 +278,7 @@ function Editor({
|
||||
Para associar esta referência a uma manifestação privada,
|
||||
entre na sua conta. Esta ficha continuará pública e não será
|
||||
copiada nem publicada no seu nome.{' '}
|
||||
<Link className="underline" href="/login">
|
||||
<Link className="underline" href={'/carteira/' + record.id + '/interesse' + (() => { const query = new URL(pageUrl, 'https://portal.invalid').searchParams.get('catalogue_query'); return query ? '?catalogue_query=' + encodeURIComponent(query) : ''; })()}>
|
||||
Entrar
|
||||
</Link>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user