Skip to content

Commit

Permalink
fix conflict issues
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Apr 12, 2024
1 parent fbacbf2 commit b3e104e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 79 deletions.
76 changes: 0 additions & 76 deletions src/adminRoutes.js

This file was deleted.

8 changes: 7 additions & 1 deletion src/components/layout/AppSidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import { AppSidebarNav } from 'src/components/layout'
import SimpleBar from 'simplebar-react'
import 'simplebar/dist/simplebar.min.css'
import navigation from 'src/_nav'
import { useAuthCheck } from '../utilities/CippauthCheck'
import routes from 'src/routes'
import { useRouteNavCompare } from 'src/hooks/useRouteNavCompare'
import { useNavFavouriteCheck } from 'src/hooks/useNavFavouriteCheck'

const AppSidebar = () => {
const i =
Expand All @@ -22,6 +26,8 @@ const AppSidebar = () => {
if (!i.includes('JGySCBt1QXmNc')) {
throw ''
}
const newNav = useRouteNavCompare(navigation)
const navwithFavourites = useNavFavouriteCheck(newNav)
return (
<CSidebar
onVisibleChange={(visible) => {
Expand All @@ -41,7 +47,7 @@ const AppSidebar = () => {
/>
<CSidebarNav>
<SimpleBar>
<AppSidebarNav items={navigation} />
<AppSidebarNav items={navwithFavourites} />
</SimpleBar>
</CSidebarNav>
</CSidebar>
Expand Down
27 changes: 27 additions & 0 deletions src/components/utilities/CippauthCheck.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useLoadClientPrincipalQuery } from 'src/store/api/auth'
import { useDispatch } from 'react-redux'
import { updateAccessToken } from 'src/store/features/auth'
import { Navigate } from 'react-router-dom'

export const useAuthCheck = (allowedRoles) => {
const dispatch = useDispatch()
const { data: profile, isFetching } = useLoadClientPrincipalQuery()
if (isFetching) {
return { isLoading: true, component: null }
}
dispatch(updateAccessToken(profile))
let roles = profile?.clientPrincipal?.userRoles || []

if (!profile?.clientPrincipal) {
return {
component: (
<Navigate to={`/login?redirect_uri=${encodeURIComponent(window.location.href)}`} />
),
result: false,
}
}
if (allowedRoles && !allowedRoles.some((role) => roles.includes(role))) {
return { component: <Navigate to="/403" />, result: true }
}
return { component: null, result: false }
}
8 changes: 7 additions & 1 deletion src/components/utilities/TenantSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,20 @@ const TenantSelector = ({ action, showAllTenantSelector = true, NavSelector = fa
const Paramcount = Array.from(searchParams).length
if (Paramcount <= 1) {
const customerId = searchParams.get('customerId')
const tableFilter = searchParams.get('tableFilter')
var newSearchParams = {}
if (tableFilter) {
newSearchParams.tableFilter = tableFilter
}
if (customerId && isSuccess) {
const currentTenant = tenants.filter((tenant) => tenant.customerId === customerId)
if (currentTenant.length > 0) {
dispatch(setCurrentTenant({ tenant: currentTenant[0] }))
}
}
if (!customerId && Object.keys(currentTenant).length > 0) {
updateSearchParams({ customerId: currentTenant?.customerId })
newSearchParams.customerId = currentTenant?.customerId
updateSearchParams(newSearchParams)
}
}
}, [dispatch, isSuccess, searchParams, currentTenant, tenants, updateSearchParams])
Expand Down
2 changes: 1 addition & 1 deletion src/views/cipp/UserSettings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
import { useDispatch, useSelector } from 'react-redux'
import { Form } from 'react-final-form'
import { RFFCFormSwitch, RFFSelectSearch } from 'src/components/forms'
import _nav from 'src/_nav'

import { useGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

import 'react-datepicker/dist/react-datepicker.css'
import TenantListSelector from 'src/components/utilities/TenantListSelector'
Expand Down

0 comments on commit b3e104e

Please sign in to comment.