WIP on dashboard cards based on roles

This commit is contained in:
Maarten de Waard 2022-10-03 16:01:21 +02:00
parent aea093332b
commit 9e70ef7bf8
No known key found for this signature in database
GPG key ID: 1D3E893A657CC8DA
2 changed files with 5 additions and 2 deletions

View file

@ -26,7 +26,6 @@ export const Tabs = ({ tabs, onTabClick }: TabsProps) => {
id="tabs" id="tabs"
name="tabs" name="tabs"
className="block w-full focus:ring-primary-500 focus:border-primary-500 border-gray-300 rounded-md" 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) => ( {tabs.map((tab) => (
<option key={tab.name}>{tab.name}</option> <option key={tab.name}>{tab.name}</option>

View file

@ -1,8 +1,9 @@
/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect } from 'react'; import React, { useEffect } from 'react';
import { useApps } from 'src/services/apps'; import { useApps } from 'src/services/apps';
import { DASHBOARD_QUICK_ACCESS } from './consts'; import { useAuth } from 'src/services/auth';
import { DashboardCard, DashboardUtility } from './components'; import { DashboardCard, DashboardUtility } from './components';
import { DASHBOARD_QUICK_ACCESS } from './consts';
export const Dashboard: React.FC = () => { export const Dashboard: React.FC = () => {
const host = window.location.hostname; const host = window.location.hostname;
@ -10,6 +11,8 @@ export const Dashboard: React.FC = () => {
splitedDomain.shift(); splitedDomain.shift();
const { apps, loadApps } = useApps(); const { apps, loadApps } = useApps();
const { currentUser, isAdmin } = useAuth();
// Tell React to load the apps // Tell React to load the apps
useEffect(() => { useEffect(() => {
loadApps(); loadApps();
@ -29,6 +32,7 @@ export const Dashboard: React.FC = () => {
<div className="grid grid-cols-1 md:grid-cols-2 md:gap-4 lg:grid-cols-4 mb-10"> <div className="grid grid-cols-1 md:grid-cols-2 md:gap-4 lg:grid-cols-4 mb-10">
{apps {apps
.filter((app) => ['dashboard', 'monitoring'].indexOf(app.slug) === -1) .filter((app) => ['dashboard', 'monitoring'].indexOf(app.slug) === -1)
.filter((app) => currentUser?.app_roles.filter((role) => role.name === app.slug) !== [])
.map((app) => ( .map((app) => (
<DashboardCard app={app} key={app.name} /> <DashboardCard app={app} key={app.name} />
))} ))}