From 8988233da897e8447a1dbdb700836fb8576e5e6b Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Wed, 11 Dec 2019 18:54:05 +0530 Subject: :tada: Initial Commit --- src/core/app.routes.js | 15 +++++++++++++++ src/core/custom.router.js | 27 +++++++++++++++++++++++++++ src/core/routes.js | 35 +++++++++++++++++++++++++++++++++++ src/core/store.js | 31 +++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 src/core/app.routes.js create mode 100644 src/core/custom.router.js create mode 100644 src/core/routes.js create mode 100644 src/core/store.js (limited to 'src/core') diff --git a/src/core/app.routes.js b/src/core/app.routes.js new file mode 100644 index 0000000..5d06e63 --- /dev/null +++ b/src/core/app.routes.js @@ -0,0 +1,15 @@ +import AdminContainer from "../modules/admin/admin.container"; +import SuperAdminContainer from "../modules/superadmin/superadmin.container"; + +export const AppRoutes = [ + { + path: '/admin', + component: AdminContainer, + permission: ['admin','superadmin'] + }, + { + path: '/superadmin', + component: SuperAdminContainer, + permission: ['admin', 'superadmin', 'user'] + } +]; diff --git a/src/core/custom.router.js b/src/core/custom.router.js new file mode 100644 index 0000000..b3f08ec --- /dev/null +++ b/src/core/custom.router.js @@ -0,0 +1,27 @@ +import React from "react"; +import { Route, Redirect } from "react-router-dom"; +import Storage from "../services/storage.service"; + +export const CustomRouter = ({ xComponent: Component, ...xProps }) => { + return ( + { + console.log(props.permissions) + let token = Storage.get("token"); + let pathName = props.match.path; + if (!token && pathName !== "/login") { + return ; + } else if (pathName === "/login" && token) { + + return ; + }else if (pathName === "/" && token) { + + return ; + } + debugger + return ; + }} + /> + ); + }; \ No newline at end of file diff --git a/src/core/routes.js b/src/core/routes.js new file mode 100644 index 0000000..764e793 --- /dev/null +++ b/src/core/routes.js @@ -0,0 +1,35 @@ +import React, { Suspense } from "react"; +import { Provider } from "react-redux"; +import { ConnectedRouter } from "connected-react-router"; +import { Switch, Redirect, Route } from "react-router-dom"; +import { CustomRouter } from "./custom.router"; +import LoginContainer from "../modules/login/login.container"; +import DashBoardContainer from "../modules/dashboard/dashboard.container"; +import { AppRoutes } from "./app.routes"; + +const Routes = ({ store, history }) => { + return ( + + + Loading ...} + > + + + + {AppRoutes.map(_routes => + )} + + + + + + ); +}; + +export default Routes; \ No newline at end of file diff --git a/src/core/store.js b/src/core/store.js new file mode 100644 index 0000000..5e55424 --- /dev/null +++ b/src/core/store.js @@ -0,0 +1,31 @@ +import { createStore, applyMiddleware } from "redux"; +import { routerMiddleware } from "connected-react-router"; +import createSagaMiddleware from "redux-saga"; +import { createBrowserHistory } from "history"; +import { composeWithDevTools } from "redux-devtools-extension/developmentOnly"; + +import createRootReducer from "../reducers/root.reducer"; + +export const history = createBrowserHistory({ + hashType: "slash" +}); + +const RouterMiddleware = routerMiddleware(history); +const SagaMiddleware = createSagaMiddleware(); + +const getMiddleware = () => { + // DEVELPOPMENT + return composeWithDevTools(applyMiddleware(SagaMiddleware, RouterMiddleware)); + // PRODUCTION + // return compose(applyMiddleware(SagaMiddleware, RouterMiddleware)); +}; + +export function configureStore(initialState) { + const store = createStore( + createRootReducer(history), + initialState, + getMiddleware() + ); + store.runSaga = SagaMiddleware.run; + return store; +} -- cgit v1.2.3