306 lines
11 KiB
TypeScript
306 lines
11 KiB
TypeScript
export type PortalNavItem = {
|
|
id: string;
|
|
label: string;
|
|
href?: string;
|
|
children?: PortalNavItem[];
|
|
};
|
|
export type PortalNavAccess = {
|
|
authenticated: boolean;
|
|
manager: boolean;
|
|
businesses?: boolean;
|
|
education?: boolean;
|
|
ai?: boolean;
|
|
};
|
|
const link = (id: string, label: string, href: string): PortalNavItem => ({
|
|
id,
|
|
label,
|
|
href,
|
|
});
|
|
|
|
/** One route catalogue for the public shell and authenticated pages. */
|
|
export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
|
const groups: PortalNavItem[] = [
|
|
{
|
|
id: 'explore',
|
|
label: 'Explorar investimentos',
|
|
children: [
|
|
link('opportunities', 'Oportunidades', '/oportunidades'),
|
|
link('sectors', 'Sectores', '/sectores'),
|
|
{
|
|
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',
|
|
),
|
|
]
|
|
: []),
|
|
],
|
|
},
|
|
{
|
|
id: 'account',
|
|
label: 'A minha área',
|
|
children: access.authenticated
|
|
? [
|
|
link('dashboard', 'Painel', '/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'),
|
|
{
|
|
id: 'manage-catalogue',
|
|
label: 'Catálogo de investimento',
|
|
children: [
|
|
link(
|
|
'manage-sectors',
|
|
'Sectores',
|
|
'/management/sectors',
|
|
),
|
|
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',
|
|
),
|
|
]
|
|
: []),
|
|
],
|
|
});
|
|
return groups;
|
|
}
|
|
|
|
export function currentNavigationGroup(
|
|
groups: PortalNavItem[],
|
|
url: string,
|
|
): string | null {
|
|
const current = new URL(url, 'https://portal.invalid');
|
|
let match: { group: string; score: number } | null = null;
|
|
const visit = (items: PortalNavItem[], group: string) =>
|
|
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 as { group: string; score: number } | null)?.group ?? null;
|
|
}
|
|
|
|
/** Select one destination, preferring a matching catalogue filter. */
|
|
export function currentNavigationItem(
|
|
groups: PortalNavItem[],
|
|
url: string,
|
|
): string | null {
|
|
const current = new URL(url, 'https://portal.invalid');
|
|
const best = { id: null as string | null, score: -1 };
|
|
const visit = (items: PortalNavItem[]) => {
|
|
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;
|
|
}
|