aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/app.routes.js15
-rw-r--r--src/core/custom.router.js27
-rw-r--r--src/core/routes.js35
-rw-r--r--src/core/store.js31
4 files changed, 108 insertions, 0 deletions
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 (
+ <Route
+ {...xProps}
+ render={props => {
+ console.log(props.permissions)
+ let token = Storage.get("token");
+ let pathName = props.match.path;
+ if (!token && pathName !== "/login") {
+ return <Redirect to="/login" />;
+ } else if (pathName === "/login" && token) {
+
+ return <Redirect to="/dashboard" />;
+ }else if (pathName === "/" && token) {
+
+ return <Redirect to="/dashboard" />;
+ }
+ debugger
+ return <Component {...props} />;
+ }}
+ />
+ );
+ }; \ 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 (
+ <Provider store={store}>
+ <ConnectedRouter history={history}>
+ <Suspense
+ fallback={<div style={{ display: "none" }}> Loading ...</div>}
+ >
+ <Switch>
+ <CustomRouter path="/login" xComponent={LoginContainer} />
+ <CustomRouter path="/dashboard" xComponent={DashBoardContainer} />
+ {AppRoutes.map(_routes =>
+ <CustomRouter
+ key={_routes.path}
+ path={_routes.path}
+ xComponent={_routes.component}
+ permissions={_routes.permission}
+ />)}
+ <Redirect from="*" to="/login" push />
+ </Switch>
+ </Suspense>
+ </ConnectedRouter>
+ </Provider>
+ );
+};
+
+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;
+}