From 70ed1e2a658563658e373c60abe9d0742d363fde Mon Sep 17 00:00:00 2001
From: "kris@sentientgeeks.com"
Date: Wed, 8 Sep 2021 21:55:34 +0530
Subject: [PATCH] user role added
---
src/@core/auth/utils.js | 2 +-
src/@core/layouts/components/footer/index.js | 4 ----
.../layouts/components/menu/horizontal-menu/index.js | 2 +-
src/@core/layouts/components/navbar/UserDropdown.js | 5 +++--
src/auth/utils.js | 10 +++++++++-
src/navigation/horizontal/clientHome.js | 10 ++++++++++
src/navigation/horizontal/index.js | 9 ++++++++-
src/navigation/vertical/index.js | 7 ++++---
src/router/Router.js | 6 ++----
src/router/routes/Pages.js | 5 +++++
src/utility/Utils.js | 9 ++++++++-
src/views/apps/client/dashboard/index.js | 12 ++++++++++++
src/views/apps/todo/index.js | 1 +
src/views/pages/authentication/Login.js | 1 -
14 files changed, 64 insertions(+), 19 deletions(-)
create mode 100644 src/navigation/horizontal/clientHome.js
create mode 100644 src/views/apps/client/dashboard/index.js
diff --git a/src/@core/auth/utils.js b/src/@core/auth/utils.js
index aa66aed..0b9d1c6 100644
--- a/src/@core/auth/utils.js
+++ b/src/@core/auth/utils.js
@@ -22,6 +22,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/
export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/'
- if (userRole === 'client') return { name: 'access-control' }
+ if (userRole === 'client') return '/'
return { name: 'auth-login' }
}
diff --git a/src/@core/layouts/components/footer/index.js b/src/@core/layouts/components/footer/index.js
index 73cfecc..0d79f3f 100644
--- a/src/@core/layouts/components/footer/index.js
+++ b/src/@core/layouts/components/footer/index.js
@@ -11,10 +11,6 @@ const Footer = () => {
, All rights Reserved
-
- Hand-crafted & Made with
-
-
)
}
diff --git a/src/@core/layouts/components/menu/horizontal-menu/index.js b/src/@core/layouts/components/menu/horizontal-menu/index.js
index 7a42f04..7294c0d 100644
--- a/src/@core/layouts/components/menu/horizontal-menu/index.js
+++ b/src/@core/layouts/components/menu/horizontal-menu/index.js
@@ -1,5 +1,5 @@
// ** React Imports
-import { useState } from 'react'
+import React, { useState, useEffect, lazy } from 'react'
// ** Horizontal Menu Array
import navigation from '@src/navigation/horizontal'
diff --git a/src/@core/layouts/components/navbar/UserDropdown.js b/src/@core/layouts/components/navbar/UserDropdown.js
index bcb158b..857acf8 100644
--- a/src/@core/layouts/components/navbar/UserDropdown.js
+++ b/src/@core/layouts/components/navbar/UserDropdown.js
@@ -6,7 +6,7 @@ import { Link } from 'react-router-dom'
import Avatar from '@components/avatar'
// ** Utils
-import { isUserLoggedIn } from '@utils'
+import { isUserLoggedIn, getUserData } from '@utils'
// ** Store & Actions
import { useDispatch } from 'react-redux'
@@ -50,11 +50,12 @@ const UserDropdown = () => {
Profile
+ {getUserData.role === "admin" &&
Tasks
-
+}
diff --git a/src/auth/utils.js b/src/auth/utils.js
index aa66aed..58ec4f1 100644
--- a/src/auth/utils.js
+++ b/src/auth/utils.js
@@ -1,4 +1,5 @@
import useJwt from '@src/@core/auth/jwt/useJwt'
+import { DefaultRoute } from '../router/routes'
/**
* Return if user is logged in
@@ -10,6 +11,13 @@ export const isUserLoggedIn = () => {
return localStorage.getItem('userData') && localStorage.getItem(useJwt.jwtConfig.storageTokenKeyName)
}
+export const getDefaultRoute = () => {
+ const userdata = JSON.parse(localStorage.getItem("userData"))
+ const userrole = userdata === null ? '' : userdata.role
+ const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
+ return redirect
+}
+
export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
/**
@@ -22,6 +30,6 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/
export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/'
- if (userRole === 'client') return { name: 'access-control' }
+ if (userRole === 'client') return '/'
return { name: 'auth-login' }
}
diff --git a/src/navigation/horizontal/clientHome.js b/src/navigation/horizontal/clientHome.js
new file mode 100644
index 0000000..1610a2c
--- /dev/null
+++ b/src/navigation/horizontal/clientHome.js
@@ -0,0 +1,10 @@
+import { Home, Activity, ShoppingCart } from 'react-feather'
+
+export default [
+ {
+ id: 'client',
+ title: 'Dashboard',
+ icon: ,
+ navLink: '/client'
+ }
+]
diff --git a/src/navigation/horizontal/index.js b/src/navigation/horizontal/index.js
index ecb7e54..e898e03 100644
--- a/src/navigation/horizontal/index.js
+++ b/src/navigation/horizontal/index.js
@@ -1,7 +1,14 @@
// ** Navigation sections imports
import apps from './apps'
import dashboards from './dashboards'
+import clientHome from './clientHome'
+const userdata = JSON.parse(localStorage.getItem("userData"))
+const userrole = userdata === null ? '' : userdata.role
// ** Merge & Export
-export default [...dashboards, ...apps]
+const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...clientHome] : [])
+console.log(userrole)
+console.log(navarr)
+export default navarr
+
diff --git a/src/navigation/vertical/index.js b/src/navigation/vertical/index.js
index 4fe39b3..13907c9 100644
--- a/src/navigation/vertical/index.js
+++ b/src/navigation/vertical/index.js
@@ -1,8 +1,9 @@
// ** Navigation sections imports
import apps from './apps'
-
import dashboards from './dashboards'
-
+const userdata = JSON.parse(localStorage.getItem("userData"))
+const userrole = userdata === null ? '' : userdata.role
// ** Merge & Export
-export default [...dashboards, ...apps]
+const navarr = (userrole === "admin") ? [...dashboards, ...apps] : ((userrole === "client") ? [...dashboards] : [])
+export default navarr
diff --git a/src/router/Router.js b/src/router/Router.js
index 7b7b28c..30303ef 100644
--- a/src/router/Router.js
+++ b/src/router/Router.js
@@ -2,7 +2,7 @@
import { Suspense, useContext, lazy } from 'react'
// ** Utils
-import { isUserLoggedIn } from '@utils'
+import { isUserLoggedIn, getDefaultRoute } from '@utils'
import { useLayout } from '@hooks/useLayout'
import { AbilityContext } from '@src/utility/context/Can'
import { useRouterTransition } from '@hooks/useRouterTransition'
@@ -85,11 +85,9 @@ const Router = () => {
** If user is not Logged in & route.meta.authRoute, !route.meta.publicRoute are undefined
** Then redirect user to login
*/
-
return
} else if (route.meta && route.meta.authRoute && isUserLoggedIn()) {
// ** If route has meta and authRole and user is Logged in then redirect user to home page (DefaultRoute)
-
return
// } else if (isUserLoggedIn() && !ability.can(action || 'read', resource)) {
// // ** If user is Logged in and doesn't have ability to visit the page redirect the user to Not Authorized
@@ -197,7 +195,7 @@ const Router = () => {
exact
path='/'
render={() => {
- return isUserLoggedIn() ? :
+ return isUserLoggedIn() ? :
}}
/>
{/* Not Auth Route */}
diff --git a/src/router/routes/Pages.js b/src/router/routes/Pages.js
index 4df628d..08ac4f9 100644
--- a/src/router/routes/Pages.js
+++ b/src/router/routes/Pages.js
@@ -130,6 +130,11 @@ const PagesRoutes = [
meta: {
navLink: '/account/view'
}
+ },
+ {
+ path: '/client',
+ exact: true,
+ component: lazy(() => import('../../views/apps/client/dashboard'))
}
]
diff --git a/src/utility/Utils.js b/src/utility/Utils.js
index ffc4e75..18bc5f7 100644
--- a/src/utility/Utils.js
+++ b/src/utility/Utils.js
@@ -1,3 +1,4 @@
+import { DefaultRoute } from '../router/routes'
// ** Checks if an object is empty (returns boolean)
export const isObjEmpty = obj => Object.keys(obj).length === 0
@@ -50,6 +51,12 @@ export const formatDateToMonthShort = (value, toTimeForCurrentDay = true) => {
*/
export const isUserLoggedIn = () => localStorage.getItem('userData')
export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
+export const getDefaultRoute = () => {
+ const userdata = JSON.parse(localStorage.getItem("userData"))
+ const userrole = userdata === null ? '' : userdata.role
+ const redirect = (userrole === "admin") ? DefaultRoute : ((userrole === "client") ? '/client' : '/home')
+ return redirect
+}
/**
** This function is used for demo purpose route navigation
@@ -61,7 +68,7 @@ export const getUserData = () => JSON.parse(localStorage.getItem('userData'))
*/
export const getHomeRouteForLoggedInUser = userRole => {
if (userRole === 'admin') return '/'
- if (userRole === 'client') return '/access-control'
+ if (userRole === 'client') return '/'
return '/login'
}
diff --git a/src/views/apps/client/dashboard/index.js b/src/views/apps/client/dashboard/index.js
new file mode 100644
index 0000000..dbc3451
--- /dev/null
+++ b/src/views/apps/client/dashboard/index.js
@@ -0,0 +1,12 @@
+import { Fragment } from "react"
+
+
+const clientDashboard = () => {
+ return (
+
+CLIENT DASHBOARD
+
+ )
+}
+
+export default clientDashboard
diff --git a/src/views/apps/todo/index.js b/src/views/apps/todo/index.js
index c686b4c..daff939 100644
--- a/src/views/apps/todo/index.js
+++ b/src/views/apps/todo/index.js
@@ -53,6 +53,7 @@ const TODO = () => {
)
}, [store.tasks.length, paramsURL.filter, paramsURL.tag, query, sort])
+
return (
{
-
Please sign-in to your account and start the adventure