From 5bcfc1bdccc2ebcdfaad23e07a0b3f7313583bd4 Mon Sep 17 00:00:00 2001 From: adriano Date: Wed, 13 Mar 2024 18:16:56 -0300 Subject: [PATCH] feat: Implement querying of synthetic and analytical reports on tickets --- .../TicketServices/ShowTicketReport.ts | 9 +- .../src/components/ReportModalType/index.js | 135 ++++++++++++++++++ frontend/src/pages/Report/index.js | 43 ++++-- 3 files changed, 171 insertions(+), 16 deletions(-) create mode 100644 frontend/src/components/ReportModalType/index.js diff --git a/backend/src/services/TicketServices/ShowTicketReport.ts b/backend/src/services/TicketServices/ShowTicketReport.ts index c60156d..bb2ab2e 100644 --- a/backend/src/services/TicketServices/ShowTicketReport.ts +++ b/backend/src/services/TicketServices/ShowTicketReport.ts @@ -40,8 +40,7 @@ const ShowTicketReport = async ({ createdOrUpdated = "created", queueId }: Request): Promise => { - let where_clause: any = {}; - // let where_clause_msg: any = {}; + let where_clause: any = {}; if (userId !== "0") { where_clause.userid = userId; @@ -71,7 +70,7 @@ const ShowTicketReport = async ({ if (queueId) { where_clause.queueId = queueId; - } + } const limit = 40; const offset = limit * (+pageNumber - 1); @@ -108,7 +107,7 @@ const ShowTicketReport = async ({ model: Message, required: true, separate: true, - where: where_clause_msg , + // where: where_clause_msg , attributes: [ "body", @@ -151,7 +150,7 @@ const ShowTicketReport = async ({ if (!tickets) { throw new AppError("ERR_NO_TICKET_FOUND", 404); - } + } return { tickets, count, hasMore }; }; diff --git a/frontend/src/components/ReportModalType/index.js b/frontend/src/components/ReportModalType/index.js new file mode 100644 index 0000000..eb7287a --- /dev/null +++ b/frontend/src/components/ReportModalType/index.js @@ -0,0 +1,135 @@ +import React, { useState, useEffect } from "react" +import Box from '@mui/material/Box' +import Button from '@mui/material/Button' +import Dialog from '@mui/material/Dialog' +import DialogActions from '@mui/material/DialogActions' +import DialogContent from '@mui/material/DialogContent' +import DialogContentText from '@mui/material/DialogContentText' +import DialogTitle from '@mui/material/DialogTitle' +import FormControl from '@mui/material/FormControl' + +import InputLabel from '@mui/material/InputLabel' +import MenuItem from '@mui/material/MenuItem' +import Select from '@mui/material/Select' + + + + +export default function MaxWidthDialog(props) { + const [open, setOpen] = useState(false) + const [fullWidth,] = useState(true) + const [currency, setCurrency] = useState(props.reportOption) + const [textOption, setTextOption] = useState('') + + + useEffect(() => { + + // props.func(currency) + + if(currency === '2' || currency === '3'){ + setTextOption('Retorna apenas tickets com status: fechado') + } + else{ + setTextOption('Retorna todos os tickets com status: aberto, fechado, pendente') + } + + }, [currency, props]) + + + const handleClickOpen = () => { + setOpen(true) + } + + const handleClose = () => { + + props.func(currency) + + setOpen(false) + } + + const handleMaxWidthChange = (event) => { + + setCurrency(event.target.value) + + + } + + + + return ( + + + + Relatórios + + + + Escolha uma opção do tipo de relatório abaixo + + + + + + opcoes + + + + + + {/* + } + label="Full width" + /> */} + + +
{textOption}
+ +
+ + + + + + +
+ +
+
+ ) +} diff --git a/frontend/src/pages/Report/index.js b/frontend/src/pages/Report/index.js index 75886f5..3ad2efa 100644 --- a/frontend/src/pages/Report/index.js +++ b/frontend/src/pages/Report/index.js @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useReducer, useContext } from "react" +import React, { useState, useEffect, useReducer, useContext, useCallback } from "react" import MainContainer from "../../components/MainContainer" import api from "../../services/api" import SelectField from "../../components/Report/SelectField" @@ -17,6 +17,8 @@ import Checkbox from '@mui/material/Checkbox' import { Button } from "@material-ui/core" import ReportModal from "../../components/ReportModal" +import ReportModalType from "../../components/ReportModalType" + import MaterialTable from 'material-table' import LogoutIcon from '@material-ui/icons/CancelOutlined' @@ -34,6 +36,9 @@ import Switch from '@mui/material/Switch' const label = { inputProps: { 'aria-label': 'Size switch demo' } } const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }] +const reportOptType = [{ 'value': '1', 'label': 'Padrão' }, { 'value': '2', 'label': 'Sintético' }, { 'value': '3', 'label': 'Analítico' }] + + const reducerQ = (state, action) => { @@ -276,21 +281,16 @@ const Report = () => { const [hasMore, setHasMore] = useState(false) const [pageNumberTickets, setTicketsPageNumber] = useState(1) const [totalCountTickets, setTotalCountTickets] = useState(0) - - - const [pageNumber, setPageNumber] = useState(1) const [users, dispatch] = useReducer(reducer, []) const [startDate, setDatePicker1] = useState(new Date()) const [endDate, setDatePicker2] = useState(new Date()) const [userId, setUser] = useState(null) const [query, dispatchQ] = useReducer(reducerQ, []) - const [reportOption, setReport] = useState('1') const [reporList,] = useState(report) const [profile, setProfile] = useState('') const [dataRows, setData] = useState([]) - const [onQueueStatus, setOnQueueProcessStatus] = useState(undefined) const [csvFile, setCsvFile] = useState() const [selectedValue, setSelectedValue] = useState('created') @@ -298,6 +298,9 @@ const Report = () => { const [queues, setQueues] = useState([]) const [queueId, setQueue] = useState(null) + const [reportTypeList,] = useState(reportOptType) + const [reportType, setReportType] = useState('1') + useEffect(() => { dispatch({ type: "RESET" }) dispatchQ({ type: "RESET" }) @@ -424,8 +427,21 @@ const Report = () => { setChecked(true) } setReport(data) - } + } + // Get from report type option + const reportTypeValue = (data) => { + console.log('DATA: ', data) + let type = '1' + if (data === '1') type = 'default' + if (data === '2') type = 'synthetic' + if (data === '3') type = 'analytic' + + handleCSVMessages(type) + + setReportType(data) + } + useEffect(() => { if (reportOption === '1') { @@ -500,7 +516,7 @@ const Report = () => { - const handleCSVMessages = () => { + const handleCSVMessages = (type = 'default') => { const fetchQueries = async () => { @@ -519,7 +535,8 @@ const Report = () => { userId: userId, startDate: startDate, endDate: endDate - } + }, + query_type: type }) const onQueueStatus = querySavedOnQueue.data.queueStatus @@ -639,7 +656,10 @@ const Report = () => { case 'empty': return ( <> - + + */} ) case 'pending' || 'processing':