mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-20 04:39:20 +00:00
improvement: moved toast error logic into single function
This commit is contained in:
@@ -20,6 +20,7 @@ import CircularProgress from "@material-ui/core/CircularProgress";
|
|||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -27,9 +28,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
// marginLeft: theme.spacing(1),
|
|
||||||
marginRight: theme.spacing(1),
|
marginRight: theme.spacing(1),
|
||||||
// width: "25ch",
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -40,7 +39,6 @@ const useStyles = makeStyles(theme => ({
|
|||||||
},
|
},
|
||||||
|
|
||||||
btnWrapper: {
|
btnWrapper: {
|
||||||
// margin: theme.spacing(1),
|
|
||||||
position: "relative",
|
position: "relative",
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -97,16 +95,7 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => {
|
|||||||
setContact(data);
|
setContact(data);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -136,16 +125,7 @@ const ContactModal = ({ open, onClose, contactId, initialValues, onSave }) => {
|
|||||||
}
|
}
|
||||||
toast.success(i18n.t("contactModal.success"));
|
toast.success(i18n.t("contactModal.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React, { useState, useEffect, useContext, useRef } from "react";
|
|||||||
import "emoji-mart/css/emoji-mart.css";
|
import "emoji-mart/css/emoji-mart.css";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { Picker } from "emoji-mart";
|
import { Picker } from "emoji-mart";
|
||||||
import { toast } from "react-toastify";
|
|
||||||
import MicRecorder from "mic-recorder-to-mp3";
|
import MicRecorder from "mic-recorder-to-mp3";
|
||||||
import clsx from "clsx";
|
import clsx from "clsx";
|
||||||
|
|
||||||
@@ -26,6 +25,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import RecordingTimer from "./RecordingTimer";
|
import RecordingTimer from "./RecordingTimer";
|
||||||
import { ReplyMessageContext } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
import { ReplyMessageContext } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const Mp3Recorder = new MicRecorder({ bitRate: 128 });
|
const Mp3Recorder = new MicRecorder({ bitRate: 128 });
|
||||||
|
|
||||||
@@ -239,16 +239,7 @@ const MessageInput = ({ ticketStatus }) => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
@@ -271,16 +262,7 @@ const MessageInput = ({ ticketStatus }) => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/messages/${ticketId}`, message);
|
await api.post(`/messages/${ticketId}`, message);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setInputMessage("");
|
setInputMessage("");
|
||||||
@@ -320,16 +302,7 @@ const MessageInput = ({ ticketStatus }) => {
|
|||||||
|
|
||||||
await api.post(`/messages/${ticketId}`, formData);
|
await api.post(`/messages/${ticketId}`, formData);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setRecording(false);
|
setRecording(false);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import React, { useState, useContext } from "react";
|
import React, { useState, useContext } from "react";
|
||||||
|
|
||||||
import { toast } from "react-toastify";
|
|
||||||
|
|
||||||
import MenuItem from "@material-ui/core/MenuItem";
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
@@ -9,6 +7,7 @@ import api from "../../services/api";
|
|||||||
import ConfirmationModal from "../ConfirmationModal";
|
import ConfirmationModal from "../ConfirmationModal";
|
||||||
import { Menu } from "@material-ui/core";
|
import { Menu } from "@material-ui/core";
|
||||||
import { ReplyMessageContext } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
import { ReplyMessageContext } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => {
|
const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => {
|
||||||
const { setReplyingMessage } = useContext(ReplyMessageContext);
|
const { setReplyingMessage } = useContext(ReplyMessageContext);
|
||||||
@@ -18,16 +17,7 @@ const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => {
|
|||||||
try {
|
try {
|
||||||
await api.delete(`/messages/${message.id}`);
|
await api.delete(`/messages/${message.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,9 +26,8 @@ import ModalImageCors from "../ModalImageCors";
|
|||||||
import MessageOptionsMenu from "../MessageOptionsMenu";
|
import MessageOptionsMenu from "../MessageOptionsMenu";
|
||||||
import whatsBackground from "../../assets/wa-background.png";
|
import whatsBackground from "../../assets/wa-background.png";
|
||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { toast } from "react-toastify";
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
messagesListWrapper: {
|
messagesListWrapper: {
|
||||||
@@ -343,16 +342,7 @@ const MessagesList = ({ ticketId, isGroup, setReplyingMessage }) => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchMessages();
|
fetchMessages();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { toast } from "react-toastify";
|
|
||||||
|
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@@ -18,6 +17,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import ButtonWithSpinner from "../ButtonWithSpinner";
|
import ButtonWithSpinner from "../ButtonWithSpinner";
|
||||||
import ContactModal from "../ContactModal";
|
import ContactModal from "../ContactModal";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const filter = createFilterOptions({
|
const filter = createFilterOptions({
|
||||||
trim: true,
|
trim: true,
|
||||||
@@ -50,16 +50,7 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -85,16 +76,7 @@ const NewTicketModal = ({ modalOpen, onClose }) => {
|
|||||||
});
|
});
|
||||||
history.push(`/tickets/${ticket.id}`);
|
history.push(`/tickets/${ticket.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
handleClose();
|
handleClose();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import QRCode from "qrcode.react";
|
import QRCode from "qrcode.react";
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
import { toast } from "react-toastify";
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
import { Dialog, DialogContent, Paper, Typography } from "@material-ui/core";
|
import { Dialog, DialogContent, Paper, Typography } from "@material-ui/core";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
@@ -18,16 +18,7 @@ const QrcodeModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
const { data } = await api.get(`/whatsapp/${whatsAppId}`);
|
const { data } = await api.get(`/whatsapp/${whatsAppId}`);
|
||||||
setQrCode(data.qrcode);
|
setQrCode(data.qrcode);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import TicketInfo from "../TicketInfo";
|
|||||||
import TicketActionButtons from "../TicketActionButtons";
|
import TicketActionButtons from "../TicketActionButtons";
|
||||||
import MessagesList from "../MessagesList";
|
import MessagesList from "../MessagesList";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
|
||||||
import { ReplyMessageProvider } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
import { ReplyMessageProvider } from "../../context/ReplyingMessage/ReplyingMessageContext";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const drawerWidth = 320;
|
const drawerWidth = 320;
|
||||||
|
|
||||||
@@ -76,19 +76,7 @@ const Ticket = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
if (err.response.status === 404) {
|
|
||||||
history.push("/tickets");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchTicket();
|
fetchTicket();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { toast } from "react-toastify";
|
|
||||||
|
|
||||||
import { makeStyles } from "@material-ui/core/styles";
|
import { makeStyles } from "@material-ui/core/styles";
|
||||||
import { IconButton } from "@material-ui/core";
|
import { IconButton } from "@material-ui/core";
|
||||||
@@ -10,6 +9,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import TicketOptionsMenu from "../TicketOptionsMenu";
|
import TicketOptionsMenu from "../TicketOptionsMenu";
|
||||||
import ButtonWithSpinner from "../ButtonWithSpinner";
|
import ButtonWithSpinner from "../ButtonWithSpinner";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
actionButtons: {
|
actionButtons: {
|
||||||
@@ -55,16 +55,7 @@ const TicketActionButtons = ({ ticket }) => {
|
|||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
import { toast } from "react-toastify";
|
|
||||||
|
|
||||||
import MenuItem from "@material-ui/core/MenuItem";
|
import MenuItem from "@material-ui/core/MenuItem";
|
||||||
import Menu from "@material-ui/core/Menu";
|
import Menu from "@material-ui/core/Menu";
|
||||||
|
|
||||||
@@ -9,6 +7,7 @@ import { i18n } from "../../translate/i18n";
|
|||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import ConfirmationModal from "../ConfirmationModal";
|
import ConfirmationModal from "../ConfirmationModal";
|
||||||
import TransferTicketModal from "../TransferTicketModal";
|
import TransferTicketModal from "../TransferTicketModal";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
||||||
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
const [confirmationOpen, setConfirmationOpen] = useState(false);
|
||||||
@@ -25,16 +24,7 @@ const TicketOptionsMenu = ({ ticket, menuOpen, handleClose, anchorEl }) => {
|
|||||||
try {
|
try {
|
||||||
await api.delete(`/tickets/${ticket.id}`);
|
await api.delete(`/tickets/${ticket.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import { useHistory } from "react-router-dom";
|
import { useHistory } from "react-router-dom";
|
||||||
import { toast } from "react-toastify";
|
|
||||||
|
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@@ -17,6 +16,7 @@ import CircularProgress from "@material-ui/core/CircularProgress";
|
|||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import ButtonWithSpinner from "../ButtonWithSpinner";
|
import ButtonWithSpinner from "../ButtonWithSpinner";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const filterOptions = createFilterOptions({
|
const filterOptions = createFilterOptions({
|
||||||
trim: true,
|
trim: true,
|
||||||
@@ -45,16 +45,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,16 +73,7 @@ const TransferTicketModal = ({ modalOpen, onClose, ticketid }) => {
|
|||||||
history.push(`/tickets`);
|
history.push(`/tickets`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import FormControl from "@material-ui/core/FormControl";
|
|||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -28,14 +29,11 @@ const useStyles = makeStyles(theme => ({
|
|||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
// marginLeft: theme.spacing(1),
|
|
||||||
marginRight: theme.spacing(1),
|
marginRight: theme.spacing(1),
|
||||||
// width: "25ch",
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
},
|
},
|
||||||
|
|
||||||
btnWrapper: {
|
btnWrapper: {
|
||||||
// margin: theme.spacing(1),
|
|
||||||
position: "relative",
|
position: "relative",
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -83,16 +81,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
return { ...prevState, ...data };
|
return { ...prevState, ...data };
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -113,16 +102,7 @@ const UserModal = ({ open, onClose, userId }) => {
|
|||||||
}
|
}
|
||||||
toast.success(i18n.t("userModal.success"));
|
toast.success(i18n.t("userModal.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ import {
|
|||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
} from "@material-ui/core";
|
} from "@material-ui/core";
|
||||||
|
|
||||||
// import { i18n } from "../../translate/i18n";
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
form: {
|
form: {
|
||||||
@@ -73,16 +73,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
const { data } = await api.get(`whatsapp/${whatsAppId}`);
|
const { data } = await api.get(`whatsapp/${whatsAppId}`);
|
||||||
setWhatsApp(data);
|
setWhatsApp(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
@@ -100,16 +91,7 @@ const WhatsAppModal = ({ open, onClose, whatsAppId }) => {
|
|||||||
}
|
}
|
||||||
toast.success(i18n.t("whatsappModal.success"));
|
toast.success(i18n.t("whatsappModal.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
handleClose();
|
handleClose();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { toast } from "react-toastify";
|
|||||||
|
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useAuth = () => {
|
const useAuth = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
@@ -78,16 +79,7 @@ const useAuth = () => {
|
|||||||
toast.success(i18n.t("auth.toasts.success"));
|
toast.success(i18n.t("auth.toasts.success"));
|
||||||
history.push("/tickets");
|
history.push("/tickets");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
import { useState, useEffect, useReducer } from "react";
|
import { useState, useEffect, useReducer } from "react";
|
||||||
import { toast } from "react-toastify";
|
|
||||||
import openSocket from "socket.io-client";
|
import openSocket from "socket.io-client";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
if (action.type === "LOAD_WHATSAPPS") {
|
if (action.type === "LOAD_WHATSAPPS") {
|
||||||
@@ -67,16 +66,7 @@ const useWhatsApps = () => {
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
|
|||||||
21
frontend/src/errors/toastError.js
Normal file
21
frontend/src/errors/toastError.js
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import { toast } from "react-toastify";
|
||||||
|
import { i18n } from "../translate/i18n";
|
||||||
|
|
||||||
|
const toastError = err => {
|
||||||
|
const errorMsg = err.response?.data?.error;
|
||||||
|
if (errorMsg) {
|
||||||
|
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
||||||
|
toast.error(i18n.t(`backendErrors.${errorMsg}`), {
|
||||||
|
toastId: errorMsg,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
toast.error(errorMsg, {
|
||||||
|
toastId: errorMsg,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
toast.error("An error occurred!");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default toastError;
|
||||||
@@ -1,8 +1,7 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { toast } from "react-toastify";
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n";
|
|
||||||
|
|
||||||
const useTickets = ({
|
const useTickets = ({
|
||||||
searchParam,
|
searchParam,
|
||||||
@@ -36,16 +35,7 @@ const useTickets = ({
|
|||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchTickets();
|
fetchTickets();
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ import ConfirmationModal from "../../components/ConfirmationModal";
|
|||||||
import QrcodeModal from "../../components/QrcodeModal";
|
import QrcodeModal from "../../components/QrcodeModal";
|
||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
import { WhatsAppsContext } from "../../context/WhatsApp/WhatsAppsContext";
|
import { WhatsAppsContext } from "../../context/WhatsApp/WhatsAppsContext";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
mainPaper: {
|
mainPaper: {
|
||||||
@@ -114,16 +115,7 @@ const Connections = () => {
|
|||||||
try {
|
try {
|
||||||
await api.post(`/whatsappsession/${whatsAppId}`);
|
await api.post(`/whatsappsession/${whatsAppId}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -131,16 +123,7 @@ const Connections = () => {
|
|||||||
try {
|
try {
|
||||||
await api.put(`/whatsappsession/${whatsAppId}`);
|
await api.put(`/whatsappsession/${whatsAppId}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -195,16 +178,7 @@ const Connections = () => {
|
|||||||
try {
|
try {
|
||||||
await api.delete(`/whatsappsession/${confirmModalInfo.whatsAppId}`);
|
await api.delete(`/whatsappsession/${confirmModalInfo.whatsAppId}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,16 +187,7 @@ const Connections = () => {
|
|||||||
await api.delete(`/whatsapp/${confirmModalInfo.whatsAppId}`);
|
await api.delete(`/whatsapp/${confirmModalInfo.whatsAppId}`);
|
||||||
toast.success(i18n.t("connections.toasts.deleted"));
|
toast.success(i18n.t("connections.toasts.deleted"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import MainHeader from "../../components/MainHeader";
|
|||||||
import Title from "../../components/Title";
|
import Title from "../../components/Title";
|
||||||
import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper";
|
import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper";
|
||||||
import MainContainer from "../../components/MainContainer";
|
import MainContainer from "../../components/MainContainer";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
if (action.type === "LOAD_CONTACTS") {
|
if (action.type === "LOAD_CONTACTS") {
|
||||||
@@ -117,16 +118,7 @@ const Contacts = () => {
|
|||||||
setHasMore(data.hasMore);
|
setHasMore(data.hasMore);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchContacts();
|
fetchContacts();
|
||||||
@@ -176,16 +168,7 @@ const Contacts = () => {
|
|||||||
});
|
});
|
||||||
history.push(`/tickets/${ticket.id}`);
|
history.push(`/tickets/${ticket.id}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
};
|
};
|
||||||
@@ -200,16 +183,7 @@ const Contacts = () => {
|
|||||||
await api.delete(`/contacts/${contactId}`);
|
await api.delete(`/contacts/${contactId}`);
|
||||||
toast.success(i18n.t("contacts.toasts.deleted"));
|
toast.success(i18n.t("contacts.toasts.deleted"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setDeletingContact(null);
|
setDeletingContact(null);
|
||||||
setSearchParam("");
|
setSearchParam("");
|
||||||
@@ -221,16 +195,7 @@ const Contacts = () => {
|
|||||||
await api.post("/contacts/import");
|
await api.post("/contacts/import");
|
||||||
history.go(0);
|
history.go(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { toast } from "react-toastify";
|
|||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
import { i18n } from "../../translate/i18n.js";
|
import { i18n } from "../../translate/i18n.js";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const useStyles = makeStyles(theme => ({
|
const useStyles = makeStyles(theme => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -43,16 +44,7 @@ const Settings = () => {
|
|||||||
const { data } = await api.get("/settings");
|
const { data } = await api.get("/settings");
|
||||||
setSettings(data);
|
setSettings(data);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchSession();
|
fetchSession();
|
||||||
@@ -62,7 +54,6 @@ const Settings = () => {
|
|||||||
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
const socket = openSocket(process.env.REACT_APP_BACKEND_URL);
|
||||||
socket.on("settings", data => {
|
socket.on("settings", data => {
|
||||||
if (data.action === "update") {
|
if (data.action === "update") {
|
||||||
// dispatch({ type: "UPDATE_USERS", payload: data.user });
|
|
||||||
setSettings(prevState => {
|
setSettings(prevState => {
|
||||||
const aux = [...prevState];
|
const aux = [...prevState];
|
||||||
const settingIndex = aux.findIndex(s => s.key === data.setting.key);
|
const settingIndex = aux.findIndex(s => s.key === data.setting.key);
|
||||||
@@ -87,16 +78,7 @@ const Settings = () => {
|
|||||||
});
|
});
|
||||||
toast.success(i18n.t("settings.success"));
|
toast.success(i18n.t("settings.success"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import Container from "@material-ui/core/Container";
|
|||||||
import { i18n } from "../../translate/i18n";
|
import { i18n } from "../../translate/i18n";
|
||||||
|
|
||||||
import api from "../../services/api";
|
import api from "../../services/api";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
// const Copyright = () => {
|
// const Copyright = () => {
|
||||||
// return (
|
// return (
|
||||||
@@ -47,7 +48,7 @@ const useStyles = makeStyles(theme => ({
|
|||||||
backgroundColor: theme.palette.secondary.main,
|
backgroundColor: theme.palette.secondary.main,
|
||||||
},
|
},
|
||||||
form: {
|
form: {
|
||||||
width: "100%", // Fix IE 11 issue.
|
width: "100%",
|
||||||
marginTop: theme.spacing(3),
|
marginTop: theme.spacing(3),
|
||||||
},
|
},
|
||||||
submit: {
|
submit: {
|
||||||
@@ -78,16 +79,7 @@ const SignUp = () => {
|
|||||||
toast.success(i18n.t("signup.toasts.success"));
|
toast.success(i18n.t("signup.toasts.success"));
|
||||||
history.push("/login");
|
history.push("/login");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import TableRowSkeleton from "../../components/TableRowSkeleton";
|
|||||||
import UserModal from "../../components/UserModal";
|
import UserModal from "../../components/UserModal";
|
||||||
import ConfirmationModal from "../../components/ConfirmationModal";
|
import ConfirmationModal from "../../components/ConfirmationModal";
|
||||||
import { Avatar } from "@material-ui/core";
|
import { Avatar } from "@material-ui/core";
|
||||||
|
import toastError from "../../errors/toastError";
|
||||||
|
|
||||||
const reducer = (state, action) => {
|
const reducer = (state, action) => {
|
||||||
if (action.type === "LOAD_USERS") {
|
if (action.type === "LOAD_USERS") {
|
||||||
@@ -113,16 +114,7 @@ const Users = () => {
|
|||||||
setHasMore(data.hasMore);
|
setHasMore(data.hasMore);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchUsers();
|
fetchUsers();
|
||||||
@@ -171,16 +163,7 @@ const Users = () => {
|
|||||||
await api.delete(`/users/${userId}`);
|
await api.delete(`/users/${userId}`);
|
||||||
toast.success(i18n.t("users.toasts.deleted"));
|
toast.success(i18n.t("users.toasts.deleted"));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
const errorMsg = err.response?.data?.error;
|
toastError(err);
|
||||||
if (errorMsg) {
|
|
||||||
if (i18n.exists(`backendErrors.${errorMsg}`)) {
|
|
||||||
toast.error(i18n.t(`backendErrors.${errorMsg}`));
|
|
||||||
} else {
|
|
||||||
toast.error(err.response.data.error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
toast.error("Unknown error");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setDeletingUser(null);
|
setDeletingUser(null);
|
||||||
setSearchParam("");
|
setSearchParam("");
|
||||||
|
|||||||
Reference in New Issue
Block a user