Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
Show administration page only when user is admin
Browse files Browse the repository at this point in the history
  • Loading branch information
floriandejonckheere committed Nov 22, 2023
1 parent ab8ade4 commit 62d9d4f
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions src/layouts/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
import { ReactElement } from 'react'
import { NavLink, Outlet } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'

import {
Cog6ToothIcon,
HomeIcon,
ChartBarIcon,
LightBulbIcon
} from '@heroicons/react/24/solid'

function Dashboard(): ReactElement {
import { me } from '../api/users'

export default function Dashboard(): ReactElement {
const { isPending, isError, data } = useQuery({
queryKey: ['me'],
queryFn: me
})

return (
<div className="flex flex-row w-full h-full bg-gray-50 dark:bg-slate-900">
<div
Expand Down Expand Up @@ -65,21 +74,25 @@ function Dashboard(): ReactElement {
Suggestions
</NavLink>
</li>
<li>
<NavLink
to="/administration"
className={({ isActive }) =>
`w-full flex items-center gap-x-3.5 py-2 px-2.5 text-sm text-white rounded-lg focus:outline-none focus:ring-1 focus:ring-gray-600 ${
isActive
? 'bg-sky-900'
: 'hover:bg-sky-900 hover:text-white-300'
}`
}
>
<Cog6ToothIcon className="h-5 w-5" />
Administration
</NavLink>
</li>
{!isPending &&

Check failure on line 77 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `⏎··············!isError·&&⏎·············` with `·!isError·&&`
!isError &&
data.is_admin && (
<li>

Check failure on line 80 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
<NavLink

Check failure on line 81 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
to="/administration"

Check failure on line 82 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
className={({ isActive }) =>

Check failure on line 83 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
`w-full flex items-center gap-x-3.5 py-2 px-2.5 text-sm text-white rounded-lg focus:outline-none focus:ring-1 focus:ring-gray-600 ${

Check failure on line 84 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
isActive

Check failure on line 85 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
? 'bg-sky-900'

Check failure on line 86 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
: 'hover:bg-sky-900 hover:text-white-300'

Check failure on line 87 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Delete `··`
}`

Check failure on line 88 in src/layouts/dashboard.tsx

View workflow job for this annotation

GitHub Actions / Lint

Replace `······················` with `····················`
}
>
<Cog6ToothIcon className="h-5 w-5" />
Administration
</NavLink>
</li>
)}
</ul>
</nav>
</div>
Expand All @@ -90,5 +103,3 @@ function Dashboard(): ReactElement {
</div>
)
}

export default Dashboard

0 comments on commit 62d9d4f

Please sign in to comment.