Files
Investidor-V2/outputs/investmoz-navegacao-QA-20261016/navigation-before.mjs
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

245 lines
10 KiB
JavaScript

const link = (id, label, href) => ({
id,
label,
href,
});
/** One route catalogue for the public shell and authenticated pages. */
export function portalNavigation(access) {
const opportunities = access.manager ? access.opportunityManagement : null;
const groups = [
{
id: 'explore',
label: 'Explorar investimentos',
children: [
link('opportunities', 'Oportunidades', '/oportunidades'),
link('sectors', 'Sectores', '/sectores'),
...(access.legacyContent
? [
link('legacy-agronegocio', 'Explorar agronegócio', '/explorar/agronegocio'),
]
: []),
{
id: 'structures',
label: 'Carteira e estruturas',
children: [
link('portfolio', 'Carteira de investimento', '/carteira'),
link('projects', 'Projectos âncora', '/carteira?kind=project'),
link('clusters', 'Clusters', '/carteira?kind=cluster'),
link('corridors', 'Corredores', '/carteira?kind=corridor'),
],
},
{
id: 'zones',
label: 'Zonas e parques',
children: [
link('all-zones', 'Todas as zonas', '/zonas'),
link('zee', 'ZEE', '/zonas?category=zee'),
link('zfi', 'ZFI', '/zonas?category=zfi'),
link('parks', 'Parques industriais', '/zonas?physical_category=industrial_park'),
],
},
],
},
{
id: 'prepare',
label: 'Preparar o projecto',
children: [
link('roadmap', 'Como investir', '/como-investir'),
link('dossier', 'Preparar dossier', '/simulador-fiscal'),
link('simulator', 'Simulador', '/simulador-fiscal'),
link('land', 'Terra e DUAT', '/terra-duat'),
...(access.education
? [
link('education', 'Educação e competências', '/educacao'),
]
: []),
],
},
{
id: 'support',
label: 'Serviços e apoio',
children: [
link('desk', 'Balcão Virtual', '/balcao-virtual'),
link('help', 'Apoio ao investidor', '/apoio'),
link('documents', 'Documentos e formulários', '/documentos'),
link('law', 'Legislação', '/legislacao'),
],
},
{
id: 'partnerships',
label: 'Parcerias',
children: [
link('exchange', 'Bolsa de Parcerias', '/parcerias'),
link('businesses', 'Negócios e participações', '/negocios'),
...(access.authenticated
? [
link('my-partnerships', 'As minhas parcerias', '/parcerias/painel'),
]
: []),
...(access.authenticated && access.businesses
? [
link('my-businesses', 'Os meus negócios', '/investidor/negocios'),
]
: []),
...(access.authenticated && access.businesses && access.businessReviewUrl
? [link('review-businesses', 'Revisão de negócios', access.businessReviewUrl)]
: []),
],
},
{
id: 'account',
label: 'A minha área',
children: access.authenticated
? [
link('dashboard', opportunities ? 'Painel da gestão' : 'Painel', opportunities ? '/dashboard' : '/investidor'),
link('profile', 'Perfil e empresas', '/investidor/profile'),
link('dossiers', 'Dossiers e percursos', '/investidor'),
link('requests', 'Pedidos e tarefas de acompanhamento', '/balcao-virtual'),
link('interests', 'Manifestações e favoritos', '/investidor/manifestacoes'),
link('notifications', 'Notificações', '/investidor/notifications'),
]
: [
link('login', 'Entrar', '/login'),
link('register', 'Criar conta', '/register'),
],
},
];
if (access.manager)
groups.push({
id: 'management',
label: 'Gestão',
children: [
link('manage-interests', 'Pedidos de interesse', '/management/interests'),
link('crm', 'CRM interno', '/management/crm/leads'),
...(opportunities
? [
link('manage-opportunities', opportunities.manage.label, opportunities.manage.href),
...(opportunities.installed
? [
link('create-opportunity', opportunities.create.label, opportunities.create.href),
]
: []),
]
: []),
{
id: 'manage-catalogue',
label: 'Catálogo de investimento',
children: [
link('manage-sectors', 'Sectores', '/management/sectors'),
...(!opportunities
? [
link('manage-opportunities', 'Oportunidades', '/management/opportunities'),
]
: []),
link('manage-projects', 'Projectos', '/management/projects'),
link('manage-clusters', 'Clusters', '/management/clusters'),
],
},
link('manage-portfolio', 'Carteira e estruturas', '/management/portfolio'),
link('manage-documents', 'Acervo documental', '/management/portal-services'),
link('manage-zones', 'Zonas e parques', '/management/investment/zones'),
link('manage-territory', 'Associações territoriais', '/management/territory-associations'),
link('manage-references', 'Referências e formulários', '/management/investment/references'),
link('desk-installation', 'Estado do Balcão e orientação', '/management/balcao-install'),
link('exchange-installation', 'Estado da Bolsa de Parcerias', '/management/partnerships-install'),
...(access.ai
? [
link('manage-ai', 'Assistência interna', '/management/ai'),
]
: []),
...(access.education
? [
link('manage-education', 'Educação e competências', '/management/education'),
]
: []),
],
});
if (access.authenticated && access.profileAccess) {
const profile = access.profileAccess;
groups.push({
id: 'profile-opportunities',
label: 'Perfil e oportunidades',
children: [
...(profile.mine
? [
link('my-opportunities', 'Minhas oportunidades', profile.mine),
]
: []),
...(profile.create
? [
link('new-my-opportunity', 'Nova oportunidade', profile.create),
]
: []),
link('promoter-profile', profile.mine
? 'Autorizações de Promotor'
: 'Solicitar perfil de Promotor', profile.request),
...(!profile.mine && profile.review
? [
link('profile-review', 'Revisão de oportunidades', profile.review),
]
: []),
...(profile.audit
? [
link('profile-audit', 'Auditoria de acessos', profile.audit),
]
: []),
...(profile.administration
? [
link('profile-administration', 'Gestão de perfis', profile.administration),
]
: []),
],
});
}
return groups;
}
export function currentNavigationGroup(groups, url) {
const current = new URL(url, 'https://portal.invalid');
let match = null;
const visit = (items, group) => items.forEach((item) => {
if (item.children)
visit(item.children, group);
if (!item.href)
return;
const target = new URL(item.href, current.origin);
if (current.pathname !== target.pathname &&
!current.pathname.startsWith(target.pathname + '/'))
return;
for (const [key, value] of target.searchParams)
if (current.searchParams.get(key) !== value)
return;
const score = target.pathname.length + target.searchParams.size * 100;
if (!match || score > match.score)
match = { group, score };
});
for (const group of groups)
visit(group.children ?? [], group.id);
return match?.group ?? null;
}
/** Select one destination, preferring a matching catalogue filter. */
export function currentNavigationItem(groups, url) {
const current = new URL(url, 'https://portal.invalid');
const best = { id: null, score: -1 };
const visit = (items) => {
for (const item of items) {
if (item.children)
visit(item.children);
if (!item.href)
continue;
const target = new URL(item.href, current.origin);
if (current.pathname !== target.pathname)
continue;
if ([...target.searchParams].some(([key, value]) => current.searchParams.get(key) !== value))
continue;
const score = target.searchParams.size;
if (score > best.score) {
best.id = item.id;
best.score = score;
}
}
};
for (const group of groups)
visit(group.children ?? []);
return best.id;
}