Alteração no botao download csv

pull/20/head
adriano 2022-09-06 01:09:52 -03:00
parent 55e83ff8fc
commit 0e720ef48e
1 changed files with 20 additions and 8 deletions

View File

@ -22,6 +22,7 @@ import fileDownload from 'js-file-download'
import openSocket from "socket.io-client"; import openSocket from "socket.io-client";
import { TramOutlined } from "@material-ui/icons";
const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }] const report = [{ 'value': '1', 'label': 'Atendimento por atendentes' }, { 'value': '2', 'label': 'Usuários online/offline' }]
@ -249,6 +250,7 @@ const Report = () => {
const [onQueueStatus, setOnQueueProcessStatus] = useState(undefined) const [onQueueStatus, setOnQueueProcessStatus] = useState(undefined)
const [csvFile, setCsvFile] = useState() const [csvFile, setCsvFile] = useState()
@ -415,26 +417,30 @@ const Report = () => {
return () => clearTimeout(delayDebounceFn); return () => clearTimeout(delayDebounceFn);
}, [ userA ]) }, [ userA ])
const handleCSVDownload = async () => {
const handleCSVDownload = async () => {
setOnQueueProcessStatus('downloading')
try { try {
let res = await apiBroker.get(`/reports/download/${csvFile}`, { responseType: 'blob' }); let res = await apiBroker.get(`/reports/download/${csvFile}`, { responseType: 'blob' });
if (res) { if (res) {
fileDownload(res.data, `${csvFile}`); fileDownload(res.data, `${csvFile}`);
setOnQueueProcessStatus('empty')
setOnQueueProcessStatus('empty')
} }
} catch (err) { } catch (err) {
console.log(err); console.log(err);
} }
} }
const handleCSVMessages = () => { const handleCSVMessages = () => {
@ -599,14 +605,20 @@ const Report = () => {
<> <>
<Button <Button
variant="contained" variant="contained"
color="primary" color="primary"
onClick={(e) => { onClick={(e) => {
handleCSVDownload() handleCSVDownload(e)
}} }}
> >
{"CSV DOWNLOAD"} {'CSV DOWNLOAD'}
</Button> </Button>
</>); </>);
case 'downloading':
return (
<>
<span>DOWNLOADING...</span>
</>);
default: default:
return (<><span>WAITING...</span></>); return (<><span>WAITING...</span></>);