make ismaster admin route work

This commit is contained in:
Simon Larsen 2023-09-05 15:41:12 +05:30
parent d7b415c14c
commit ca20e599fa
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
11 changed files with 70 additions and 12 deletions

View File

@ -22,6 +22,7 @@ export default abstract class LoginUtil {
UserUtil.setEmail(user.email as Email);
UserUtil.setUserId(user.id as ObjectID);
UserUtil.setName(user.name as Name);
UserUtil.setIsMasterAdmin(user.isMasterAdmin as boolean);
Analytics.userAuth(user.email!);

View File

@ -9,7 +9,7 @@ import {
import Navigation from 'CommonUI/src/Utils/Navigation';
import User from 'CommonUI/src/Utils/User';
import URL from 'Common/Types/API/URL';
import { ACCOUNTS_URL } from 'CommonUI/src/Config';
import { ACCOUNTS_URL, DASHBOARD_URL } from 'CommonUI/src/Config';
import MasterPage from './Components/MasterPage/MasterPage';
import RouteMap from './Utils/RouteMap';
import PageMap from './Utils/PageMap';
@ -32,6 +32,10 @@ const App: () => JSX.Element = () => {
Navigation.navigate(URL.fromString(ACCOUNTS_URL.toString()));
}
}
if(!User.isMasterAdmin()){
Navigation.navigate(URL.fromString(DASHBOARD_URL.toString()))
}
return (
<MasterPage>

View File

@ -11,13 +11,33 @@ const DashboardNavbar: FunctionComponent = (): ReactElement => {
return (
<NavBar>
<NavBarItem
title="Home"
icon={IconProp.Home}
title="Users"
icon={IconProp.User}
route={RouteUtil.populateRouteParams(
RouteMap[PageMap.HOME] as Route
RouteMap[PageMap.USERS] as Route
)}
></NavBarItem>
<NavBarItem
title="Projects"
icon={IconProp.Folder}
route={RouteUtil.populateRouteParams(
RouteMap[PageMap.PROJECTS] as Route
)}
></NavBarItem>
<NavBarItem
title="Settings"
icon={IconProp.Settings}
route={RouteUtil.populateRouteParams(
RouteMap[PageMap.SETTINGS] as Route
)}
></NavBarItem>
</NavBar>
);
};

View File

@ -1,7 +1,11 @@
enum PageMap {
INIT = 'INIT',
HOME = 'HOME',
LOGOUT = 'LOGOUT'
LOGOUT = 'LOGOUT',
SETTINGS = 'SETTINGS',
USERS = 'USERS',
PROJECTS = 'PROJECTS',
}
export default PageMap;

View File

@ -5,9 +5,12 @@ import RouteParams from './RouteParams';
import ObjectID from 'Common/Types/ObjectID';
const RouteMap: Dictionary<Route> = {
[PageMap.INIT]: new Route(`/admin-dashboard`),
[PageMap.HOME]: new Route(`/admin-dashboard`),
[PageMap.LOGOUT]: new Route(`/admin-dashboard/logout`)
[PageMap.INIT]: new Route(`/admin`),
[PageMap.HOME]: new Route(`/admin`),
[PageMap.LOGOUT]: new Route(`/admin/logout`),
[PageMap.SETTINGS]: new Route(`/admin/settings`),
[PageMap.PROJECTS]: new Route(`/admin/projects`),
[PageMap.USERS]: new Route(`/admin/users`),
};
export class RouteUtil {

View File

@ -184,7 +184,7 @@ export const ApiReferenceRoute: Route = new Route(
);
export const AdminDashboardRoute: Route = new Route(
process.env['ADMINDASHBOARD_ROUTE'] || '/admin-dashboard'
process.env['ADMIN_DASHBOARD_ROUTE'] || '/admin-dashboard'
);
export const IsProduction: boolean =

View File

@ -14,7 +14,13 @@ const TopAlert: FunctionComponent<ComponentProps> = (
<p className="text-sm leading-6 text-white w-full">
<div className='w-full'>
<strong className="font-semibold">{props.title}</strong>&nbsp;-&nbsp;
{props.description}
{props.description} &nbsp;&nbsp;
<a
href="#"
className="flex-none rounded-full bg-gray-200 px-3.5 py-1 text-sm font-semibold text-gray-900 shadow-sm hover:bg-gray-300 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-gray-900"
>
Go to User Dashboard <span aria-hidden="true">&rarr;</span>
</a>
</div>
</p>
</div>

View File

@ -47,7 +47,7 @@ export const HELM_ROUTE: Route = new Route(env('HELMCHART_ROUTE'));
export const API_DOCS_ROUTE: Route = new Route(env('API_REFERENCE_ROUTE'));
export const ADMIN_DASHBOARD_ROUTE: Route = new Route(
env('ADMINDASHBOARD_ROUTE')
env('ADMIN_DASHBOARD_ROUTE')
);
export const ACCOUNTS_ROUTE: Route = new Route(env('ACCOUNTS_ROUTE'));
export const HOME_ROUTE: Route = new Route(env('HOME_ROUTE'));

View File

@ -118,6 +118,14 @@ export default class User {
return sessionStorage.removeItem('initialUrl');
}
public static isMasterAdmin(): boolean {
return LocalStorage.getItem('is_master_admin') as boolean;
}
public static setIsMasterAdmin(isMasterAdmin: boolean): void {
LocalStorage.setItem('is_master_admin', isMasterAdmin);
}
public static isLoggedIn(): boolean {
return LocalStorage.getItem('access_token') ? true : false;
}

View File

@ -7,6 +7,9 @@ import BlankProfilePic from 'CommonUI/src/Images/users/blank-profile.svg';
import HeaderIconDropdownButton from 'CommonUI/src/Components/Header/HeaderIconDropdownButton';
import IconDropdownItem from 'CommonUI/src/Components/Header/IconDropdown/IconDropdownItem';
import IconDropdownMenu from 'CommonUI/src/Components/Header/IconDropdown/IconDropdownMenu';
import Navigation from 'CommonUI/src/Utils/Navigation';
import { ADMIN_DASHBOARD_URL } from 'CommonUI/src/Config';
import User from 'CommonUI/src/Utils/User';
export interface ComponentProps {
onClickUserProfile: () => void;
@ -37,6 +40,15 @@ const DashboardUserProfile: FunctionComponent<ComponentProps> = (
icon={IconProp.User}
/>
{User.isMasterAdmin() ? <IconDropdownItem
title="Admin Settings"
onClick={() => {
setIsDropdownVisible(false);
Navigation.navigate(ADMIN_DASHBOARD_URL);
}}
icon={IconProp.Settings}
/> : <></>}
<IconDropdownItem
title="Log out"
onClick={() => {

View File

@ -109,7 +109,7 @@ REALTIME_ROUTE=/realtime
API_DOCS_ROUTE=/reference
NOTIFICATION_ROUTE=/notification
DASHBOARD_ROUTE=/dashboard
ADMIN_DASHBOARD_ROUTE=/admin-dashboard
ADMIN_DASHBOARD_ROUTE=/admin
DASHBOARD_API_ROUTE=/api
WORKFLOW_ROUTE=/workflow
LINK_SHORTENER_ROUTE=/l