From f47da2cee41654af6b54c4fa28857cec2a2cf9d0 Mon Sep 17 00:00:00 2001 From: Robson Tenorio Date: Mon, 21 Mar 2022 00:20:43 -0300 Subject: [PATCH] =?UTF-8?q?Add=20Configura=C3=A7=C3=A3o=20para=20o=20tempo?= =?UTF-8?q?=20de=20cria=C3=A7=C3=A3o=20de=20novos=20Tickets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20200904070004-create-default-settings.ts | 6 + .../FindOrCreateTicketService.ts | 12 +- frontend/src/pages/Settings/index.js | 278 +++++++++--------- frontend/src/translate/languages/en.js | 15 + frontend/src/translate/languages/es.js | 15 + frontend/src/translate/languages/pt.js | 15 + 6 files changed, 191 insertions(+), 150 deletions(-) diff --git a/backend/src/database/seeds/20200904070004-create-default-settings.ts b/backend/src/database/seeds/20200904070004-create-default-settings.ts index bd494b02..95f81393 100644 --- a/backend/src/database/seeds/20200904070004-create-default-settings.ts +++ b/backend/src/database/seeds/20200904070004-create-default-settings.ts @@ -22,6 +22,12 @@ module.exports = { value: "disabled", createdAt: new Date(), updatedAt: new Date() + }, + { + key: "timeCreateNewTicket", + value: "10", + createdAt: new Date(), + updatedAt: new Date() } ], {} diff --git a/backend/src/services/TicketServices/FindOrCreateTicketService.ts b/backend/src/services/TicketServices/FindOrCreateTicketService.ts index bf4c2b00..6aed476b 100644 --- a/backend/src/services/TicketServices/FindOrCreateTicketService.ts +++ b/backend/src/services/TicketServices/FindOrCreateTicketService.ts @@ -1,8 +1,10 @@ -import { subHours } from "date-fns"; +// import { subHours } from "date-fns"; +const add = require('date-fns/add') import { Op } from "sequelize"; import Contact from "../../models/Contact"; import Ticket from "../../models/Ticket"; import ShowTicketService from "./ShowTicketService"; +import ListSettingsServiceOne from "../SettingServices/ListSettingsServiceOne"; const FindOrCreateTicketService = async ( contact: Contact, @@ -41,10 +43,14 @@ const FindOrCreateTicketService = async ( } if (!ticket && !groupContact) { + const listSettingsService = await ListSettingsServiceOne({key: "timeCreateNewTicket"}); + var timeCreateNewTicket = listSettingsService?.value; + + ticket = await Ticket.findOne({ where: { updatedAt: { - [Op.between]: [+subHours(new Date(), 2), +new Date()] + [Op.between]: [+add(new Date(), {seconds: timeCreateNewTicket}), +new Date()] }, contactId: contact.id }, @@ -75,4 +81,4 @@ const FindOrCreateTicketService = async ( return ticket; }; -export default FindOrCreateTicketService; +export default FindOrCreateTicketService; \ No newline at end of file diff --git a/frontend/src/pages/Settings/index.js b/frontend/src/pages/Settings/index.js index 1a7303f5..db90dc72 100644 --- a/frontend/src/pages/Settings/index.js +++ b/frontend/src/pages/Settings/index.js @@ -1,20 +1,19 @@ import React, { useState, useEffect } from "react"; -import openSocket from "../../services/socket-io"; +import openSocket from "socket.io-client"; -import { makeStyles, withStyles } from "@material-ui/core/styles"; +import { makeStyles } 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 Select from "@material-ui/core/Select"; import TextField from "@material-ui/core/TextField"; 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 Switch from '@material-ui/core/Switch'; -import Grid from '@material-ui/core/Grid'; - - const useStyles = makeStyles(theme => ({ root: { @@ -23,17 +22,12 @@ const useStyles = makeStyles(theme => ({ padding: theme.spacing(8, 8, 3), }, - typography: { - subtitle6: { - fontSize: 12, - } - }, - paper: { padding: theme.spacing(2), display: "flex", alignItems: "center", marginBottom: 12, + }, settingOption: { @@ -44,61 +38,6 @@ const useStyles = makeStyles(theme => ({ }, })); -const IOSSwitch = withStyles((theme) => ({ - root: { - width: 40, - height: 24, - padding: 0, - margin: theme.spacing(0), - marginLeft: 7, - marginBottom: 1, - - }, - switchBase: { - padding: 1, - '&$checked': { - transform: 'translateX(16px)', - color: theme.palette.common.white, - '& + $track': { - backgroundColor: '#52d869', - opacity: 1, - border: 'none', - }, - }, - '&$focusVisible $thumb': { - color: '#52d869', - border: '6px solid #fff', - }, - }, - thumb: { - width: 22, - height: 22, - }, - track: { - borderRadius: 26 / 2, - border: `1px solid ${theme.palette.grey[400]}`, - backgroundColor: theme.palette.grey[50], - opacity: 1, - transition: theme.transitions.create(['background-color', 'border']), - }, - checked: {}, - focusVisible: {}, -}))(({ classes, ...props }) => { - return ( - - ); -}); const Settings = () => { const classes = useStyles(); @@ -136,21 +75,8 @@ const Settings = () => { }; }, []); - const handleChangeBooleanSetting = async e => { - const selectedValue = e.target.checked ? "enabled" : "disabled"; - const settingKey = e.target.name; - - try { - await api.put(`/settings/${settingKey}`, { - value: selectedValue, - }); - toast.success(i18n.t("settings.success")); - } catch (err) { - toastError(err); - } - }; const handleChangeSetting = async e => { - const selectedValue = e.target.checked ? "enabled" : "disabled"; + const selectedValue = e.target.value; const settingKey = e.target.name; try { @@ -174,73 +100,131 @@ const Settings = () => { {i18n.t("settings.title")} - - - - - {i18n.t("settings.settings.userCreation.name")} - - - - - - 0 && getSettingValue("userCreation") === "enabled"} - onChange={handleChangeBooleanSetting} - > - - - - - - - - - - {i18n.t("settings.settings.CheckMsgIsGroup.name")} - - - - - - 0 && getSettingValue("CheckMsgIsGroup") === "enabled"} - onChange={handleChangeBooleanSetting} - > - - - - - - - - - - {i18n.t("settings.settings.call.name")} - - - - - - 0 && getSettingValue("call") === "enabled"} - onChange={handleChangeBooleanSetting} - > - - - - - + + + {i18n.t("settings.settings.userCreation.name")} + + + + + + + + + {i18n.t("settings.settings.timeCreateNewTicket.name")} + + + + + + + + + {i18n.t("settings.settings.call.name")} + + + + + + + {i18n.t("settings.settings.CheckMsgIsGroup.name")} + + + diff --git a/frontend/src/translate/languages/en.js b/frontend/src/translate/languages/en.js index 9341b165..0400420b 100644 --- a/frontend/src/translate/languages/en.js +++ b/frontend/src/translate/languages/en.js @@ -372,6 +372,21 @@ const messages = { }, }, }, + timeCreateNewTicket: { + name: "Create new ticket after", + note: "Select the time it will take to open a new ticket if the customer contacts you again", + options: { + "10": "10 seconds", + "30": "30 seconds", + "60": "1 minute", + "300": "5 minutes", + "1800" : "30 minutes", + "3600" : "1 hour", + "7200" : "2 hours", + "21600" : "6 hours", + "43200" : "12 hours", + }, + }, CheckMsgIsGroup: { name: "Ignore Groups Msgs", options: { diff --git a/frontend/src/translate/languages/es.js b/frontend/src/translate/languages/es.js index 3a8c12f9..d0fd81b2 100644 --- a/frontend/src/translate/languages/es.js +++ b/frontend/src/translate/languages/es.js @@ -384,6 +384,21 @@ const messages = { disabled: "Deshabilitado", }, }, + timeCreateNewTicket: { + name: "Crear nuevo ticket después", + note: "Selecciona el tiempo que tardará en abrir un nuevo ticket si el cliente te vuelve a contactar", + options: { + "10": "10 Segundos", + "30": "30 Segundos", + "60": "1 minuto", + "300": "5 minutos", + "1800" : "30 minutos", + "3600" : "1 hora", + "7200" : "2 horas", + "21600" : "6 horas", + "43200" : "12 horas", + }, + }, messagesList: { header: { assignedTo: "Asignado a:", diff --git a/frontend/src/translate/languages/pt.js b/frontend/src/translate/languages/pt.js index 5c044607..56edde17 100644 --- a/frontend/src/translate/languages/pt.js +++ b/frontend/src/translate/languages/pt.js @@ -401,6 +401,21 @@ const messages = { disabled: "Desativado", }, }, + timeCreateNewTicket: { + name: "Cria novo ticket após", + note: "Selecione o tempo que será necessário para abrir um novo ticket, caso o cliente entre em contatos novamente", + options: { + "10": "10 Segundos", + "30": "30 Segundos", + "60": "1 minuto", + "300": "5 minutos", + "1800" : "30 minutos", + "3600" : "1 hora", + "7200" : "2 horas", + "21600" : "6 horas", + "43200" : "12 horas", + }, + }, }, }, messagesList: {