Skip to content

Commit

Permalink
CRUD apenas admin ou habilitado nas configurações
Browse files Browse the repository at this point in the history
  • Loading branch information
rtenorioh committed Oct 9, 2024
1 parent 68f6328 commit 87638c7
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 68 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { QueryInterface } from "sequelize";

module.exports = {
up: (queryInterface: QueryInterface) => {
return queryInterface.bulkInsert(
"Settings",
[
{
key: "quickAnswer",
value: "disabled",
createdAt: new Date(),
updatedAt: new Date()
}
],
{}
);
},

down: (queryInterface: QueryInterface) => {
return queryInterface.bulkDelete("Settings", {});
}
};
139 changes: 83 additions & 56 deletions frontend/src/pages/QuickAnswers/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import React, { useState, useEffect, useReducer } from "react";
import openSocket from "../../services/socket-io";
import { useHistory } from "react-router-dom";

import {
Button,
IconButton,
InputAdornment,
makeStyles,
Paper,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
InputAdornment,
TextField,
Tooltip
} from "@material-ui/core";
Expand All @@ -24,16 +20,20 @@ import {
Search
} from "@material-ui/icons";

import api from "../../services/api";
import { i18n } from "../../translate/i18n";
import React, { useContext, useEffect, useReducer, useState } from "react";
import { useHistory } from "react-router-dom";
import openSocket from "../../services/socket-io";

import ConfirmationModal from "../../components/ConfirmationModal";
import MainContainer from "../../components/MainContainer";
import MainHeader from "../../components/MainHeader";
import MainHeaderButtonsWrapper from "../../components/MainHeaderButtonsWrapper";
import Title from "../../components/Title";
import TableRowSkeleton from "../../components/TableRowSkeleton";
import QuickAnswersModal from "../../components/QuickAnswersModal";
import ConfirmationModal from "../../components/ConfirmationModal";
import TableRowSkeleton from "../../components/TableRowSkeleton";
import Title from "../../components/Title";
import { AuthContext } from "../../context/Auth/AuthContext";
import api from "../../services/api";
import { i18n } from "../../translate/i18n";

import { toast } from "react-toastify";
import toastError from "../../errors/toastError";
Expand Down Expand Up @@ -95,7 +95,6 @@ const useStyles = makeStyles((theme) => ({
const QuickAnswers = () => {
const classes = useStyles();
const history = useHistory();

const [loading, setLoading] = useState(false);
const [pageNumber, setPageNumber] = useState(1);
const [searchParam, setSearchParam] = useState("");
Expand All @@ -106,6 +105,9 @@ const QuickAnswers = () => {
const [deletingAllQuickAnswers, setDeletingAllQuickAnswers] = useState(null);
const [confirmModalOpen, setConfirmModalOpen] = useState(false);
const [hasMore, setHasMore] = useState(false);
const [settings, setSettings] = useState([]);
const { user } = useContext(AuthContext);
const isAdmin = user.profile;

useEffect(() => {
dispatch({ type: "RESET" });
Expand Down Expand Up @@ -153,6 +155,23 @@ const QuickAnswers = () => {
};
}, []);

useEffect(() => {
const fetchSettings = async () => {
try {
const { data } = await api.get("/settings");
setSettings(data);
} catch (err) {
toastError(err);
}
};
fetchSettings();
}, []);

const getSettingValue = key => {
const { value } = settings.find(s => s.key === key);
return value;
};

const handleSearch = (event) => {
setSearchParam(event.target.value.toLowerCase());
};
Expand Down Expand Up @@ -214,13 +233,13 @@ const QuickAnswers = () => {
<ConfirmationModal
title={
deletingQuickAnswers ? `${i18n.t("quickAnswers.confirmationModal.deleteTitle")} ${deletingQuickAnswers.shortcut}?`
: `${i18n.t("quickAnswers.confirmationModal.deleteAllTitle")}`
: `${i18n.t("quickAnswers.confirmationModal.deleteAllTitle")}`
}
open={confirmModalOpen}
onClose={setConfirmModalOpen}
onConfirm={() =>
onConfirm={() =>
deletingQuickAnswers ? handleDeleteQuickAnswers(deletingQuickAnswers.id)
: handleDeleteAllQuickAnswers(deletingAllQuickAnswers)
: handleDeleteAllQuickAnswers(deletingAllQuickAnswers)
}
>
{
Expand Down Expand Up @@ -250,27 +269,31 @@ const QuickAnswers = () => {
),
}}
/>
<Tooltip title={i18n.t("quickAnswers.buttons.add")}>
<Button
variant="contained"
color="primary"
onClick={handleOpenQuickAnswersModal}
>
<AddCircleOutline />
</Button>
</Tooltip>
<Tooltip title={i18n.t("quickAnswers.buttons.deleteAll")}>
<Button
variant="contained"
color="primary"
onClick={(e) => {
setConfirmModalOpen(true);
setDeletingAllQuickAnswers(quickAnswers);
}}
>
<DeleteForever />
</Button>
</Tooltip>
{((settings && settings.length > 0 && getSettingValue("quickAnswer") === "enabled") || (isAdmin === "admin")) && (
<Tooltip title={i18n.t("quickAnswers.buttons.add")}>
<Button
variant="contained"
color="primary"
onClick={handleOpenQuickAnswersModal}
>
<AddCircleOutline />
</Button>
</Tooltip>
)}
{((settings && settings.length > 0 && getSettingValue("quickAnswer") === "enabled") || (isAdmin === "admin")) && (
<Tooltip title={i18n.t("quickAnswers.buttons.deleteAll")}>
<Button
variant="contained"
color="primary"
onClick={(e) => {
setConfirmModalOpen(true);
setDeletingAllQuickAnswers(quickAnswers);
}}
>
<DeleteForever />
</Button>
</Tooltip>
)}
</MainHeaderButtonsWrapper>
</MainHeader>
<Paper
Expand All @@ -287,9 +310,11 @@ const QuickAnswers = () => {
<TableCell align="center">
{i18n.t("quickAnswers.table.message")}
</TableCell>
<TableCell align="center">
{i18n.t("quickAnswers.table.actions")}
</TableCell>
{((settings && settings.length > 0 && getSettingValue("quickAnswer") === "enabled") || (isAdmin === "admin")) && (
<TableCell align="center">
{i18n.t("quickAnswers.table.actions")}
</TableCell>
)}
</TableRow>
</TableHead>
<TableBody>
Expand All @@ -298,24 +323,26 @@ const QuickAnswers = () => {
<TableRow key={quickAnswer.id}>
<TableCell align="center">{quickAnswer.shortcut}</TableCell>
<TableCell align="center">{quickAnswer.message}</TableCell>
<TableCell align="center">
<IconButton
size="small"
onClick={() => handleEditQuickAnswers(quickAnswer)}
>
<Edit color="secondary" />
</IconButton>

<IconButton
size="small"
onClick={(e) => {
setConfirmModalOpen(true);
setDeletingQuickAnswers(quickAnswer);
}}
>
<DeleteOutline color="secondary" />
</IconButton>
</TableCell>
{((settings && settings.length > 0 && getSettingValue("quickAnswer") === "enabled") || (isAdmin === "admin")) && (
<TableCell align="center">
<IconButton
size="small"
onClick={() => handleEditQuickAnswers(quickAnswer)}
>
<Edit color="secondary" />
</IconButton>

<IconButton
size="small"
onClick={(e) => {
setConfirmModalOpen(true);
setDeletingQuickAnswers(quickAnswer);
}}
>
<DeleteOutline color="secondary" />
</IconButton>
</TableCell>
)}
</TableRow>
))}
{loading && <TableRowSkeleton columns={3} />}
Expand Down
31 changes: 22 additions & 9 deletions frontend/src/pages/Settings/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import React, { useState, useEffect } from "react";
import openSocket from "socket.io-client";
import React, { useEffect, useState } from "react";
import { useHistory } from "react-router-dom";
import openSocket from "socket.io-client";

import { makeStyles, withStyles } from "@material-ui/core/styles";
import Paper from "@material-ui/core/Paper";
import Typography from "@material-ui/core/Typography";
import Container from "@material-ui/core/Container";
import Paper from "@material-ui/core/Paper";
import Select from "@material-ui/core/Select";
import { makeStyles, withStyles } from "@material-ui/core/styles";
import Typography from "@material-ui/core/Typography";
import { toast } from "react-toastify";

import Tooltip from "@material-ui/core/Tooltip";

import api from "../../services/api";
import { i18n } from "../../translate/i18n.js";
import toastError from "../../errors/toastError";
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import toastError from "../../errors/toastError";
import api from "../../services/api";
import { i18n } from "../../translate/i18n.js";

const useStyles = makeStyles(theme => ({
root: {
Expand Down Expand Up @@ -243,10 +243,23 @@ const Settings = () => {
</Tooltip>
</Paper>


</Container>
<Container className={classes.container} maxWidth="xs">

<Typography variant="body2" gutterBottom></Typography>
<Paper className={classes.paper}>
<Tooltip title={i18n.t("settings.settings.quickAnswer.note")}>
<FormControlLabel
control={
<IOSSwitch
checked={settings && settings.length > 0 && getSettingValue("quickAnswer") === "enabled"}
onChange={handleChangeBooleanSetting} name="quickAnswer"
/>}
label={i18n.t("settings.settings.quickAnswer.name")}
/>
</Tooltip>
</Paper>

<Typography variant="body2" gutterBottom></Typography>
<Paper className={classes.paper}>
<Tooltip title={i18n.t("settings.settings.closeTicketApi.note")}>
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/translate/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ const messages = {
deleteMessage: "All agent data will be lost. Open tickets for this agent will be moved to hold.",
},
},
company:{
company: {
success: "Company data successfully saved.",
title: "Company Data",
info: "Information",
Expand Down Expand Up @@ -555,6 +555,14 @@ const messages = {
disabled: "Closed",
},
},
quickAnswer: {
name: "Quick Answers",
note: "If enabled, you can edit quick answers",
options: {
enabled: "Enabled",
disabled: "Disabled",
},
},
closeTicketApi: {
name: "Close Ticket sent API",
note: "Automatically closes ticket when submitted via API",
Expand Down Expand Up @@ -700,3 +708,4 @@ const messages = {
};

export { messages };

12 changes: 10 additions & 2 deletions frontend/src/translate/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ const messages = {
deleteMessage: "Se perderán todos los datos del asistente. Los tickets abiertos para este asistente se moverán a espera.",
},
},
company:{
company: {
success: "Los datos de la empresa se guardaron con éxito.",
title: "Datos de la empresa",
info: "Información",
Expand Down Expand Up @@ -555,6 +555,14 @@ const messages = {
disabled: "Cerrado",
},
},
quickAnswer: {
name: "Respuestas rápidas",
note: "Si está habilitado, puedes editar respuestas rápidas",
options: {
enabled: "Habilitado",
disabled: "Deshabilitado",
},
},
closeTicketApi: {
name: "Cerrar ticket enviado API",
note: "Cierra automáticamente el ticket cuando se envía a través de API",
Expand Down Expand Up @@ -698,4 +706,4 @@ const messages = {
},
};

export { messages };
export { messages };
8 changes: 8 additions & 0 deletions frontend/src/translate/languages/pt.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,14 @@ const messages = {
disabled: "Fechado",
},
},
quickAnswer: {
name: "Respostas Rápidas",
note: "Se habilitado, poderá editar as respostas rápidas",
options: {
enabled: "Ativado",
disabled: "Desativado",
},
},
closeTicketApi: {
name: "Encerrar Ticket enviado API",
note: "Fecha automaticamente o ticket quando enviado por API",
Expand Down

0 comments on commit 87638c7

Please sign in to comment.