fix(navigation): expose work area and preserve authorised menu destinations in QA
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { profileLinks } from '@/components/profile-navigation';
|
||||
import {PortalSidebarNavigation} from '@/components/portal-sidebar-navigation';
|
||||
import type { ProfileAccess } from '@/types/profile-access';
|
||||
import { Link, usePage } from '@inertiajs/react';
|
||||
import { LayoutGrid } from 'lucide-react';
|
||||
import { portalNavigation } from '@/lib/portal-navigation';
|
||||
import { portalNavigation,canShowLegacyManagement } from '@/lib/portal-navigation';
|
||||
import AppLogo from '@/components/app-logo';
|
||||
import { NavMain } from '@/components/nav-main';
|
||||
import { NavUser } from '@/components/nav-user';
|
||||
import {
|
||||
Sidebar,
|
||||
@@ -20,6 +18,7 @@ import type { Auth } from '@/types';
|
||||
import type { OpportunityManagementAccess } from '@/types/opportunity-management';
|
||||
|
||||
export function AppSidebar() {
|
||||
const currentPage=usePage();
|
||||
const {
|
||||
auth,
|
||||
existingBusinessEnabled,
|
||||
@@ -27,7 +26,9 @@ export function AppSidebar() {
|
||||
aiEnabled,
|
||||
opportunityManagement,
|
||||
contentManagementHref,
|
||||
contentManagementAccess,
|
||||
profileAccess,
|
||||
scopedAdministration,
|
||||
} = usePage<{
|
||||
auth: Auth;
|
||||
existingBusinessEnabled?: boolean;
|
||||
@@ -36,45 +37,26 @@ export function AppSidebar() {
|
||||
profileAccess?: ProfileAccess | null;
|
||||
opportunityManagement?: OpportunityManagementAccess | null;
|
||||
contentManagementHref?: string | null;
|
||||
scopedAdministration?: {label:string;href:string}[];
|
||||
contentManagementAccess?: {opportunities?:{index:string;create?:string|null}};
|
||||
}>().props;
|
||||
const groups = portalNavigation({
|
||||
authenticated: !!auth.user,
|
||||
manager: auth.canManagePortal,
|
||||
manager: canShowLegacyManagement(auth),
|
||||
businesses: existingBusinessEnabled,
|
||||
education: educationEnabled,
|
||||
ai: aiEnabled,
|
||||
opportunityManagement,
|
||||
profileAccess,
|
||||
contentManagementHref,
|
||||
contentManagementAccess,
|
||||
scopedAdministration,
|
||||
legacyContent: currentPage.props.legacyContentEnabled as boolean|undefined,
|
||||
procurement: currentPage.props.procurementEnabled as boolean|undefined,
|
||||
businessReviewUrl: currentPage.props.businessReviewUrl as string|null|undefined,
|
||||
});
|
||||
const items = groups.map((group) => ({
|
||||
title: group.label,
|
||||
href: group.children?.find((item) => item.href)?.href ?? '/',
|
||||
icon: LayoutGrid,
|
||||
}));
|
||||
if (contentManagementHref) {
|
||||
items.unshift({ title: 'Gestão de conteúdos e oportunidades', href: contentManagementHref, icon: LayoutGrid });
|
||||
}
|
||||
if (auth.canManagePortal && opportunityManagement) {
|
||||
items.push({
|
||||
title: opportunityManagement.manage.label,
|
||||
href: opportunityManagement.manage.href,
|
||||
icon: LayoutGrid,
|
||||
});
|
||||
if (opportunityManagement.installed) {
|
||||
items.push({
|
||||
title: opportunityManagement.create.label,
|
||||
href: opportunityManagement.create.href,
|
||||
icon: LayoutGrid,
|
||||
});
|
||||
}
|
||||
}
|
||||
items.push(
|
||||
...profileLinks(profileAccess).map((link) => ({
|
||||
...link,
|
||||
icon: LayoutGrid,
|
||||
})),
|
||||
);
|
||||
return (
|
||||
<Sidebar collapsible="icon" variant="inset">
|
||||
<Sidebar collapsible="offcanvas" variant="inset">
|
||||
<SidebarHeader>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
@@ -88,7 +70,7 @@ export function AppSidebar() {
|
||||
</SidebarHeader>
|
||||
|
||||
<SidebarContent>
|
||||
<NavMain items={items} />
|
||||
<PortalSidebarNavigation groups={groups} url={currentPage.url}/>
|
||||
</SidebarContent>
|
||||
|
||||
<SidebarFooter>
|
||||
|
||||
@@ -31,6 +31,7 @@ import {
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
portalNavigation,
|
||||
canShowLegacyManagement,
|
||||
currentNavigationGroup,
|
||||
currentNavigationItem,
|
||||
} from '@/lib/portal-navigation';
|
||||
@@ -44,6 +45,7 @@ export function PortalGroupedMenu() {
|
||||
auth: {
|
||||
user: { name?: string; email?: string } | null;
|
||||
canManagePortal: boolean;
|
||||
legacyManagementAccess?:boolean;
|
||||
};
|
||||
existingBusinessEnabled?: boolean;
|
||||
businessReviewUrl?: string | null;
|
||||
@@ -54,6 +56,8 @@ export function PortalGroupedMenu() {
|
||||
profileAccess?: ProfileAccess | null;
|
||||
opportunityManagement?: OpportunityManagementAccess | null;
|
||||
scopedAdministration?: { label: string; href: string }[];
|
||||
contentManagementHref?: string | null;
|
||||
contentManagementAccess?: {opportunities?:{index:string;create?:string|null}};
|
||||
}>();
|
||||
const { t, language, requestCount } = useTempoUi();
|
||||
const mobile = useIsMobile();
|
||||
@@ -63,7 +67,7 @@ export function PortalGroupedMenu() {
|
||||
? { id: navigation.active, ...navigation.view.tools }
|
||||
: undefined,
|
||||
authenticated: !!props.auth?.user,
|
||||
manager: !!props.auth?.canManagePortal,
|
||||
manager: canShowLegacyManagement(props.auth),
|
||||
businesses: props.existingBusinessEnabled,
|
||||
businessReviewUrl: props.businessReviewUrl,
|
||||
education: props.educationEnabled,
|
||||
@@ -72,17 +76,10 @@ export function PortalGroupedMenu() {
|
||||
legacyContent: props.legacyContentEnabled,
|
||||
opportunityManagement: props.opportunityManagement,
|
||||
profileAccess: props.profileAccess,
|
||||
contentManagementHref: props.contentManagementHref,
|
||||
contentManagementAccess: props.contentManagementAccess,
|
||||
scopedAdministration: props.scopedAdministration,
|
||||
});
|
||||
if (props.scopedAdministration?.length)
|
||||
groups.push({
|
||||
id: 'scoped-administration',
|
||||
label: 'Administração',
|
||||
children: props.scopedAdministration.map((item, index) => ({
|
||||
id: `scoped-${index}`,
|
||||
label: item.label,
|
||||
href: item.href,
|
||||
})),
|
||||
});
|
||||
const current = currentNavigationGroup(groups, url);
|
||||
const currentItem = currentNavigationItem(groups, url);
|
||||
const [loggingOut, setLoggingOut] = useState(false);
|
||||
@@ -134,7 +131,7 @@ export function PortalGroupedMenu() {
|
||||
);
|
||||
const accountGroups = groups.filter(
|
||||
(group) =>
|
||||
!['home', 'discovery', 'realization', 'support'].includes(group.id),
|
||||
!['home', 'discovery', 'realization', 'support','work'].includes(group.id),
|
||||
);
|
||||
const panelLabel = `${t('O meu painel')} — ${requestCount} ${t(requestCount === 1 ? 'pedido recebido' : 'pedidos recebidos')}`;
|
||||
const institutionalCurrent = url.split('?')[0] === '/contacto';
|
||||
@@ -200,6 +197,7 @@ export function PortalGroupedMenu() {
|
||||
'discovery',
|
||||
'realization',
|
||||
'support',
|
||||
'work',
|
||||
].includes(group.id),
|
||||
)
|
||||
.map((group) => (
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import {Link} from '@inertiajs/react';
|
||||
import {LayoutGrid} from 'lucide-react';
|
||||
import type {ReactNode} from 'react';
|
||||
import type {PortalNavItem} from '@/lib/portal-navigation';
|
||||
import {currentNavigationItem} from '@/lib/portal-navigation';
|
||||
import {searchTerritoryHref} from '@/lib/search-territory';
|
||||
import {SidebarGroup,SidebarGroupLabel,SidebarMenu,SidebarMenuButton,SidebarMenuItem} from '@/components/ui/sidebar';
|
||||
|
||||
/** Render every authorised destination; a group is never reduced to its first link. */
|
||||
export function PortalSidebarNavigation({groups,url}:{groups:PortalNavItem[];url:string}){
|
||||
const active=currentNavigationItem(groups,url);
|
||||
const ordered=[...groups.filter(group=>group.id==='work'),...groups.filter(group=>group.id!=='work')];
|
||||
const links=(items:PortalNavItem[],depth=0):ReactNode=>items.map(item=>item.children?
|
||||
<li key={item.id} className="list-none"><p className="px-2 pt-3 pb-1 text-xs font-medium text-muted-foreground">{item.label}</p><ul className="ml-2 border-l pl-2">{links(item.children,depth+1)}</ul></li>:
|
||||
item.href?<SidebarMenuItem key={item.id}><SidebarMenuButton asChild isActive={item.id===active} className="h-auto min-h-8 whitespace-normal py-2"><Link href={searchTerritoryHref(item.href,url)} aria-current={item.id===active?'page':undefined}>{depth===0&&<LayoutGrid aria-hidden="true"/>}<span className="min-w-0 flex-1" style={{whiteSpace:'normal',overflow:'visible',textOverflow:'clip',overflowWrap:'anywhere'}}>{item.label}</span></Link></SidebarMenuButton></SidebarMenuItem>:null);
|
||||
return <nav aria-label="Navegação completa do portal">{ordered.map(group=><SidebarGroup key={group.id}><SidebarGroupLabel>{group.label}</SidebarGroupLabel><SidebarMenu>{links(group.children??[])}</SidebarMenu></SidebarGroup>)}</nav>;
|
||||
}
|
||||
@@ -8,6 +8,9 @@ export type PortalNavItem = {
|
||||
children?: PortalNavItem[];
|
||||
};
|
||||
export type PortalNavAccess = {
|
||||
contentManagementHref?: string | null;
|
||||
contentManagementAccess?: {opportunities?:{index:string;create?:string|null}};
|
||||
scopedAdministration?: { label: string; href: string }[];
|
||||
procurement?: boolean;
|
||||
authenticated: boolean;
|
||||
manager: boolean;
|
||||
@@ -31,6 +34,10 @@ const link = (id: string, label: string, href: string): PortalNavItem => ({
|
||||
label,
|
||||
href,
|
||||
});
|
||||
/** Display the existing server decision; a generic manager flag cannot override a scoped denial. */
|
||||
export function canShowLegacyManagement(auth?:{user?:unknown;canManagePortal?:boolean;legacyManagementAccess?:boolean}):boolean {
|
||||
return !!auth?.user && (auth.legacyManagementAccess??auth.canManagePortal??false);
|
||||
}
|
||||
|
||||
/** One route catalogue for the public shell and authenticated pages. */
|
||||
export function legacyPortalNavigation(
|
||||
@@ -371,6 +378,7 @@ export function legacyPortalNavigation(
|
||||
'Gestão de perfis',
|
||||
profile.administration,
|
||||
),
|
||||
link('profile-installation','Instalação dos perfis 040000','/management/profile-install'),
|
||||
]
|
||||
: []),
|
||||
],
|
||||
@@ -439,7 +447,10 @@ export function currentNavigationItem(
|
||||
|
||||
/** Investor organization; existing capability filters still determine private destinations. */
|
||||
export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
const previous = legacyPortalNavigation(access);
|
||||
const previous = legacyPortalNavigation({...access,manager:access.authenticated&&access.manager,profileAccess:access.authenticated?access.profileAccess:null});
|
||||
const workHub=access.authenticated?access.contentManagementHref:null;
|
||||
const workOpportunities=access.authenticated?access.contentManagementAccess?.opportunities:undefined;
|
||||
const workCreate=access.authenticated?(access.profileAccess?.create||workOpportunities?.create||(access.manager&&access.opportunityManagement?.installed?access.opportunityManagement.create.href:null)):null;
|
||||
return uniqueNavigationDestinations([
|
||||
{
|
||||
id: 'discovery',
|
||||
@@ -544,11 +555,20 @@ export function portalNavigation(access: PortalNavAccess): PortalNavItem[] {
|
||||
),
|
||||
],
|
||||
},
|
||||
...previous.filter((group) =>
|
||||
['account', 'management', 'profile-opportunities'].includes(
|
||||
group.id,
|
||||
),
|
||||
),
|
||||
...[{
|
||||
id: 'work',
|
||||
label: 'Área de trabalho',
|
||||
children: [
|
||||
link('work-entry', workHub ? 'Gestão de conteúdos e oportunidades':'Acesso à gestão', workHub || '/acesso-gestao'),
|
||||
...(workCreate ? [
|
||||
link('prepare-analysis', 'Preparar análise e ideia', workCreate+'?analysis=proactive'),
|
||||
] : []),
|
||||
...(workOpportunities ? [link('work-opportunities','Oportunidades em preparação',workOpportunities.index)] : []),
|
||||
...previous.filter(group=>['management','profile-opportunities'].includes(group.id)).flatMap(group=>group.children??[]),
|
||||
...(access.authenticated&&access.scopedAdministration?.length ? [{id:'work-administration',label:'Administração',children:access.scopedAdministration.map((item,index)=>link('scoped-'+index,item.label,item.href))}] : []),
|
||||
],
|
||||
}],
|
||||
...previous.filter((group) => group.id === 'account'),
|
||||
...(access.authenticated &&
|
||||
access.businesses &&
|
||||
access.businessReviewUrl
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {ProactiveInvestmentEditor,type ProactiveAnalysis,type ProactiveOptions} from '@/components/proactive-investment';
|
||||
import {ProactiveInvestmentEditor,newProactive,type ProactiveAnalysis,type ProactiveOptions} from '@/components/proactive-investment';
|
||||
import { ClassificationReview } from '@/components/opportunity-classification';
|
||||
import { createOperationKey } from '@/lib/operation-key';
|
||||
import { valueText } from '@/lib/value-text';
|
||||
@@ -140,8 +140,10 @@ export default function OpportunityDraft({
|
||||
auth: { user: { id: number } };
|
||||
canEditDraft?: boolean;
|
||||
}>().props;
|
||||
const proactiveEntryUrl=usePage().url;
|
||||
const [data, setData] = useState<Values>({
|
||||
...values,
|
||||
...(!record && !values.proactive && new URLSearchParams(proactiveEntryUrl.split('?')[1]??'').get('analysis')==='proactive' ? {proactive:newProactive()} : {}),
|
||||
...(profileMode
|
||||
? {
|
||||
organization_id: record
|
||||
|
||||
Reference in New Issue
Block a user