[ ADD ] react configuration

This commit is contained in:
Kuroi488
2020-11-16 17:14:34 +01:00
parent 89c9cfe099
commit 5078a1a96e
71 changed files with 16891 additions and 0 deletions

10
react/src/utils/Auth.js Normal file
View File

@ -0,0 +1,10 @@
// Service to check authentication for user and to signOut
const Auth = {
signOut() {
localStorage.removeItem("token");
},
isAuth() {
return localStorage.getItem("token");
}
};
export default Auth;

View File

@ -0,0 +1 @@
export const BASE_URL = 'BASE_URL';

View File

@ -0,0 +1,5 @@
import React from "react";
export const Home = React.lazy(() => import('../containers/Home/Home'));
export const Login = React.lazy(() => import('../containers/Login/Login'));
export const NotFound = React.lazy(() => import('../components/NotFound/NotFound'));

View File

@ -0,0 +1,18 @@
import React from "react";
import { Route, Redirect } from "react-router-dom";
import Auth from "../utils/Auth";
const PrivateRoute = ({ component: Component, ...rest }) => {
return (
// Show the component only when the user is logged in
// Otherwise, redirect the user to /signin page
<Route
{...rest}
render={props =>
Auth.isAuth() ? <Component {...props} /> : <Redirect to="/login" />
}
/>
);
};
export default PrivateRoute;

18
react/src/utils/Shared.js Normal file
View File

@ -0,0 +1,18 @@
import store from "../store";
import { showSnackbarAction } from "../store/Snackbar/SnackbarAction";
import messages from "../assets/Local/messages";
// To show error message that returned from backend
export function dispatchSnackbarError(data) {
if (data) {
const errorMsg = data.error.message;
store.dispatch(showSnackbarAction(errorMsg, "error"));
}
}
// To show success message after any success request if needed and rendered from locale files
export function dispatchSnackbarSuccess(message) {
const lang = store.getState().lang;
store.dispatch(
showSnackbarAction(messages[lang].snackbar[message], "success")
);
}