I am trying to add validations based on the response from api 200 or 400 and want to show message to user using snaqebar but once i download the csv first time browser gets stuck also validation message is not coming when exporting the file for first time.
//api service for exporting csv
function downloadFilteredTicketsCsv(ticketModalData) {
const link = document.createElement("a");
link.target = "_blank";
link.download = "Service Tickets";
axios
.post(apiUrl + apiUrlConstant.DOWNLOAD_FILTERED_TICKETS_CSV, ticketModalData)
.then((response) => {
link.href = URL.createObjectURL(
new Blob([response.data], { type: "text/csv" })
);
link.click();
return response
})
.catch(err => {
return err;
});
// function when clicking the event
const downloadFilteredTicketsCSV = () => {
let modifiedTicketData = cloneDeep(ticketModalData)
modifiedTicketData.parameters.pageSize = totalRows;
if (totalRows > 1000) {
enqueueSnackbar("The record limit has exceeded. You can download only up to 1000 records at a time.", {
variant: "warning",
});
} else {
serviceDashboardService.downloadFilteredTicketsCsv(modifiedTicketData)
.then(response => {
console.log(response, 'response')
if (response.status === 200) {
enqueueSnackbar("Please wait...It may take sometime to download the file.", {
variant: "success",
});
} else {
console.log(response, 'response2')
enqueueSnackbar(response.data.message, {
variant: "error",
});
}
})
}
};