import React, { useState } from "react"; import { saveAs } from "file-saver"; import celebration from "../../assests/newCeleb.gif"; import close from "../../assests/close.png"; import Modal from "react-bootstrap/Modal"; import ModalHeader from "react-bootstrap/esm/ModalHeader"; import axios from "axios"; import { getBase64FromUrl } from "../../utils/Utils"; import { themeColor } from "../../utils/ThemeColor/backColor"; import printModule from "print-js"; import loader from "../../assests/loader2.gif"; function EmailComponent({ isEmail, pdfUrl, isCeleb, setIsEmail, setSuccessEmail, signObjId, pdfName, sender, }) { const [emailCount, setEmailCount] = useState([]); const [emailValue, setEmailValue] = useState(); const [isLoading, setIsLoading] = useState(false); //function for send email const sendEmail = async () => { setIsLoading(true); let sendMail, recipent; for (let i = 0; i < emailCount.length; i++) { // await axios // .get( // `${localStorage.getItem("baseUrl")}classes/${localStorage.getItem("_appName")}_Contactbook?where={"Email":"${emailCount[i]}"}`, // { // headers: { // "Content-Type": "application/json", // "X-Parse-Application-Id": localStorage.getItem("parseAppId"), // sessionToken: localStorage.getItem("accesstoken"), // }, // } // ) // .then((Listdata) => { // const json = Listdata.data; // if (json.results[0]) { // recipent = json.results[0]; // } // }) // .catch((err) => { // console.log("axois err ", err); // }); try { console.log("recipients", recipent); const imgPng = "https://qikinnovation.ams3.digitaloceanspaces.com/logo.png"; // "https://qikinnovation.ams3.digitaloceanspaces.com/mailLogo_2023-08-18T12%3A51%3A31.573Z.png"; let url = `${localStorage.getItem("baseUrl")}functions/sendmailv3/`; const headers = { "Content-Type": "application/json", "X-Parse-Application-Id": localStorage.getItem("parseAppId"), sessionToken: localStorage.getItem("accesstoken"), }; // const serverUrl = localStorage.getItem("baseUrl"); // const newServer = serverUrl.replaceAll("/", "%2F"); // const serverParams = `${newServer}&${localStorage.getItem( // "parseAppId" // )}&${localStorage.getItem("_appName")}`; // let pdfUrlWeb = ` ${pdfName}`; const themeBGcolor = themeColor(); let params = { pdfName: pdfName, url: pdfUrl, recipient: emailCount[i], subject: `${sender.name} has signed the doc - ${pdfName}`, from: sender.email, html: "

Document Copy

A copy of the document " + pdfName + " Standard is attached to this email. Kindly download the document from the attachment.

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender " + sender.email + " directly. If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

", //"html":"

Digital Signature Request

" + recipent.Name + " has requested you to review and sign" +pdfName+"

Sender" + recipent.Email + "

This is an automated email from Open Sign. For any queries regarding this email, please contact the sender " + recipent.Email + " directly.If you think this email is inappropriate or spam, you may file a complaint with Open Sign here.

" }; sendMail = await axios.post(url, params, { headers: headers }); } catch (error) { console.log("error", error); setIsLoading(false); alert("Something went wrong!"); } } if (sendMail.data.result.status === "success") { setIsEmail(false); setSuccessEmail(true); setTimeout(() => { setSuccessEmail(false); }, 3000); setIsLoading(false); } else if (sendMail.data.result.status === "error") { setIsLoading(false); alert("Something went wrong!"); } else { setIsLoading(false); alert("Something went wrong!"); } }; //function for remove email const removeChip = (index) => { const updateEmailCount = emailCount.filter((data, key) => key !== index); setEmailCount(updateEmailCount); }; //function for get email value const handleEmailValue = (e) => { const value = e.target.value; setEmailValue(value); }; //function for save email in array after press enter const handleEnterPress = (e) => { if (e.key === "Enter" && emailValue) { setEmailCount((prev) => [...prev, emailValue]); setEmailValue(""); } else if (e === "add" && emailValue) { setEmailCount((prev) => [...prev, emailValue]); setEmailValue(""); } }; // function for print signed pdf const handleToPrint = async (event) => { event.preventDefault(); const base64 = await getBase64FromUrl(pdfUrl); printModule({ printable: base64, type: "pdf", base64: true }); // window.print('https://nxgcreator.s3.ap-south-1.amazonaws.com/exported_file_32_2023-08-22T04%3A59%3A13.432Z.pdf',); }; //handle download signed pdf const handleDownloadPdf = () => { saveAs(pdfUrl, `${pdfName}_signed_by_OpenSign™.pdf`); }; return (
{/* isEmail */} {isLoading && (
no img This might take some time
)} Email Documents
{isCeleb && (
print img
)}

Recipients added here will get a copy of the signed document.

{emailCount.length > 0 ? ( <>
{emailCount.map((data, ind) => { return (
{data} print img removeChip(ind)} src={close} width={10} height={10} style={{ fontWeight: "600" }} />
); })}
{emailCount.length <= 9 && ( )}
) : (
)} { if (emailValue) { handleEnterPress("add"); } }} >
Note: {" "} You can only send to ten recipients at a time.
); } export default EmailComponent;