Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 78 additions & 95 deletions apps/OpenSign/src/pages/Form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ function Form() {
}

const Forms = (props) => {
const appName =
"OpenSign™";
const appName = "OpenSign™";
const { t } = useTranslation();
const abortController = new AbortController();
const inputFileRef = useRef(null);
Expand All @@ -70,7 +69,7 @@ const Forms = (props) => {
NotifyOnSignatures: "",
Bcc: [],
RedirectUrl: "",
AllowModifications: false,
AllowModifications: false
});
const [fileupload, setFileUpload] = useState("");
const [selectedFiles, setSelectedFiles] = useState([]);
Expand Down Expand Up @@ -101,8 +100,7 @@ const Forms = (props) => {
extUserData?.IsTourEnabled === false
? "false"
: "true";
const fileSize =
maxFileSize;
const fileSize = maxFileSize;
useEffect(() => {
handleReset();
return () => abortController.abort();
Expand All @@ -114,12 +112,12 @@ const Forms = (props) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
const initializeValues = async () => {
setFormData((obj) => ({
...obj,
NotifyOnSignatures: true,
SendinOrder: sendinorder,
IsTourEnabled: istourenabled
}));
setFormData((obj) => ({
...obj,
NotifyOnSignatures: true,
SendinOrder: sendinorder,
IsTourEnabled: istourenabled
}));
};

// `removeFile` is used to reset progress, percentage and remove file if exists
Expand Down Expand Up @@ -278,8 +276,7 @@ const Forms = (props) => {
setfileload(false);
removeFile(e);
console.log("err in docx to pdf ", err);
const error =
t("docx-error");
const error = t("docx-error");
if (err?.code === 209) {
dispatch(sessionStatus(false));
} else {
Expand Down Expand Up @@ -308,25 +305,25 @@ const Forms = (props) => {
const name = generatePdfName(16);
const pdfName = `${name}.pdf`;
let uploadedUrl = "";
const parseFile = new Parse.File(
pdfName,
[...pdfBytes],
"application/pdf"
);
const response = await parseFile.save({
progress: (progressValue, loaded, total, { type }) => {
if (type === "upload" && progressValue !== null) {
const percentCompleted = Math.round((loaded * 100) / total);
setpercentage(percentCompleted);
}
}
});
if (response.url()) {
const fileRes = await getSecureUrl(response.url());
if (fileRes.url) {
uploadedUrl = fileRes.url;
const parseFile = new Parse.File(
pdfName,
[...pdfBytes],
"application/pdf"
);
const response = await parseFile.save({
progress: (progressValue, loaded, total) => {
if (progressValue !== null) {
const percentCompleted = Math.round((loaded * 100) / total);
setpercentage(percentCompleted);
}
}
});
if (response.url()) {
const fileRes = await getSecureUrl(response.url());
if (fileRes.url) {
uploadedUrl = fileRes.url;
}
}
if (uploadedUrl) {
const tenantId = localStorage.getItem("TenantId");
const userId = extUserData?.UserId?.objectId;
Expand Down Expand Up @@ -388,16 +385,13 @@ const Forms = (props) => {
object.set("Description", formData?.Description);
object.set("Note", formData?.Note);
if (props.title === "Request Signatures") {
if (
extUserData?.TenantId?.RequestBody &&
extUserData?.TenantId?.RequestSubject
) {
object.set("RequestBody", extUserData?.TenantId?.RequestBody);
object.set(
"RequestSubject",
extUserData?.TenantId?.RequestSubject
);
}
if (
extUserData?.TenantId?.RequestBody &&
extUserData?.TenantId?.RequestSubject
) {
object.set("RequestBody", extUserData?.TenantId?.RequestBody);
object.set("RequestSubject", extUserData?.TenantId?.RequestSubject);
}
}
if (props.title !== "Sign Yourself") {
const isChecked = formData.SendinOrder === "false" ? false : true;
Expand All @@ -416,11 +410,11 @@ const Forms = (props) => {
object.set("RemindOnceInEvery", remindOnceInEvery);
object.set("IsTourEnabled", isTourEnabled);
object.set("TimeToCompleteDays", TimeToCompleteDays);
object.set("AllowModifications", false);
object.set("IsEnableOTP", false);
if (formData.NotifyOnSignatures !== undefined) {
object.set("NotifyOnSignatures", formData.NotifyOnSignatures);
}
object.set("AllowModifications", false);
object.set("IsEnableOTP", false);
if (formData.NotifyOnSignatures !== undefined) {
object.set("NotifyOnSignatures", formData.NotifyOnSignatures);
}
if (formData?.RedirectUrl) {
object.set("RedirectUrl", formData.RedirectUrl);
}
Expand Down Expand Up @@ -457,9 +451,9 @@ const Forms = (props) => {
setBcc([]);
setFolder({ ObjectId: "", Name: "" });
const notifySign =
extUserData?.NotifyOnSignatures !== undefined
? extUserData?.NotifyOnSignatures
: true;
extUserData?.NotifyOnSignatures !== undefined
? extUserData?.NotifyOnSignatures
: true;
setFormData({
Name: "",
Description: "",
Expand All @@ -477,7 +471,7 @@ const Forms = (props) => {
IsEnableOTP: "false",
IsTourEnabled: istourenabled,
RedirectUrl: "",
AllowModifications: false,
AllowModifications: false
});
setFileUpload("");
setSelectedFiles([]);
Expand Down Expand Up @@ -539,9 +533,9 @@ const Forms = (props) => {
setBcc([]);
setFolder({ ObjectId: "", Name: "" });
const notifySign =
extUserData?.NotifyOnSignatures !== undefined
? extUserData?.NotifyOnSignatures
: true;
extUserData?.NotifyOnSignatures !== undefined
? extUserData?.NotifyOnSignatures
: true;
let obj = {
Name: "",
Description: "",
Expand All @@ -559,7 +553,7 @@ const Forms = (props) => {
IsTourEnabled: istourenabled,
NotifyOnSignatures: notifySign,
RedirectUrl: "",
AllowModifications: false,
AllowModifications: false
};
setFormData(obj);
removeFile();
Expand All @@ -581,35 +575,27 @@ const Forms = (props) => {
const name = generatePdfName(16);
const pdfFile = await decryptPdf(formData?.file, formData?.password);
setIsDecrypting(false);
const res = await getFileAsArrayBuffer(pdfFile);
const flatPdf = await flattenPdf(res);
const parseFile = new Parse.File(name, [...flatPdf], "application/pdf");
await parseFile.save({
progress: (progressValue, loaded, total, { type }) => {
if (type === "upload" && progressValue !== null) {
const percentCompleted = Math.round((loaded * 100) / total);
setpercentage(percentCompleted);
}
}
});
// Retrieve the URL of the uploaded file
if (parseFile.url()) {
const fileRes = await getSecureUrl(parseFile.url());
if (fileRes.url) {
setFileUpload(fileRes.url);
removeFile();
const title = generateTitleFromFilename(formData?.file?.name);
setFormData((obj) => ({ ...obj, password: "", Name: title }));
SaveFileSize(size, fileRes?.url, tenantId, userId);
return fileRes.url;
} else {
removeFile();
setFormData((prev) => ({ ...prev, password: "" }));
setIsDecrypting(false);
if (inputFileRef.current) {
inputFileRef.current.value = ""; // Set file input value to empty string
}
const res = await getFileAsArrayBuffer(pdfFile);
const flatPdf = await flattenPdf(res);
const parseFile = new Parse.File(name, [...flatPdf], "application/pdf");
await parseFile.save({
progress: (progressValue, loaded, total) => {
if (progressValue !== null) {
const percentCompleted = Math.round((loaded * 100) / total);
setpercentage(percentCompleted);
}
}
});
// Retrieve the URL of the uploaded file
if (parseFile.url()) {
const fileRes = await getSecureUrl(parseFile.url());
if (fileRes.url) {
setFileUpload(fileRes.url);
removeFile();
const title = generateTitleFromFilename(formData?.file?.name);
setFormData((obj) => ({ ...obj, password: "", Name: title }));
SaveFileSize(size, fileRes?.url, tenantId, userId);
return fileRes.url;
} else {
removeFile();
setFormData((prev) => ({ ...prev, password: "" }));
Expand All @@ -618,6 +604,14 @@ const Forms = (props) => {
inputFileRef.current.value = ""; // Set file input value to empty string
}
}
} else {
removeFile();
setFormData((prev) => ({ ...prev, password: "" }));
setIsDecrypting(false);
if (inputFileRef.current) {
inputFileRef.current.value = ""; // Set file input value to empty string
}
}
} catch (err) {
removeFile();
if (err?.code === 209) {
Expand Down Expand Up @@ -1060,10 +1054,7 @@ const Forms = (props) => {
{isAdvanceOpt && (
<div
style={{
height:
props.title === "New Template"
? "100px"
: "280px"
height: props.title === "New Template" ? "100px" : "280px"
}}
className="w-[1px] bg-gray-300 m-auto hidden md:inline-block"
></div>
Expand Down Expand Up @@ -1172,11 +1163,7 @@ const Forms = (props) => {
</Tooltip>
</label>
<div className="flex flex-col md:flex-row md:gap-4">
<div
className={
`flex items-center gap-2 ml-2 mb-1`
}
>
<div className={`flex items-center gap-2 ml-2 mb-1`}>
<input
className="mr-[2px] op-radio op-radio-xs"
type="radio"
Expand All @@ -1185,11 +1172,7 @@ const Forms = (props) => {
/>
<div className="text-center">{t("yes")}</div>
</div>
<div
className={
`flex items-center gap-2 ml-2 mb-1`
}
>
<div className={`flex items-center gap-2 ml-2 mb-1`}>
<input
className="mr-[2px] op-radio op-radio-xs"
type="radio"
Expand Down
22 changes: 7 additions & 15 deletions apps/OpenSign/src/pages/UserProfile.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
import React, {
useState,
useEffect,
} from "react";
import React, { useState, useEffect } from "react";
import { Navigate, useNavigate } from "react-router";
import Parse from "parse";
import { SaveFileSize } from "../constant/saveFileSize";
import dp from "../assets/images/dp.png";
import { sanitizeFileName } from "../utils";
import axios from "axios";
import Tooltip from "../primitives/Tooltip";
import {
getSecureUrl,
handleSendOTP,
} from "../constant/Utils";
import { getSecureUrl, handleSendOTP } from "../constant/Utils";
import ModalUi from "../primitives/ModalUi";
import Loader from "../primitives/Loader";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -133,7 +127,7 @@ function UserProfile() {
Name: obj.Name,
JobTitle: jobTitle,
Company: company,
Language: obj?.language || "",
Language: obj?.language || ""
};

await axios.put(
Expand Down Expand Up @@ -172,8 +166,8 @@ function UserProfile() {

try {
const response = await parseFile.save({
progress: (progressValue, loaded, total, { type }) => {
if (type === "upload" && progressValue !== null) {
progress: (progressValue, loaded, total) => {
if (progressValue !== null) {
const percentCompleted = Math.round((loaded * 100) / total);
// console.log("percentCompleted ", percentCompleted);
setpercentage(percentCompleted);
Expand Down Expand Up @@ -449,7 +443,7 @@ function UserProfile() {
<button
type="button"
onClick={(e) => {
editmode ? handleSubmit(e) : setEditMode(true);
editmode ? handleSubmit(e) : setEditMode(true);
}}
className="op-btn op-btn-primary md:w-[100px]"
>
Expand All @@ -460,9 +454,7 @@ function UserProfile() {
onClick={() =>
editmode ? handleCancel() : navigate("/changepassword")
}
className={
`op-btn ${editmode ? "op-btn-ghost w-[100px]" : "op-btn-secondary"}`
}
className={`op-btn ${editmode ? "op-btn-ghost w-[100px]" : "op-btn-secondary"}`}
>
{editmode ? t("cancel") : t("change-password")}
</button>
Expand Down