Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

147
Views
React export csv functionality

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",
                });
          }
        })
    }
  };

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!