Skip to content

Commit 0f1ef04

Browse files
refactor code
1 parent 9852c87 commit 0f1ef04

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export class AppComponent{
246246
{" "}
247247
{t("public-template-mssg-4")}
248248
<a
249-
href="https://www.npmjs.com/package/opensignme-angular"
249+
href="https://www.npmjs.com/package/opensign-angular"
250250
target="_blank"
251251
rel="noreferrer"
252252
className="cursor-pointer text-blue-700 "

apps/OpenSign/src/pages/PdfRequestFiles.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,15 @@ function PdfRequestFiles(props) {
297297
}
298298
}
299299
);
300-
const documentData =
301-
templateDeatils.data && templateDeatils.data.result
302-
? [templateDeatils.data.result]
303-
: [];
300+
const documentData = templateDeatils?.data?.result
301+
? [templateDeatils?.data?.result]
302+
: [];
304303
if (documentData && documentData[0]?.error) {
305304
props?.setTemplateStatus &&
306305
props?.setTemplateStatus({
307306
status: "Invalid"
308307
});
308+
throw new Error("error: Invalid TemplateId");
309309
} else if (documentData && documentData.length > 0) {
310310
if (documentData[0]?.IsPublic) {
311311
props?.setTemplateStatus &&
@@ -359,20 +359,30 @@ function PdfRequestFiles(props) {
359359
props?.setTemplateStatus({
360360
status: "Private"
361361
});
362+
setIsLoading(false);
363+
setHandleError(t("something-went-wrong-mssg"));
364+
console.error("error: TemplateId is not public");
365+
return;
362366
}
363367
} else {
364368
props?.setTemplateStatus &&
365369
props?.setTemplateStatus({
366370
status: "Invalid"
367371
});
372+
setIsLoading(false);
373+
setHandleError(t("something-went-wrong-mssg"));
374+
console.error("error: Invalid TemplateId");
375+
return;
368376
}
369377
} catch (err) {
370-
console.log("err in get template details ", err);
378+
setIsLoading(false);
371379
if (err?.response?.data?.code === 101) {
372380
setHandleError(t("error-template"));
373381
} else {
374382
setHandleError(t("something-went-wrong-mssg"));
375383
}
384+
console.error("error: Invalid TemplateId");
385+
return;
376386
}
377387
};
378388
//function for get document details for perticular signer with signer'object id
@@ -1641,7 +1651,6 @@ function PdfRequestFiles(props) {
16411651
</div>
16421652
);
16431653
};
1644-
console.log("templateId", props.templateId);
16451654
return (
16461655
<DndProvider backend={HTML5Backend}>
16471656
<Title title={props.templateId ? "Public Sign" : "Request Sign"} />

apps/OpenSign/src/script/PublicTemplate.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,37 @@ import { isPublicStaging } from "../constant/const";
1111
pdfjs.GlobalWorkerOptions.workerSrc = `//cdnjs.cloudflare.com/ajax/libs/pdf.js/${pdfjs.version}/pdf.worker.min.mjs`;
1212

1313
// Wrapper component to manage props
14-
const PublicScriptFileWrapper = ({ initialProps }) => {
15-
const [props, setProps] = useState(initialProps);
14+
const PublicScriptFileWrapper = () => {
15+
const [props, setProps] = useState("");
1616

17-
// Make the setProps function globally accessible
1817
useEffect(() => {
18+
// Assigns the function 'setProps' to the global 'window' object as 'updatePublicTemplateProps'.
19+
// This allows 'setProps' to be accessed and called globally across different scripts or components,
20+
// enabling dynamic updates to the public template's properties.
1921
window.updatePublicTemplateProps = setProps;
20-
22+
const publicScript = document.getElementById("opensign-script");
23+
// condition for using plan js load opensign-script then get templateId
24+
if (publicScript) {
25+
// Get the custom templateId attribute
26+
const templateId = publicScript.getAttribute("templateId");
27+
if (templateId) {
28+
setProps({ templateId: templateId });
29+
} else {
30+
const error = "error: TemplateId is missing";
31+
throw new Error(error);
32+
}
33+
}
2134
return () => {
2235
window.updatePublicTemplateProps = undefined;
2336
};
2437
}, []);
25-
2638
return <PdfRequestFiles {...props} />;
2739
};
2840

2941
const appId = isPublicStaging ? "opensign" : "legadranaxn";
30-
//"opensign"
31-
3242
const serverUrl = isPublicStaging
3343
? "https://staging-app.opensignlabs.com/api/app"
3444
: "https://app.opensignlabs.com/api/app";
35-
// "https://staging-app.opensignlabs.com/api/app"
3645

3746
localStorage.setItem("baseUrl", `${serverUrl}/`);
3847
localStorage.setItem("parseAppId", appId);
@@ -58,7 +67,7 @@ const root = ReactDOM.createRoot(document.getElementById("script-component"));
5867
root.render(
5968
<div data-theme="opensigncss">
6069
<Provider store={store}>
61-
<PublicScriptFileWrapper initialProps={{ text: "templateId" }} />
70+
<PublicScriptFileWrapper />
6271
</Provider>
6372
</div>
6473
);

0 commit comments

Comments
 (0)