Skip to content

Commit 70ae1e2

Browse files
fix: merge conflict
2 parents c491595 + 6875135 commit 70ae1e2

File tree

5 files changed

+280
-176
lines changed

5 files changed

+280
-176
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ We would like to thank all our contributors and users for their support and feed
136136
<td align="center" valign="top" width="14.28%"><a href="https://github.com/VikramNagwal"><img src="https://avatars.githubusercontent.com/u/123088024?v=4?s=100" width="100px;" alt="Vikram"/><br /><sub><b>Vikram</b></sub></a><br /><a href="#code-VikramNagwal" title="Code">💻</a></td>
137137
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ugoconsonni"><img src="https://avatars.githubusercontent.com/u/13661702?v=4?s=100" width="100px;" alt="ugoconsonni"/><br /><sub><b>ugoconsonni</b></sub></a><br /><a href="#code-ugoconsonni" title="Code">💻</a></td>
138138
<td align="center" valign="top" width="14.28%"><a href="https://github.com/daniel-mutwiri"><img src="https://avatars.githubusercontent.com/u/8936960?v=4?s=100" width="100px;" alt="Daniel Mutwiri"/><br /><sub><b>Daniel Mutwiri</b></sub></a><br /><a href="#code-daniel-mutwiri" title="Code">💻</a></td>
139-
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Zathiel"><img src="https://avatars.githubusercontent.com/u/26553418?v=4?s=100" width="100px;" alt="Zathiel"/><br /><sub><b>Zathiel</b></sub></a><br /><a href="#code-Zathiel" title="Code">💻</a></td>
139+
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Zathiel"><img src="https://avatars.githubusercontent.com/u/26553418?v=4?s=100" width="100px;" alt="Zathiel"/><br /><sub><b>Zathiel</b></sub></a><br /><a href="#code-Zathiel" title="Code">💻</a><a href="#security-Zathiel" title="Security">🛡️</a></td>
140140
</tr>
141141
</tbody>
142142
</table>

apps/OpenSign/src/components/pdf/PdfHeader.js

Lines changed: 45 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React, { useState } from "react";
22
import PrevNext from "./PrevNext";
3-
import printModule from "print-js";
4-
import { getBase64FromUrl } from "../../constant/Utils";
5-
import { saveAs } from "file-saver";
3+
import {
4+
handleDownloadCertificate,
5+
handleDownloadPdf,
6+
handleToPrint
7+
} from "../../constant/Utils";
68
import "../../styles/signature.css";
79
import * as DropdownMenu from "@radix-ui/react-dropdown-menu";
810
import { useNavigate } from "react-router-dom";
911
import { themeColor } from "../../constant/const";
10-
import axios from "axios";
1112
import ModalUi from "../../primitives/ModalUi";
12-
import { appInfo } from "../../constant/appinfo";
1313

1414
function Header({
1515
isPdfRequestFiles,
@@ -59,130 +59,6 @@ function Header({
5959
setIsDecline(currentDecline);
6060
};
6161

62-
//function for print digital sign pdf
63-
const handleToPrint = async (event) => {
64-
event.preventDefault();
65-
setIsDownloading("pdf");
66-
try {
67-
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
68-
const axiosRes = await axios.post(
69-
`${appInfo.baseUrl}/functions/getsignedurl`,
70-
{ url: pdfUrl },
71-
{
72-
headers: {
73-
"content-type": "Application/json",
74-
"X-Parse-Application-Id": appInfo.appId,
75-
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
76-
}
77-
}
78-
);
79-
const url = axiosRes.data.result;
80-
const pdf = await getBase64FromUrl(url);
81-
const isAndroidDevice = navigator.userAgent.match(/Android/i);
82-
const isAppleDevice =
83-
(/iPad|iPhone|iPod/.test(navigator.platform) ||
84-
(navigator.platform === "MacIntel" &&
85-
navigator.maxTouchPoints > 1)) &&
86-
!window.MSStream;
87-
if (isAndroidDevice || isAppleDevice) {
88-
const byteArray = Uint8Array.from(
89-
atob(pdf)
90-
.split("")
91-
.map((char) => char.charCodeAt(0))
92-
);
93-
const blob = new Blob([byteArray], { type: "application/pdf" });
94-
const blobUrl = URL.createObjectURL(blob);
95-
window.open(blobUrl, "_blank");
96-
setIsDownloading("");
97-
} else {
98-
printModule({ printable: pdf, type: "pdf", base64: true });
99-
setIsDownloading("");
100-
}
101-
} catch (err) {
102-
setIsDownloading("");
103-
console.log("err in getsignedurl", err);
104-
alert("something went wrong, please try again later.");
105-
}
106-
};
107-
108-
//handle download signed pdf
109-
const handleDownloadPdf = async () => {
110-
setIsDownloading("pdf");
111-
const pdfName = pdfDetails[0] && pdfDetails[0].Name;
112-
try {
113-
// const url = await Parse.Cloud.run("getsignedurl", { url: pdfUrl });
114-
const axiosRes = await axios.post(
115-
`${appInfo.baseUrl}/functions/getsignedurl`,
116-
{ url: pdfUrl },
117-
{
118-
headers: {
119-
"content-type": "Application/json",
120-
"X-Parse-Application-Id": appInfo.appId,
121-
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
122-
}
123-
}
124-
);
125-
const url = axiosRes.data.result;
126-
saveAs(url, `${sanitizeFileName(pdfName)}_signed_by_OpenSign™.pdf`);
127-
setIsDownloading("");
128-
} catch (err) {
129-
console.log("err in getsignedurl", err);
130-
setIsDownloading("");
131-
alert("something went wrong, please try again later.");
132-
}
133-
};
134-
135-
const sanitizeFileName = (pdfName) => {
136-
// Replace spaces with underscore
137-
return pdfName.replace(/ /g, "_");
138-
};
139-
140-
//handle download signed pdf
141-
const handleDownloadCertificate = async () => {
142-
if (pdfDetails?.length > 0 && pdfDetails[0]?.CertificateUrl) {
143-
try {
144-
await fetch(pdfDetails[0] && pdfDetails[0]?.CertificateUrl);
145-
const certificateUrl = pdfDetails[0] && pdfDetails[0]?.CertificateUrl;
146-
saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`);
147-
} catch (err) {
148-
console.log("err in download in certificate", err);
149-
}
150-
} else {
151-
setIsDownloading("certificate");
152-
try {
153-
const data = {
154-
docId: pdfDetails[0]?.objectId
155-
};
156-
const docDetails = await axios.post(
157-
`${localStorage.getItem("baseUrl")}functions/getDocument`,
158-
data,
159-
{
160-
headers: {
161-
"Content-Type": "application/json",
162-
"X-Parse-Application-Id": localStorage.getItem("parseAppId"),
163-
sessionToken: localStorage.getItem("accesstoken")
164-
}
165-
}
166-
);
167-
if (docDetails.data && docDetails.data.result) {
168-
const doc = docDetails.data.result;
169-
if (doc?.CertificateUrl) {
170-
await fetch(doc?.CertificateUrl);
171-
const certificateUrl = doc?.CertificateUrl;
172-
saveAs(certificateUrl, `Certificate_signed_by_OpenSign™.pdf`);
173-
setIsDownloading("");
174-
} else {
175-
setIsDownloading("certificate");
176-
}
177-
}
178-
} catch (err) {
179-
setIsDownloading("");
180-
console.log("err in download in certificate", err);
181-
alert("something went wrong, please try again later.");
182-
}
183-
}
184-
};
185-
18662
return (
18763
<div style={{ padding: "5px 0px 5px 0px" }} className="mobileHead">
18864
{isMobile && isShowHeader ? (
@@ -255,7 +131,9 @@ function Header({
255131
>
256132
<DropdownMenu.Item
257133
className="DropdownMenuItem"
258-
onClick={() => handleDownloadPdf()}
134+
onClick={() =>
135+
handleDownloadPdf(pdfDetails, pdfUrl, setIsDownloading)
136+
}
259137
>
260138
<div
261139
style={{
@@ -274,7 +152,12 @@ function Header({
274152
{isCompleted && (
275153
<DropdownMenu.Item
276154
className="DropdownMenuItem"
277-
onClick={() => handleDownloadCertificate()}
155+
onClick={() =>
156+
handleDownloadCertificate(
157+
pdfDetails,
158+
setIsDownloading
159+
)
160+
}
278161
>
279162
<div
280163
style={{
@@ -313,7 +196,9 @@ function Header({
313196
)}
314197
<DropdownMenu.Item
315198
className="DropdownMenuItem"
316-
onClick={handleToPrint}
199+
onClick={(e) =>
200+
handleToPrint(e, pdfUrl, setIsDownloading)
201+
}
317202
>
318203
<div
319204
style={{
@@ -395,7 +280,13 @@ function Header({
395280
>
396281
<DropdownMenu.Item
397282
className="flex flex-row justify-center items-center text-[13px] focus:outline-none cursor-pointer"
398-
onClick={() => handleDownloadPdf()}
283+
onClick={() =>
284+
handleDownloadPdf(
285+
pdfDetails,
286+
pdfUrl,
287+
setIsDownloading
288+
)
289+
}
399290
>
400291
<i
401292
className="fa fa-arrow-down mr-[5px]"
@@ -482,7 +373,9 @@ function Header({
482373
{isCompleted && (
483374
<button
484375
type="button"
485-
onClick={() => handleDownloadCertificate()}
376+
onClick={() =>
377+
handleDownloadCertificate(pdfDetails, setIsDownloading)
378+
}
486379
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#08bc66]"
487380
>
488381
<i
@@ -494,7 +387,7 @@ function Header({
494387
)}
495388

496389
<button
497-
onClick={handleToPrint}
390+
onClick={(e) => handleToPrint(e, pdfUrl, setIsDownloading)}
498391
type="button"
499392
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
500393
>
@@ -505,7 +398,9 @@ function Header({
505398
<button
506399
type="button"
507400
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#f14343]"
508-
onClick={() => handleDownloadPdf()}
401+
onClick={() =>
402+
handleDownloadPdf(pdfDetails, pdfUrl, setIsDownloading)
403+
}
509404
>
510405
<i className="fa fa-download py-[3px]" aria-hidden="true"></i>
511406
<span className="hidden lg:block ml-1">Download</span>
@@ -554,7 +449,13 @@ function Header({
554449
>
555450
<DropdownMenu.Item
556451
className="flex flex-row justify-center items-center text-[13px] focus:outline-none cursor-pointer"
557-
onClick={() => handleDownloadPdf()}
452+
onClick={() =>
453+
handleDownloadPdf(
454+
pdfDetails,
455+
pdfUrl,
456+
setIsDownloading
457+
)
458+
}
558459
>
559460
<i
560461
className="fa fa-arrow-down mr-[5px]"
@@ -574,7 +475,9 @@ function Header({
574475
{isCompleted && (
575476
<button
576477
type="button"
577-
onClick={() => handleDownloadCertificate()}
478+
onClick={() =>
479+
handleDownloadCertificate(pdfDetails, setIsDownloading)
480+
}
578481
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#08bc66]"
579482
>
580483
<i
@@ -585,7 +488,7 @@ function Header({
585488
</button>
586489
)}
587490
<button
588-
onClick={handleToPrint}
491+
onClick={(e) => handleToPrint(e, pdfUrl, setIsDownloading)}
589492
type="button"
590493
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#188ae2]"
591494
>
@@ -595,7 +498,9 @@ function Header({
595498
<button
596499
type="button"
597500
className="flex flex-row items-center shadow rounded-[3px] py-[3px] px-[11px] text-white font-[500] text-[13px] mr-[5px] bg-[#f14343]"
598-
onClick={() => handleDownloadPdf()}
501+
onClick={() =>
502+
handleDownloadPdf(pdfDetails, pdfUrl, setIsDownloading)
503+
}
599504
>
600505
<i className="fa fa-download py-[3px]" aria-hidden="true"></i>
601506
<span className="hidden lg:block ml-1">Download</span>

0 commit comments

Comments
 (0)