2022-02-28 13:51:11 +00:00
|
|
|
import React, { useContext, useState, useEffect } from "react";
|
2022-01-06 01:26:15 +00:00
|
|
|
import { useHistory } from "react-router-dom";
|
|
|
|
|
|
|
|
import { makeStyles } from "@material-ui/core/styles";
|
|
|
|
import { IconButton } from "@material-ui/core";
|
|
|
|
import { MoreVert, Replay } from "@material-ui/icons";
|
|
|
|
|
|
|
|
import { i18n } from "../../translate/i18n";
|
|
|
|
import api from "../../services/api";
|
|
|
|
import TicketOptionsMenu from "../TicketOptionsMenu";
|
|
|
|
import ButtonWithSpinner from "../ButtonWithSpinner";
|
|
|
|
import toastError from "../../errors/toastError";
|
|
|
|
import { AuthContext } from "../../context/Auth/AuthContext";
|
|
|
|
|
2022-02-27 04:35:56 +00:00
|
|
|
import Modal from "../ChatEnd/ModalChatEnd";
|
|
|
|
import { render } from '@testing-library/react';
|
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const useStyles = makeStyles(theme => ({
|
|
|
|
actionButtons: {
|
|
|
|
marginRight: 6,
|
|
|
|
flex: "none",
|
|
|
|
alignSelf: "center",
|
|
|
|
marginLeft: "auto",
|
|
|
|
"& > *": {
|
|
|
|
margin: theme.spacing(1),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
const TicketActionButtons = ({ ticket, schedule }) => {
|
2022-01-06 01:26:15 +00:00
|
|
|
const classes = useStyles();
|
|
|
|
const history = useHistory();
|
|
|
|
const [anchorEl, setAnchorEl] = useState(null);
|
|
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
const ticketOptionsMenuOpen = Boolean(anchorEl);
|
|
|
|
const { user } = useContext(AuthContext);
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
const [chatEnd, setChatEnd] = useState(null)
|
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
const handleOpenTicketOptionsMenu = e => {
|
|
|
|
setAnchorEl(e.currentTarget);
|
|
|
|
};
|
|
|
|
|
|
|
|
const handleCloseTicketOptionsMenu = e => {
|
|
|
|
setAnchorEl(null);
|
|
|
|
};
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
const chatEndVal = (data) => {
|
|
|
|
|
|
|
|
if(data){
|
2022-02-28 18:17:36 +00:00
|
|
|
|
|
|
|
data = {...data, 'ticketId': ticket.id}
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
console.log('ChatEnd: ',(data));
|
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
handleUpdateTicketStatus(null, "closed", user?.id, data)
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setChatEnd(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
const handleModal = (status, userId) => {
|
2022-02-27 04:35:56 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
render(<Modal
|
|
|
|
modal_header={'Finalização de Atendimento'}
|
|
|
|
func={chatEndVal}
|
2022-02-28 18:17:36 +00:00
|
|
|
schedules={schedule}
|
|
|
|
/>)
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
};
|
2022-02-27 20:05:21 +00:00
|
|
|
|
2022-02-27 04:35:56 +00:00
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
const handleUpdateTicketStatus = async (e, status, userId, schedulingData={}) => {
|
2022-02-28 13:51:11 +00:00
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
// Thuanny
|
2022-02-27 04:35:56 +00:00
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
// let schedulingData = {
|
|
|
|
// 'ticketId': ticket.id,
|
|
|
|
// 'scheduleId': '2',
|
|
|
|
// 'cpf_cnpj': '3337733377',
|
|
|
|
// 'schedulingDate': '2022-02-25 22:30:42',
|
|
|
|
// 'reminder': 'Retorno',
|
|
|
|
// 'message': 'Ola sr estamos entrando em contato para confirma seu horário hoje às 17:00?',
|
|
|
|
// 'status': ''
|
|
|
|
// }
|
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
setLoading(true);
|
|
|
|
try {
|
2022-02-28 18:17:36 +00:00
|
|
|
|
|
|
|
if(status==='closed'){
|
|
|
|
|
|
|
|
await api.put(`/tickets/${ticket.id}`, {
|
|
|
|
status: status,
|
|
|
|
userId: userId || null,
|
|
|
|
schedulingNotifyData: JSON.stringify(schedulingData)
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
|
|
|
await api.put(`/tickets/${ticket.id}`, {
|
|
|
|
status: status,
|
|
|
|
userId: userId || null
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
2022-02-28 13:51:11 +00:00
|
|
|
|
|
|
|
setLoading(false);
|
|
|
|
if (status === "open") {
|
|
|
|
history.push(`/tickets/${ticket.id}`);
|
|
|
|
} else {
|
|
|
|
history.push("/tickets");
|
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
setLoading(false);
|
|
|
|
toastError(err);
|
|
|
|
}
|
|
|
|
|
2022-02-27 20:05:21 +00:00
|
|
|
|
2022-02-27 04:35:56 +00:00
|
|
|
|
2022-02-28 13:51:11 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classes.actionButtons}>
|
|
|
|
{ticket.status === "closed" && (
|
|
|
|
<ButtonWithSpinner
|
|
|
|
loading={loading}
|
|
|
|
startIcon={<Replay />}
|
|
|
|
size="small"
|
|
|
|
onClick={e => handleUpdateTicketStatus(e, "open", user?.id)}
|
|
|
|
>
|
|
|
|
{i18n.t("messagesList.header.buttons.reopen")}
|
|
|
|
</ButtonWithSpinner>
|
|
|
|
)}
|
|
|
|
{ticket.status === "open" && (
|
|
|
|
<>
|
|
|
|
<ButtonWithSpinner
|
|
|
|
loading={loading}
|
|
|
|
startIcon={<Replay />}
|
|
|
|
size="small"
|
|
|
|
onClick={e => handleUpdateTicketStatus(e, "pending", null)}
|
|
|
|
>
|
|
|
|
{i18n.t("messagesList.header.buttons.return")}
|
|
|
|
</ButtonWithSpinner>
|
2022-02-22 20:36:11 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
<ButtonWithSpinner
|
|
|
|
loading={loading}
|
|
|
|
size="small"
|
|
|
|
variant="contained"
|
|
|
|
color="primary"
|
2022-02-28 13:51:11 +00:00
|
|
|
onClick={e => {
|
|
|
|
|
2022-02-28 18:17:36 +00:00
|
|
|
handleModal( "closed", user?.id)
|
2022-02-28 13:51:11 +00:00
|
|
|
// handleUpdateTicketStatus(e, "closed", user?.id)
|
|
|
|
|
|
|
|
}}
|
2022-01-06 01:26:15 +00:00
|
|
|
>
|
|
|
|
{i18n.t("messagesList.header.buttons.resolve")}
|
|
|
|
</ButtonWithSpinner>
|
2022-02-22 20:36:11 +00:00
|
|
|
|
2022-01-06 01:26:15 +00:00
|
|
|
<IconButton onClick={handleOpenTicketOptionsMenu}>
|
|
|
|
<MoreVert />
|
|
|
|
</IconButton>
|
|
|
|
<TicketOptionsMenu
|
|
|
|
ticket={ticket}
|
|
|
|
anchorEl={anchorEl}
|
|
|
|
menuOpen={ticketOptionsMenuOpen}
|
|
|
|
handleClose={handleCloseTicketOptionsMenu}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
{ticket.status === "pending" && (
|
|
|
|
<ButtonWithSpinner
|
|
|
|
loading={loading}
|
|
|
|
size="small"
|
|
|
|
variant="contained"
|
|
|
|
color="primary"
|
|
|
|
onClick={e => handleUpdateTicketStatus(e, "open", user?.id)}
|
|
|
|
>
|
|
|
|
{i18n.t("messagesList.header.buttons.accept")}
|
|
|
|
</ButtonWithSpinner>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default TicketActionButtons;
|