Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
adjust disables to enabled (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrund-tsi authored Feb 21, 2023
1 parent 3f0ddf8 commit 3c88ec3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/components/LandingPage/landing-page.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import CwaSpinner from '../spinner/spinner.component';
import LandingButton from './LandingButton';
import LandingCancellationText from './LandingCancellationText';
import LandingDisclaimerButton from './LandingDisclaimerButton';
import useDisabledTenant from '../../misc/useDisabledTenant';
import useEnabledTenant from '../../misc/useEnabledTenant';

const LandingPage = (props: any) => {
const context = React.useContext(AppContext);
Expand All @@ -42,7 +42,7 @@ const LandingPage = (props: any) => {
const { t } = useTranslation();
const { keycloak } = useKeycloak();
const [, , , getDownloadLink] = useCancallation();
const disabledUserManagement = useDisabledTenant();
const enabledUserManagement = useEnabledTenant();

const [cancellationStep, setCancellationStep] = React.useState<CancellationSteps>(
CancellationSteps.NO_CANCEL
Expand Down Expand Up @@ -121,7 +121,7 @@ const LandingPage = (props: any) => {
/>

<LandingButton
hasRole={utils.hasRole(keycloak, 'c19_quick_test_admin') && !disabledUserManagement}
hasRole={utils.hasRole(keycloak, 'c19_quick_test_admin') && enabledUserManagement}
title={t('translation:user-management')}
onClick={navigation.toUserManagement}
/>
Expand Down
6 changes: 3 additions & 3 deletions src/components/modules/private-route.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import AppContext from '../../store/app-context';

interface PrivateRouteProps {
roles?: string[];
disabled?: boolean;
enabled?: boolean;
}

const PrivateRoute = (props: PrivateRouteProps) => {
Expand All @@ -38,7 +38,7 @@ const PrivateRoute = (props: PrivateRouteProps) => {
const [isInit, setIsInit] = React.useState(false);
const [isAuthorized, setIsAuthorized] = React.useState(false);

const { roles, disabled } = props;
const { roles, enabled } = props;

React.useEffect(() => {
if (keycloak) {
Expand Down Expand Up @@ -66,7 +66,7 @@ const PrivateRoute = (props: PrivateRouteProps) => {
return (
<>
{isInit &&
(isAuthorized && !disabled ? (
(isAuthorized && enabled ? (
<Outlet />
) : (
<Navigate
Expand Down
16 changes: 8 additions & 8 deletions src/misc/useDisabledTenant.ts → src/misc/useEnabledTenant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ import React, { useEffect } from 'react';
import AppContext from '../store/app-context';
import useLocalStorage from './useLocalStorage';

const useDisabledTenant = () => {
const useEnabledTenant = () => {
const { contextConfig } = React.useContext(AppContext);
const [isDisbled, setIsDisabled] = React.useState(false);
const [disabledList, setDisabledList] = React.useState(['']);
const [isEnbled, setIsEnabled] = React.useState(false);
const [enabledFlag, setEnabledFlag] = React.useState('');
const [storedTenant] = useLocalStorage('mandant', '');

// get disabled list from context config
useEffect(() => {
contextConfig && setDisabledList(contextConfig['disable-user-management']);
contextConfig && setEnabledFlag(contextConfig['enable-user-management']);
}, [contextConfig]);

// set disabled state if current tenant is in disabled-list
React.useEffect(() => {
setIsDisabled(!!(storedTenant && disabledList && disabledList.includes(storedTenant)));
}, [storedTenant, disabledList]);
setIsEnabled(!!(storedTenant && enabledFlag && enabledFlag === storedTenant));
}, [storedTenant, enabledFlag]);

return isDisbled;
return isEnbled;
};

export default useDisabledTenant;
export default useEnabledTenant;
6 changes: 3 additions & 3 deletions src/routing.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ import ErrorPage from './components/modals/error-page.component';
import NotificationToast from './components/modals/notification-toast.component';
import PrivateRoute from './components/modules/private-route.component';
import AppContext from './store/app-context';
import useDisabledTenant from './misc/useDisabledTenant';
import useEnabledTenant from './misc/useEnabledTenant';

const Routing = () => {
const { t } = useTranslation();
const context = React.useContext(AppContext);
const [quickTest, setQuickTest] = React.useState<IQuickTest>();
const [notificationShow, setNotificationShow] = React.useState(false);
const userManagementRouteIsDisabled = useDisabledTenant();
const userManagementRouteIsEnabled = useEnabledTenant();

document.title = t('translation:title');

Expand Down Expand Up @@ -133,7 +133,7 @@ const Routing = () => {
element={
<PrivateRoute
roles={['c19_quick_test_admin']}
disabled={userManagementRouteIsDisabled}
enabled={userManagementRouteIsEnabled}
/>
}
>
Expand Down

0 comments on commit 3c88ec3

Please sign in to comment.