refactor code

This commit is contained in:
RaktimaNXG
2024-09-19 17:19:45 +05:30
parent 9852c87be7
commit 0f1ef0406e
3 changed files with 34 additions and 16 deletions
+1 -1
View File
@@ -246,7 +246,7 @@ export class AppComponent{
{" "}
{t("public-template-mssg-4")}
<a
href="https://www.npmjs.com/package/opensignme-angular"
href="https://www.npmjs.com/package/opensign-angular"
target="_blank"
rel="noreferrer"
className="cursor-pointer text-blue-700 "
+15 -6
View File
@@ -297,15 +297,15 @@ function PdfRequestFiles(props) {
}
}
);
const documentData =
templateDeatils.data && templateDeatils.data.result
? [templateDeatils.data.result]
: [];
const documentData = templateDeatils?.data?.result
? [templateDeatils?.data?.result]
: [];
if (documentData && documentData[0]?.error) {
props?.setTemplateStatus &&
props?.setTemplateStatus({
status: "Invalid"
});
throw new Error("error: Invalid TemplateId");
} else if (documentData && documentData.length > 0) {
if (documentData[0]?.IsPublic) {
props?.setTemplateStatus &&
@@ -359,20 +359,30 @@ function PdfRequestFiles(props) {
props?.setTemplateStatus({
status: "Private"
});
setIsLoading(false);
setHandleError(t("something-went-wrong-mssg"));
console.error("error: TemplateId is not public");
return;
}
} else {
props?.setTemplateStatus &&
props?.setTemplateStatus({
status: "Invalid"
});
setIsLoading(false);
setHandleError(t("something-went-wrong-mssg"));
console.error("error: Invalid TemplateId");
return;
}
} catch (err) {
console.log("err in get template details ", err);
setIsLoading(false);
if (err?.response?.data?.code === 101) {
setHandleError(t("error-template"));
} else {
setHandleError(t("something-went-wrong-mssg"));
}
console.error("error: Invalid TemplateId");
return;
}
};
//function for get document details for perticular signer with signer'object id
@@ -1641,7 +1651,6 @@ function PdfRequestFiles(props) {
</div>
);
};
console.log("templateId", props.templateId);
return (
<DndProvider backend={HTML5Backend}>
<Title title={props.templateId ? "Public Sign" : "Request Sign"} />
+18 -9
View File
@@ -11,28 +11,37 @@ import { isPublicStaging } from "../constant/const";
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.mjs`;
// Wrapper component to manage props
const PublicScriptFileWrapper = ({ initialProps }) => {
const [props, setProps] = useState(initialProps);
const PublicScriptFileWrapper = () => {
const [props, setProps] = useState("");
// Make the setProps function globally accessible
useEffect(() => {
// Assigns the function 'setProps' to the global 'window' object as 'updatePublicTemplateProps'.
// This allows 'setProps' to be accessed and called globally across different scripts or components,
// enabling dynamic updates to the public template's properties.
window.updatePublicTemplateProps = setProps;
const publicScript = document.getElementById("opensign-script");
// condition for using plan js load opensign-script then get templateId
if (publicScript) {
// Get the custom templateId attribute
const templateId = publicScript.getAttribute("templateId");
if (templateId) {
setProps({ templateId: templateId });
} else {
const error = "error: TemplateId is missing";
throw new Error(error);
}
}
return () => {
window.updatePublicTemplateProps = undefined;
};
}, []);
return <PdfRequestFiles {...props} />;
};
const appId = isPublicStaging ? "opensign" : "legadranaxn";
//"opensign"
const serverUrl = isPublicStaging
? "https://staging-app.opensignlabs.com/api/app"
: "https://app.opensignlabs.com/api/app";
// "https://staging-app.opensignlabs.com/api/app"
localStorage.setItem("baseUrl", `${serverUrl}/`);
localStorage.setItem("parseAppId", appId);
@@ -58,7 +67,7 @@ const root = ReactDOM.createRoot(document.getElementById("script-component"));
root.render(
<div data-theme="opensigncss">
<Provider store={store}>
<PublicScriptFileWrapper initialProps={{ text: "templateId" }} />
<PublicScriptFileWrapper />
</Provider>
</div>
);