Skip to content

Commit 5a6437e

Browse files
Merge pull request #1116 from OpenSignLabs/validation
fix: all contacts are not visible in request sign form's signers inputbox
2 parents b298571 + 4ffc98b commit 5a6437e

File tree

1 file changed

+46
-38
lines changed

1 file changed

+46
-38
lines changed

apps/OpenSign/src/components/shared/fields/SignersInput.js

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from "react";
2-
import Select from "react-select";
2+
import AsyncSelect from "react-select/async";
33
import AddSigner from "../../AddSigner";
44
import Parse from "parse";
55
import Tooltip from "../../../primitives/Tooltip";
@@ -35,7 +35,6 @@ const AddSignerModal = ({ isOpen, children }) => {
3535
const SignersInput = (props) => {
3636
const { t } = useTranslation();
3737
const [state, setState] = useState(undefined);
38-
// const [editFormData, setEditFormData] = useState([]);
3938
const [selected, setSelected] = useState([]);
4039
const [isModal, setIsModel] = useState(false);
4140
const onChange = (selectedOptions) => setSelected(selectedOptions);
@@ -46,40 +45,6 @@ const SignersInput = (props) => {
4645
setSelected(newValue);
4746
};
4847

49-
const GetSelectListData = async () => {
50-
try {
51-
const currentUser = Parse.User.current();
52-
const contactbook = new Parse.Query("contracts_Contactbook");
53-
contactbook.equalTo(
54-
"CreatedBy",
55-
Parse.User.createWithoutData(currentUser.id)
56-
);
57-
contactbook.notEqualTo("IsDeleted", true);
58-
const contactRes = await contactbook.find();
59-
if (contactRes) {
60-
const res = JSON.parse(JSON.stringify(contactRes));
61-
let list = [];
62-
63-
// let _selected = [];
64-
res.forEach((x) => {
65-
let obj = {
66-
label: x.Name,
67-
value: x.objectId,
68-
isChecked: true
69-
};
70-
71-
list.push(obj);
72-
});
73-
setState(list);
74-
}
75-
} catch (error) {
76-
console.log("err", error);
77-
}
78-
};
79-
80-
useEffect(() => {
81-
GetSelectListData();
82-
}, []);
8348
useEffect(() => {
8449
if (props.isReset && props.isReset === true) {
8550
setSelected([]);
@@ -118,7 +83,46 @@ const SignersInput = (props) => {
11883
setSelected([data]);
11984
}
12085
};
121-
86+
const loadOptions = async (inputValue) => {
87+
try {
88+
const currentUser = Parse.User.current();
89+
const contactbook = new Parse.Query("contracts_Contactbook");
90+
contactbook.equalTo(
91+
"CreatedBy",
92+
Parse.User.createWithoutData(currentUser.id)
93+
);
94+
if (inputValue.length > 1) {
95+
contactbook.matches("Name", new RegExp(inputValue, "i"));
96+
}
97+
contactbook.notEqualTo("IsDeleted", true);
98+
const contactRes = await contactbook.find();
99+
if (contactRes) {
100+
const res = JSON.parse(JSON.stringify(contactRes));
101+
//compareArrays is a function where compare between two array (total signersList and dcument signers list)
102+
//and filter signers from total signer's list which already present in document's signers list
103+
const compareArrays = (res, signerObj) => {
104+
return res.filter(
105+
(item1) =>
106+
!signerObj.find((item2) => item2.objectId === item1.objectId)
107+
);
108+
};
109+
110+
//get update signer's List if signersdata is present
111+
const updateSignersList =
112+
props?.signersData && compareArrays(res, props?.signersData);
113+
114+
const result = updateSignersList ? updateSignersList : res;
115+
setState(result);
116+
return await result.map((item) => ({
117+
label: item.Name,
118+
value: item.objectId,
119+
isChecked: true
120+
}));
121+
}
122+
} catch (error) {
123+
console.log("err", error);
124+
}
125+
};
122126
return (
123127
<div className="text-xs mt-2 ">
124128
<label className="block relative">
@@ -130,16 +134,20 @@ const SignersInput = (props) => {
130134
</label>
131135
<div className="flex gap-x-[5px]">
132136
<div className="w-full">
133-
<Select
137+
<AsyncSelect
134138
onSortEnd={onSortEnd}
135139
distance={4}
136140
isMulti
141+
cacheOptions
142+
defaultOptions
137143
options={state || []}
138144
value={selected}
139145
onChange={onChange}
140146
closeMenuOnSelect={false}
141147
required={props.required}
148+
loadingMessage={() => t("loading")}
142149
noOptionsMessage={() => t("contact-not-found")}
150+
loadOptions={loadOptions}
143151
unstyled
144152
classNames={{
145153
control: () =>

0 commit comments

Comments
 (0)