@@ -1,3 +1,6 @@
|
||||
import type { ProfileAccess } from '@/types/profile-access';
|
||||
import type { OpportunityManagementAccess } from '@/types/opportunity-management';
|
||||
|
||||
export type PortalNavItem = {
|
||||
id: string;
|
||||
label: string;
|
||||
@@ -10,6 +13,8 @@ export type PortalNavAccess = {
|
||||
businesses?: boolean;
|
||||
education?: boolean;
|
||||
ai?: boolean;
|
||||
profileAccess?: ProfileAccess | null;
|
||||
opportunityManagement?: OpportunityManagementAccess | null;
|
||||
};
|
||||
const link = (id: string, label: string, href: string): PortalNavItem => ({
|
||||
id,
|
||||
@@ -19,6 +24,7 @@ const link = (id: string, label: string, href: string): PortalNavItem => ({
|
||||
|
||||
/** One route catalogue for the public shell and authenticated pages. */
|
||||
export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
const opportunities = access.manager ? access.opportunityManagement : null;
|
||||
const groups: PortalNavItem[] = [
|
||||
{
|
||||
id: 'explore',
|
||||
@@ -124,7 +130,11 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
label: 'A minha área',
|
||||
children: access.authenticated
|
||||
? [
|
||||
link('dashboard', 'Painel', '/investidor'),
|
||||
link(
|
||||
'dashboard',
|
||||
opportunities ? 'Painel da gestão' : 'Painel',
|
||||
opportunities ? '/dashboard' : '/investidor',
|
||||
),
|
||||
link(
|
||||
'profile',
|
||||
'Perfil e empresas',
|
||||
@@ -164,6 +174,24 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
'/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',
|
||||
@@ -173,11 +201,15 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
'Sectores',
|
||||
'/management/sectors',
|
||||
),
|
||||
link(
|
||||
'manage-opportunities',
|
||||
'Oportunidades',
|
||||
'/management/opportunities',
|
||||
),
|
||||
...(!opportunities
|
||||
? [
|
||||
link(
|
||||
'manage-opportunities',
|
||||
'Oportunidades',
|
||||
'/management/opportunities',
|
||||
),
|
||||
]
|
||||
: []),
|
||||
link(
|
||||
'manage-projects',
|
||||
'Projectos',
|
||||
@@ -245,6 +277,17 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
: []),
|
||||
],
|
||||
});
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
export class ProfileValidationError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly fields: Record<string, string>,
|
||||
) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
export async function profileJson(
|
||||
url: string,
|
||||
data: object = {},
|
||||
method: 'GET' | 'POST' = 'POST',
|
||||
) {
|
||||
const cookie = document.cookie
|
||||
.split('; ')
|
||||
.find((c) => c.startsWith('XSRF-TOKEN='));
|
||||
const response = await fetch(url, {
|
||||
method,
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-XSRF-TOKEN': cookie ? decodeURIComponent(cookie.slice(11)) : '',
|
||||
},
|
||||
body: method === 'GET' ? undefined : JSON.stringify(data),
|
||||
});
|
||||
const result = await response.json();
|
||||
if (!response.ok)
|
||||
throw new ProfileValidationError(
|
||||
result.message ?? 'A ação não foi concluída.',
|
||||
Object.fromEntries(
|
||||
Object.entries(result.errors ?? {}).map(([key, value]) => [
|
||||
key,
|
||||
Array.isArray(value) ? value.join(' ') : String(value),
|
||||
]),
|
||||
),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user