From a276acc26721a4032c7c8b2c75f1dee54c19af45 Mon Sep 17 00:00:00 2001 From: Robson Tenorio Henriques Date: Sat, 26 Oct 2024 22:43:22 -0300 Subject: [PATCH] =?UTF-8?q?Add=20Hist=C3=B3rico=20das=20Edi=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/MessageHistoryModal/index.js | 70 +++++++++++++++++++ frontend/src/components/MessageInput/index.js | 5 ++ .../components/MessageOptionsMenu/index.js | 32 +++++++-- frontend/src/translate/languages/pt.js | 6 ++ 4 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 frontend/src/components/MessageHistoryModal/index.js diff --git a/frontend/src/components/MessageHistoryModal/index.js b/frontend/src/components/MessageHistoryModal/index.js new file mode 100644 index 00000000..9ed94e84 --- /dev/null +++ b/frontend/src/components/MessageHistoryModal/index.js @@ -0,0 +1,70 @@ +import PropTypes from "prop-types"; +import React from "react"; + +import { Table, TableBody, TableCell, TableContainer, TableRow, makeStyles } from "@material-ui/core"; +import Button from "@material-ui/core/Button"; +import Dialog from "@material-ui/core/Dialog"; +import DialogActions from "@material-ui/core/DialogActions"; +import DialogContent from "@material-ui/core/DialogContent"; +import DialogTitle from "@material-ui/core/DialogTitle"; + +import { format, parseISO } from "date-fns"; + +import { i18n } from "../../translate/i18n"; + +const useStyles = makeStyles((theme) => ({ + timestamp: { + minWidth: 250 + } +})); + +const MessageHistoryModal = ({ open, onClose, oldMessages }) => { + const classes = useStyles(); + + return ( + onClose(false)} + aria-labelledby="dialog-title" + > + {i18n.t("messageHistoryModal.title")} + + + + + {oldMessages?.map((oldMessage) => ( + + + {oldMessage.body} + + + {format(parseISO(oldMessage.createdAt), "dd/MM HH:mm")} + + + ))} + +
+
+
+ + + + +
+ ); +}; + +MessageHistoryModal.propTypes = { + open: PropTypes.bool.isRequired, + onClose: PropTypes.func.isRequired, + oldMessages: PropTypes.array +}; + +export default MessageHistoryModal; \ No newline at end of file diff --git a/frontend/src/components/MessageInput/index.js b/frontend/src/components/MessageInput/index.js index 349e8fbd..994d8015 100644 --- a/frontend/src/components/MessageInput/index.js +++ b/frontend/src/components/MessageInput/index.js @@ -34,6 +34,7 @@ import clsx from "clsx"; import { Picker } from "emoji-mart"; import "emoji-mart/css/emoji-mart.css"; import MicRecorder from "mic-recorder-to-mp3"; +import PropTypes from "prop-types"; import React, { useContext, useEffect, @@ -786,4 +787,8 @@ const MessageInput = ({ ticketStatus }) => { } }; +MessageInput.propTypes = { + ticketStatus: PropTypes.string +} + export default MessageInput; \ No newline at end of file diff --git a/frontend/src/components/MessageOptionsMenu/index.js b/frontend/src/components/MessageOptionsMenu/index.js index 51e90023..bcab4201 100644 --- a/frontend/src/components/MessageOptionsMenu/index.js +++ b/frontend/src/components/MessageOptionsMenu/index.js @@ -3,17 +3,20 @@ import React, { useContext, useState } from "react"; import MenuItem from "@material-ui/core/MenuItem"; import { Menu } from "@material-ui/core"; +import PropTypes from "prop-types"; import { EditMessageContext } from "../../context/EditingMessage/EditingMessageContext"; import { ReplyMessageContext } from "../../context/ReplyingMessage/ReplyingMessageContext"; import toastError from "../../errors/toastError"; import api from "../../services/api"; import { i18n } from "../../translate/i18n"; import ConfirmationModal from "../ConfirmationModal"; +import MessageHistoryModal from "../MessageHistoryModal"; const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => { const { setReplyingMessage } = useContext(ReplyMessageContext); const { setEditingMessage } = useContext(EditMessageContext); const [confirmationOpen, setConfirmationOpen] = useState(false); + const [messageHistoryOpen, setMessageHistoryOpen] = useState(false); const canEditMessage = () => { const timeDiff = new Date() - new Date(message.updatedAt); @@ -47,6 +50,11 @@ const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => { handleClose(); }; + const handleOpenMessageHistoryModal = (e) => { + setMessageHistoryOpen(true); + handleClose(); + } + return ( <> { > {i18n.t("messageOptionsMenu.confirmationModal.message")} + + { ) ]} + {message.oldMessages?.length > 0 && ( + + {i18n.t("messageOptionsMenu.history")} + + )} {i18n.t("messageOptionsMenu.reply")} @@ -89,12 +108,11 @@ const MessageOptionsMenu = ({ message, menuOpen, handleClose, anchorEl }) => { ); }; -// MessageOptionsMenu.propTypes = { -// message: PropTypes.object, -// menuOpen: PropTypes.bool.isRequired, -// handleClose: PropTypes.func.isRequired, -// anchorEl: PropTypes.object -// } - +MessageOptionsMenu.propTypes = { + message: PropTypes.object, + menuOpen: PropTypes.bool.isRequired, + handleClose: PropTypes.func.isRequired, + anchorEl: PropTypes.object +} export default MessageOptionsMenu; diff --git a/frontend/src/translate/languages/pt.js b/frontend/src/translate/languages/pt.js index a4574b5c..0b10ed4d 100644 --- a/frontend/src/translate/languages/pt.js +++ b/frontend/src/translate/languages/pt.js @@ -675,6 +675,7 @@ const messages = { }, messageOptionsMenu: { edit: "Editar", + history: "Histórico", delete: "Deletar", reply: "Responder", confirmationModal: { @@ -682,6 +683,10 @@ const messages = { message: "Esta ação não pode ser revertida.", }, }, + messageHistoryModal: { + close: "Fechar", + title: "Histórico de edição da mensagem" + }, backendErrors: { ERR_NO_OTHER_WHATSAPP: "Deve haver pelo menos um WhatsApp padrão.", ERR_NO_DEF_WAPP_FOUND: "Nenhum WhatsApp padrão encontrado. Verifique a página de conexões.", @@ -692,6 +697,7 @@ const messages = { ERR_INVALID_CREDENTIALS: "Erro de autenticação. Por favor, tente novamente.", ERR_SENDING_WAPP_MSG: "Erro ao enviar mensagem do WhatsApp. Verifique a página de conexões.", ERR_DELETE_WAPP_MSG: "Não foi possível excluir a mensagem do WhatsApp.", + ERR_EDITING_WAPP_MSG: "Não foi possível editar a mensagem do WhatsApp.", ERR_OTHER_OPEN_TICKET: "Já existe um ticket aberto para este contato.", ERR_SESSION_EXPIRED: "Sessão expirada. Por favor entre.", ERR_USER_CREATION_DISABLED: "A criação do atendente foi desabilitada pelo administrador.",