Skip to content

Commit c46fa19

Browse files
Merge pull request #23 from OpenSignLabs/staging
update
2 parents f712532 + 2fa2f56 commit c46fa19

File tree

14 files changed

+161
-920
lines changed

14 files changed

+161
-920
lines changed

apps/OpenSign/src/components/LoginFacebook.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,15 @@ const LoginFacebook = ({
213213
type="button"
214214
onClick={() => handleSubmitbtn()}
215215
className="btn btn-info"
216+
style={{ marginRight: 10 }}
216217
>
217218
Sign up
218219
</button>
219220
<button
220221
type="button"
221222
className="btn btn-secondary"
222223
onClick={() => setIsModal(false)}
223-
style={{ marginRight: 10, width: 90 }}
224+
style={{ width: 90 }}
224225
>
225226
Cancel
226227
</button>

apps/OpenSign/src/components/LoginGoogle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,15 @@ const GoogleSignInBtn = ({
289289
type="button"
290290
className="bg-[#17a2b8] p-2 text-white rounded"
291291
onClick={() => handleSubmitbtn()}
292+
style={{ marginRight: 10 }}
292293
>
293294
Sign up
294295
</button>
295296
<button
296297
type="button"
297298
className="bg-[#6c757d] p-2 text-white rounded"
298299
onClick={handleCloseModal}
299-
style={{ marginRight: 10, width: 90 }}
300+
style={{ width: 90 }}
300301
>
301302
Cancel
302303
</button>

apps/OpenSign/src/components/dashboard/DashboardCard.js

Lines changed: 53 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import React, { useState, useEffect } from "react";
22
import axios from "axios";
33
import Parse from "parse";
4-
import onSearchFilter from "../../constant/searchQuery";
54
import getReplacedHashQuery from "../../constant/getReplacedHashQuery";
65
import "../../styles/loader.css";
76
import { useNavigate } from "react-router-dom";
@@ -45,12 +44,7 @@ const DashboardCard = (props) => {
4544
var reg = /(\#.*?\#)/gi; // eslint-disable-line
4645
var str = props.Data.query;
4746
var test = "";
48-
if (str.includes("#filterCondition#")) {
49-
str = str.replace(
50-
"#filterCondition#",
51-
onSearchFilter(props.DefaultQuery)
52-
);
53-
}
47+
5448
if (props.Data.extendkey) {
5549
let a = props.Data.extendkey.split(".");
5650
if (a.length > 0) {
@@ -105,13 +99,6 @@ const DashboardCard = (props) => {
10599
let data = JSON.parse(localStorage.getItem("Extand_Class"));
106100
resr = data[0];
107101
} else {
108-
// let emp = Parse.Object.extend(
109-
// localStorage.getItem("extended_class")
110-
// );
111-
// let q = new Parse.Query(emp);
112-
// q.equalTo("UserId", currentUser);
113-
// let t = await q.first();
114-
// resr = t.toJSON();
115102
resr = await Parse.Cloud.run("getUserDetails", {
116103
email: currentUser.get("email")
117104
});
@@ -149,47 +136,65 @@ const DashboardCard = (props) => {
149136
"X-Parse-Application-Id": parseAppId,
150137
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
151138
};
152-
await axios.get(url, { headers: headers }).then((res) => {
153-
if (res.data.results.length > 0) {
154-
setLoading(false);
155-
if (props.Data.key !== "count") {
156-
setresponse(res.data.results[0][props.Data.key]);
157-
} else {
158-
if (props.Label === "Need your Signature") {
159-
const listData = res.data?.results.filter(
160-
(x) => x.Signers.length > 0
139+
// handle need your sign report count
140+
if (props.Data.Redirect_id === "4Hhwbp482K") {
141+
const params = {
142+
reportId: props.Data.Redirect_id,
143+
skip: 0,
144+
limit: 200
145+
};
146+
const url = `${parseBaseUrl}/functions/getReport`;
147+
await axios
148+
.post(url, params, {
149+
headers: {
150+
"Content-Type": "application/json",
151+
"X-Parse-Application-Id": parseAppId,
152+
sessiontoken: localStorage.getItem("accesstoken")
153+
}
154+
})
155+
.then((res) => {
156+
const listData = res.data?.result.filter(
157+
(x) => x.Signers.length > 0
158+
);
159+
let arr = [];
160+
for (const obj of listData) {
161+
const isSigner = obj.Signers.some(
162+
(item) => item.UserId.objectId === currentUser.id
161163
);
162-
let arr = [];
163-
for (const obj of listData) {
164-
const isSigner = obj.Signers.some(
165-
(item) => item.UserId.objectId === currentUser.id
166-
);
167-
if (isSigner) {
168-
let isRecord;
169-
if (obj?.AuditTrail && obj?.AuditTrail.length > 0) {
170-
isRecord = obj?.AuditTrail.some(
171-
(item) =>
172-
item?.UserPtr?.UserId?.objectId === currentUser.id &&
173-
item.Activity === "Signed"
174-
);
175-
} else {
176-
isRecord = false;
177-
}
178-
if (isRecord === false) {
179-
arr.push(obj);
180-
}
164+
if (isSigner) {
165+
let isRecord;
166+
if (obj?.AuditTrail && obj?.AuditTrail.length > 0) {
167+
isRecord = obj?.AuditTrail.some(
168+
(item) =>
169+
item?.UserPtr?.UserId?.objectId === currentUser.id &&
170+
item.Activity === "Signed"
171+
);
172+
} else {
173+
isRecord = false;
174+
}
175+
if (isRecord === false) {
176+
arr.push(obj);
181177
}
182178
}
183-
setresponse(arr.length);
179+
}
180+
setresponse(arr.length);
181+
setLoading(false);
182+
});
183+
} else {
184+
await axios.get(url, { headers: headers }).then((res) => {
185+
if (res.data.results.length > 0) {
186+
setLoading(false);
187+
if (props.Data.key !== "count") {
188+
setresponse(res.data.results[0][props.Data.key]);
184189
} else {
185190
setresponse(res.data[props.Data.key]);
186191
}
192+
} else {
193+
setresponse(0);
194+
setLoading(false);
187195
}
188-
} else {
189-
setresponse(0);
190-
setLoading(false);
191-
}
192-
});
196+
});
197+
}
193198
} catch (e) {
194199
console.error("Problem", e);
195200
setLoading(false);
@@ -226,13 +231,6 @@ const DashboardCard = (props) => {
226231
let data = JSON.parse(localStorage.getItem("Extand_Class"));
227232
res = data[0];
228233
} else {
229-
// var emp = Parse.Object.extend(
230-
// localStorage.getItem("extended_class")
231-
// );
232-
// var q = new Parse.Query(emp);
233-
// q.equalTo("UserId", currentUser);
234-
// let resr = await q.first();
235-
// res = resr.toJSON();
236234
let resr = await Parse.Cloud.run("getUserDetails", {
237235
email: currentUser.get("email")
238236
});

apps/OpenSign/src/components/dashboard/DashboardReport.js

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,58 @@ function DashboardReport(props) {
99
const [isLoader, setIsLoader] = useState(true);
1010
const [reportName, setReportName] = useState("");
1111
const [actions, setActions] = useState([]);
12+
const [isNextRecord, setIsNextRecord] = useState(false);
13+
const [isMoreDocs, setIsMoreDocs] = useState(true);
14+
const abortController = new AbortController();
15+
const docPerPage = 5;
16+
1217
useEffect(() => {
1318
setReportName("");
1419
getReportData(props.Record.reportId);
20+
21+
// Function returned from useEffect is called on unmount
22+
return () => {
23+
setIsLoader(true);
24+
setList([]);
25+
setIsNextRecord(false);
26+
// Here it'll abort the fetch
27+
abortController.abort();
28+
};
29+
// eslint-disable-next-line
1530
}, [props.Record.reportId]);
1631

17-
const getReportData = async (id) => {
32+
// below useEffect call when isNextRecord state is true and fetch next record
33+
useEffect(() => {
34+
if (isNextRecord) {
35+
getReportData(props.Record.reportId, List.length, 200);
36+
}
37+
// eslint-disable-next-line
38+
}, [isNextRecord]);
39+
40+
const getReportData = async (id, skipUserRecord = 0, limit = 200) => {
1841
setIsLoader(true);
1942
const json = reportJson(id);
2043
if (json) {
2144
setActions(json.actions);
2245
setReportName(json.reportName);
23-
const { className, params, keys, orderBy } = json;
2446
Parse.serverURL = localStorage.getItem("BaseUrl12");
2547
Parse.initialize(localStorage.getItem("AppID12"));
26-
const serverURL =
27-
localStorage.getItem("BaseUrl12") + "classes/" + className;
48+
const currentUser = Parse.User.current().id;
2849

29-
const strParams = JSON.stringify(params);
30-
const strKeys = keys.join();
3150
const headers = {
3251
"Content-Type": "application/json",
3352
"X-Parse-Application-Id": localStorage.getItem("AppID12"),
34-
"X-Parse-Session-Token": localStorage.getItem("accesstoken")
53+
sessiontoken: localStorage.getItem("accesstoken")
3554
};
3655
try {
37-
const url = `${serverURL}?where=${strParams}&keys=${strKeys}&order=${orderBy}&include=AuditTrail.UserPtr`;
38-
const res = await axios.get(url, { headers: headers });
39-
// console.log("res ", res.data?.results);
56+
const params = { reportId: id, skip: skipUserRecord, limit: limit };
57+
const url = `${localStorage.getItem("BaseUrl12")}/functions/getReport`;
58+
const res = await axios.post(url, params, {
59+
headers: headers,
60+
signal: abortController.signal // is used to cancel fetch query
61+
});
4062
if (id === "5Go51Q7T8r") {
41-
const currentUser = Parse.User.current().id;
42-
const listData = res.data?.results.filter(
43-
(x) => x.Signers.length > 0
44-
);
63+
const listData = res.data?.result.filter((x) => x.Signers.length > 0);
4564
let arr = [];
4665
for (const obj of listData) {
4766
const isSigner = obj.Signers.some(
@@ -63,14 +82,34 @@ function DashboardReport(props) {
6382
}
6483
}
6584
}
66-
setList(arr);
85+
if (arr.length === docPerPage) {
86+
setIsMoreDocs(true);
87+
} else {
88+
setIsMoreDocs(false);
89+
}
90+
setList((prevRecord) =>
91+
prevRecord.length > 0 ? [...prevRecord, ...arr] : arr
92+
);
6793
} else {
68-
setList(res.data?.results);
94+
if (res.data.result.length === docPerPage) {
95+
setIsMoreDocs(true);
96+
} else {
97+
setIsMoreDocs(false);
98+
}
99+
setIsNextRecord(false);
100+
setList((prevRecord) =>
101+
prevRecord.length > 0
102+
? [...prevRecord, ...res.data.result]
103+
: res.data.result
104+
);
69105
}
70106
setIsLoader(false);
71107
} catch (err) {
72-
console.log("err ", err);
73-
setIsLoader(false);
108+
const isCancel = axios.isCancel(err);
109+
if (!isCancel) {
110+
console.log("err ", err);
111+
setIsLoader(false);
112+
}
74113
}
75114
} else {
76115
setIsLoader(false);
@@ -101,8 +140,10 @@ function DashboardReport(props) {
101140
<ReportTable
102141
ReportName={reportName}
103142
List={List}
104-
act={"Sign"}
105143
actions={actions}
144+
setIsNextRecord={setIsNextRecord}
145+
isMoreDocs={isMoreDocs}
146+
docPerPage={docPerPage}
106147
/>
107148
) : (
108149
<div className="flex items-center justify-center h-[100px] w-full bg-white rounded">

0 commit comments

Comments
 (0)