Implemented rbac
This commit is contained in:
@@ -3,6 +3,7 @@ import { createPortal } from 'react-dom';
|
||||
import { Download, FileSpreadsheet, FileText, ChevronDown } from 'lucide-react';
|
||||
import { ExportColumn, exportToSpreadsheet, exportToPdf } from '../../utils/exportUtils';
|
||||
import { useAuth } from '../../auth/AuthProvider';
|
||||
import { useRbac, RoleClaim } from '../../auth/rbac';
|
||||
|
||||
export interface ExportButtonProps<T = any> {
|
||||
title: string;
|
||||
@@ -13,6 +14,7 @@ export interface ExportButtonProps<T = any> {
|
||||
label?: string;
|
||||
size?: 'sm' | 'md';
|
||||
className?: string;
|
||||
claim?: RoleClaim;
|
||||
}
|
||||
|
||||
export function ExportButton<T>({
|
||||
@@ -24,14 +26,17 @@ export function ExportButton<T>({
|
||||
label = 'Export',
|
||||
size = 'md',
|
||||
className = '',
|
||||
claim,
|
||||
}: ExportButtonProps<T>) {
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [menuPosition, setMenuPosition] = useState<{ top: number; right: number } | null>(null);
|
||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
const { user, claims, tenantId } = useAuth();
|
||||
const { canExport } = useRbac();
|
||||
|
||||
const isDisabled = !data || data.length === 0;
|
||||
const isClaimAllowed = claim ? canExport(claim) : true;
|
||||
const isDisabled = !data || data.length === 0 || !isClaimAllowed;
|
||||
|
||||
const updatePosition = useCallback(() => {
|
||||
if (!dropdownRef.current) return;
|
||||
@@ -67,10 +72,10 @@ export function ExportButton<T>({
|
||||
};
|
||||
}, [isOpen, updatePosition]);
|
||||
|
||||
const handleExportSpreadsheet = () => {
|
||||
const handleExportSpreadsheet = async () => {
|
||||
if (isDisabled) return;
|
||||
setIsOpen(false);
|
||||
exportToSpreadsheet({
|
||||
await exportToSpreadsheet({
|
||||
title,
|
||||
subtitle,
|
||||
filename,
|
||||
@@ -81,10 +86,10 @@ export function ExportButton<T>({
|
||||
});
|
||||
};
|
||||
|
||||
const handleExportPdf = () => {
|
||||
const handleExportPdf = async () => {
|
||||
if (isDisabled) return;
|
||||
setIsOpen(false);
|
||||
exportToPdf({
|
||||
await exportToPdf({
|
||||
title,
|
||||
subtitle,
|
||||
filename,
|
||||
|
||||
Reference in New Issue
Block a user