Link documented investment complements to existing fiches and dossier context

This commit is contained in:
2026-10-23 16:34:57 +02:00
parent 4098192a05
commit 603a88e1d3
23 changed files with 881 additions and 25 deletions
+12
View File
@@ -1,8 +1,20 @@
const levels = ['province_id', 'district_id', 'admin_post_id', 'locality_id'];
const searchRoutes = ['/carteira', '/oportunidades', '/zonas', '/educacao'];
/** 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;
if (!params.get('complement_origin') || !params.get('complement_code') || (target && params.get('complement_target') !== target)) return null;
const query = new URLSearchParams();
for (const field of ['complement_origin', 'complement_code', 'complement_target', 'complement_territory', 'selection_key']) if(params.get(field)) query.set(field,params.get(field)!);
const dossier = params.get('investment_dossier');
return (dossier && /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i.test(dossier) ? `/investimentos/${dossier}/contexto/editar` : '/investimentos/iniciar')+'?'+query;
}
/** Carry the explicitly consulted portfolio origin and search geography into the existing preparation entry. */
export function investmentPreparationHref(opportunity: number, pageUrl: string, origin?: string | null): string {
const complementary = complementPreparationHref(pageUrl, `opportunity:${opportunity}`);
if (complementary) return complementary;
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: `opportunity:${opportunity}`});