mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-19 04:09:26 +00:00
improvement: start moving routes to custom route
This commit is contained in:
@@ -158,6 +158,7 @@ const MainDrawer = ({ appTitle, children }) => {
|
||||
<AppBar
|
||||
position="absolute"
|
||||
className={clsx(classes.appBar, open && classes.appBarShift)}
|
||||
color={process.env.NODE_ENV === "development" ? "secondary" : "primary"}
|
||||
>
|
||||
<Toolbar variant="dense" className={classes.toolbar}>
|
||||
<IconButton
|
||||
|
||||
@@ -339,6 +339,8 @@ const TicketsList = () => {
|
||||
document.getElementById("sound").play();
|
||||
};
|
||||
|
||||
console.log(process.env.NODE_ENV);
|
||||
|
||||
const resetUnreadMessages = ticketId => {
|
||||
setTickets(prevState => {
|
||||
const ticketIndex = prevState.findIndex(
|
||||
|
||||
45
frontend/src/routes/Route.js
Normal file
45
frontend/src/routes/Route.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import React from "react";
|
||||
import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
|
||||
|
||||
import Backdrop from "@material-ui/core/Backdrop";
|
||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
|
||||
import { AuthContext, AuthProvider } from "../context/Auth/AuthContext";
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
backdrop: {
|
||||
zIndex: theme.zIndex.drawer + 1,
|
||||
color: "#fff",
|
||||
},
|
||||
}));
|
||||
|
||||
const RouteWrapper = ({ component: Component, isPrivate = false, ...rest }) => {
|
||||
const classes = useStyles();
|
||||
const { isAuth, loading } = useContext(AuthContext);
|
||||
|
||||
if (loading)
|
||||
return (
|
||||
<Backdrop className={classes.backdrop} open={loading}>
|
||||
<CircularProgress color="inherit" />
|
||||
</Backdrop>
|
||||
);
|
||||
|
||||
if (!isAuth && isPrivate) {
|
||||
return (
|
||||
<Redirect to={{ pathname: "/login", state: { from: rest.location } }} />
|
||||
);
|
||||
}
|
||||
|
||||
if (isAuth && !isPrivate) {
|
||||
return (
|
||||
<Redirect
|
||||
to={{ pathname: "/dashboard", state: { from: rest.location } }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return <Route {...rest} component={Component} />;
|
||||
};
|
||||
|
||||
export default RouteWrapper;
|
||||
@@ -5,14 +5,14 @@ import Backdrop from "@material-ui/core/Backdrop";
|
||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||
import { makeStyles } from "@material-ui/core/styles";
|
||||
|
||||
import MainDrawer from "./components/MainDrawer";
|
||||
import Dashboard from "./pages/Dashboard/";
|
||||
import Chat from "./pages/Chat/";
|
||||
import Signup from "./pages/Signup/";
|
||||
import Login from "./pages/Login/";
|
||||
import WhatsAuth from "./pages/WhatsAuth/WhatsAuth";
|
||||
import Contacts from "./pages/Contacts/";
|
||||
import { AuthContext, AuthProvider } from "./context/Auth/AuthContext";
|
||||
import MainDrawer from "../components/MainDrawer";
|
||||
import Dashboard from "../pages/Dashboard/";
|
||||
import Chat from "../pages/Chat/";
|
||||
import Signup from "../pages/Signup/";
|
||||
import Login from "../pages/Login/";
|
||||
import WhatsAuth from "../pages/WhatsAuth/WhatsAuth";
|
||||
import Contacts from "../pages/Contacts/";
|
||||
import { AuthContext, AuthProvider } from "../context/Auth/AuthContext";
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
backdrop: {
|
||||
Reference in New Issue
Block a user