Merge pull request #980 from OpenSignLabs/raktima-opensignlabs-patch-11

fix: issue with files opening in a new tab on download instead of direct download
This commit is contained in:
prafull-opensignlabs
2024-07-26 19:24:46 +05:30
committed by GitHub
2 changed files with 21 additions and 3 deletions
+15 -1
View File
@@ -1979,6 +1979,20 @@ export const handleSendOTP = async (email) => {
alert(error.message);
}
};
export const fetchUrl = async (url, pdfName) => {
try {
const response = await fetch(url);
if (!response.ok) {
alert("something went wrong, please try again later.");
throw new Error("Network response was not ok");
}
const blob = await response.blob();
saveAs(blob, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`);
} catch (error) {
alert("something went wrong, please try again later.");
console.error("Error downloading the file:", error);
}
};
//handle download signed pdf
export const handleDownloadPdf = async (
pdfDetails,
@@ -2001,7 +2015,7 @@ export const handleDownloadPdf = async (
}
);
const url = axiosRes.data.result;
saveAs(url, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`);
await fetchUrl(url, pdfName);
setIsDownloading("");
} catch (err) {
console.log("err in getsignedurl", err);
@@ -10,10 +10,10 @@ import Tooltip from "./Tooltip";
import { RWebShare } from "react-web-share";
import Tour from "reactour";
import Parse from "parse";
import { saveAs } from "file-saver";
import {
checkIsSubscribedTeam,
copytoData,
fetchUrl,
replaceMailVaribles
} from "../constant/Utils";
import Confetti from "react-confetti";
@@ -595,14 +595,18 @@ const ReportTable = (props) => {
// `handleDownload` is used to get valid doc url available in completed report
const handleDownload = async (item) => {
setActLoader({ [`${item.objectId}`]: true });
const url = item?.SignedUrl || item?.URL || "";
const pdfName = item?.Name || "exported_file";
if (url) {
try {
const signedUrl = await Parse.Cloud.run("getsignedurl", { url: url });
saveAs(signedUrl);
await fetchUrl(signedUrl, pdfName);
setActLoader({});
} catch (err) {
console.log("err in getsignedurl", err);
alert("something went wrong, please try again later.");
setActLoader({});
}
}
};