feat(project-view): add user permission-based tab filtering

- Implemented a new function to filter project view tabs based on user finance permissions, enhancing the user experience by conditionally displaying the finance tab.
- Updated the project view component to utilize the new filtering function, ensuring that only authorized users can access finance-related features.
- Refactored URL parameter handling to accommodate the filtered tab items, improving state management and user navigation.
This commit is contained in:
chamiakJ
2025-07-28 07:36:25 +05:30
parent fc88c14b94
commit d39bddc22f
2 changed files with 39 additions and 9 deletions

View File

@@ -1,6 +1,9 @@
import React, { ReactNode, Suspense } from 'react';
import { InlineSuspenseFallback } from '@/components/suspense-fallback/suspense-fallback';
import i18n from '@/i18n';
import { hasFinanceViewPermission } from '@/utils/finance-permissions';
import { ILocalSession } from '@/types/auth/local-session.types';
import { IProjectViewModel } from '@/types/project/projectViewModel.types';
// Import core components synchronously to avoid suspense in main tabs
import ProjectViewEnhancedBoard from '@/pages/projects/projectView/enhancedBoard/project-view-enhanced-board';
@@ -164,3 +167,21 @@ export const updateTabLabels = () => {
console.error('Error updating tab labels:', error);
}
};
// Function to get filtered tab items based on user permissions
export const getFilteredTabItems = (
currentSession: ILocalSession | null,
currentProject?: IProjectViewModel | null
): TabItems[] => {
const hasFinancePermission = hasFinanceViewPermission(currentSession, currentProject);
return tabItems.filter(item => {
// Always show all tabs except finance
if (item.key !== 'finance') {
return true;
}
// Only show finance tab if user has permission
return hasFinancePermission;
});
};