mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-22 21:50:12 +00:00
feat: display erros messages on login errors
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import Routes from "./routes";
|
import Routes from "./routes";
|
||||||
import "dotenv/config";
|
import "react-toastify/dist/ReactToastify.css";
|
||||||
|
|
||||||
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
|
import { createMuiTheme, ThemeProvider } from "@material-ui/core/styles";
|
||||||
import { ptBR } from "@material-ui/core/locale";
|
import { ptBR } from "@material-ui/core/locale";
|
||||||
|
|||||||
@@ -339,8 +339,6 @@ const TicketsList = () => {
|
|||||||
document.getElementById("sound").play();
|
document.getElementById("sound").play();
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(process.env.NODE_ENV);
|
|
||||||
|
|
||||||
const resetUnreadMessages = ticketId => {
|
const resetUnreadMessages = ticketId => {
|
||||||
setTickets(prevState => {
|
setTickets(prevState => {
|
||||||
const ticketIndex = prevState.findIndex(
|
const ticketIndex = prevState.findIndex(
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
|
|
||||||
|
import { toast } from "react-toastify";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
|
||||||
const useAuth = () => {
|
const useAuth = () => {
|
||||||
@@ -33,7 +35,7 @@ const useAuth = () => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
setIsAuth(false);
|
setIsAuth(false);
|
||||||
alert("Erro de autenticação. Por favor, faça login novamente");
|
toast.error("Erro de autenticação. Por favor, faça login novamente");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
checkAuth();
|
checkAuth();
|
||||||
@@ -50,7 +52,7 @@ const useAuth = () => {
|
|||||||
setIsAuth(true);
|
setIsAuth(true);
|
||||||
history.push("/chat");
|
history.push("/chat");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert(err);
|
toast.error("Erro de autenticação. Verifique os dados de login");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import React from "react";
|
import React, { useContext } from "react";
|
||||||
import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
|
import { Route, Redirect } from "react-router-dom";
|
||||||
|
|
||||||
import Backdrop from "@material-ui/core/Backdrop";
|
import Backdrop from "@material-ui/core/Backdrop";
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
|
|
||||||
import { AuthContext, AuthProvider } from "../context/Auth/AuthContext";
|
import { AuthContext } from "../context/Auth/AuthContext";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
backdrop: {
|
backdrop: {
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import React, { useContext } from "react";
|
import React from "react";
|
||||||
import { BrowserRouter, Route, Switch, Redirect } from "react-router-dom";
|
import { BrowserRouter, Switch } from "react-router-dom";
|
||||||
|
import { ToastContainer } from "react-toastify";
|
||||||
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 MainDrawer from "../components/MainDrawer";
|
||||||
import Dashboard from "../pages/Dashboard/";
|
import Dashboard from "../pages/Dashboard/";
|
||||||
@@ -12,81 +9,24 @@ import Signup from "../pages/Signup/";
|
|||||||
import Login from "../pages/Login/";
|
import Login from "../pages/Login/";
|
||||||
import WhatsAuth from "../pages/WhatsAuth/WhatsAuth";
|
import WhatsAuth from "../pages/WhatsAuth/WhatsAuth";
|
||||||
import Contacts from "../pages/Contacts/";
|
import Contacts from "../pages/Contacts/";
|
||||||
import { AuthContext, AuthProvider } from "../context/Auth/AuthContext";
|
import { AuthProvider } from "../context/Auth/AuthContext";
|
||||||
|
import Route from "./Route";
|
||||||
const useStyles = makeStyles(theme => ({
|
|
||||||
backdrop: {
|
|
||||||
zIndex: theme.zIndex.drawer + 1,
|
|
||||||
color: "#fff",
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
const PrivateRoute = ({ component: Component, ...rest }) => {
|
|
||||||
const classes = useStyles();
|
|
||||||
const { isAuth, loading } = useContext(AuthContext);
|
|
||||||
|
|
||||||
if (loading)
|
|
||||||
return (
|
|
||||||
<Backdrop className={classes.backdrop} open={loading}>
|
|
||||||
<CircularProgress color="inherit" />
|
|
||||||
</Backdrop>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Route
|
|
||||||
{...rest}
|
|
||||||
render={props =>
|
|
||||||
isAuth ? (
|
|
||||||
<Component {...props} />
|
|
||||||
) : (
|
|
||||||
<Redirect
|
|
||||||
to={{ pathname: "/login", state: { from: props.location } }}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const PublicRoute = ({ component: Component, ...rest }) => {
|
|
||||||
const classes = useStyles();
|
|
||||||
const { isAuth, loading } = useContext(AuthContext);
|
|
||||||
|
|
||||||
if (loading)
|
|
||||||
return (
|
|
||||||
<Backdrop className={classes.backdrop} open={loading}>
|
|
||||||
<CircularProgress color="inherit" />
|
|
||||||
</Backdrop>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Route
|
|
||||||
{...rest}
|
|
||||||
render={props =>
|
|
||||||
!isAuth ? (
|
|
||||||
<Component {...props} />
|
|
||||||
) : (
|
|
||||||
<Redirect to={{ pathname: "/", state: { from: props.location } }} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Routes = () => {
|
const Routes = () => {
|
||||||
return (
|
return (
|
||||||
<BrowserRouter>
|
<BrowserRouter>
|
||||||
<AuthProvider>
|
<AuthProvider>
|
||||||
<Switch>
|
<Switch>
|
||||||
<PublicRoute exact path="/login" component={Login} />
|
<Route exact path="/login" component={Login} />
|
||||||
<PublicRoute exact path="/signup" component={Signup} />
|
<Route exact path="/signup" component={Signup} />
|
||||||
<MainDrawer>
|
<MainDrawer>
|
||||||
<PrivateRoute exact path="/" component={Dashboard} />
|
<Route exact path="/" component={Dashboard} isPrivate />
|
||||||
<PrivateRoute exact path="/chat/:ticketId?" component={Chat} />
|
<Route exact path="/chat/:ticketId?" component={Chat} isPrivate />
|
||||||
<PrivateRoute exact path="/whats-auth" component={WhatsAuth} />
|
<Route exact path="/whats-auth" component={WhatsAuth} isPrivate />
|
||||||
<PrivateRoute exact path="/contacts" component={Contacts} />
|
<Route exact path="/contacts" component={Contacts} isPrivate />
|
||||||
</MainDrawer>
|
</MainDrawer>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
<ToastContainer autoClose={3000} />
|
||||||
</AuthProvider>
|
</AuthProvider>
|
||||||
</BrowserRouter>
|
</BrowserRouter>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user