From 9e70ef7bf8fc3bf3f73f990e0ffa3e16b5479328 Mon Sep 17 00:00:00 2001 From: Maarten de Waard Date: Mon, 3 Oct 2022 16:01:21 +0200 Subject: [PATCH] WIP on dashboard cards based on roles --- src/components/Tabs/Tabs.tsx | 1 - src/modules/dashboard/Dashboard.tsx | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Tabs/Tabs.tsx b/src/components/Tabs/Tabs.tsx index 92a1852..2c8dea9 100644 --- a/src/components/Tabs/Tabs.tsx +++ b/src/components/Tabs/Tabs.tsx @@ -26,7 +26,6 @@ export const Tabs = ({ tabs, onTabClick }: TabsProps) => { id="tabs" name="tabs" className="block w-full focus:ring-primary-500 focus:border-primary-500 border-gray-300 rounded-md" - // defaultValue={tabs ? tabs.find((tab) => tab.current).name : undefined} > {tabs.map((tab) => ( diff --git a/src/modules/dashboard/Dashboard.tsx b/src/modules/dashboard/Dashboard.tsx index cb8f44f..83538df 100644 --- a/src/modules/dashboard/Dashboard.tsx +++ b/src/modules/dashboard/Dashboard.tsx @@ -1,8 +1,9 @@ /* eslint-disable react-hooks/exhaustive-deps */ import React, { useEffect } from 'react'; import { useApps } from 'src/services/apps'; -import { DASHBOARD_QUICK_ACCESS } from './consts'; +import { useAuth } from 'src/services/auth'; import { DashboardCard, DashboardUtility } from './components'; +import { DASHBOARD_QUICK_ACCESS } from './consts'; export const Dashboard: React.FC = () => { const host = window.location.hostname; @@ -10,6 +11,8 @@ export const Dashboard: React.FC = () => { splitedDomain.shift(); const { apps, loadApps } = useApps(); + const { currentUser, isAdmin } = useAuth(); + // Tell React to load the apps useEffect(() => { loadApps(); @@ -29,6 +32,7 @@ export const Dashboard: React.FC = () => {
{apps .filter((app) => ['dashboard', 'monitoring'].indexOf(app.slug) === -1) + .filter((app) => currentUser?.app_roles.filter((role) => role.name === app.slug) !== []) .map((app) => ( ))}