From 8a2960511c9a3f8a60bb12fe833f3c38fc8ebfab Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Tue, 2 Jul 2024 20:54:30 +0530 Subject: [PATCH] feat: add share with functionality of template --- apps/OpenSign/src/json/ReportJson.js | 8 ++ .../src/primitives/GetReportDisplay.js | 134 +++++++++++++++++- .../cloud/parsefunction/getReport.js | 43 +++++- .../cloud/parsefunction/reportsJson.js | 6 +- 4 files changed, 182 insertions(+), 9 deletions(-) diff --git a/apps/OpenSign/src/json/ReportJson.js b/apps/OpenSign/src/json/ReportJson.js index bd35f9312..a33990b46 100644 --- a/apps/OpenSign/src/json/ReportJson.js +++ b/apps/OpenSign/src/json/ReportJson.js @@ -346,6 +346,14 @@ export default function reportJson(id) { message: "This menu reveals more options such as Edit & Delete. Use the 'Edit' button to add signer roles, modify fields, and update your template. Changes will apply to all future documents created from this template but won’t affect existing documents.Use the Delete button you can delete template. ", subaction: [ + { + btnId: "1873", + btnLabel: "Share-with", + hoverLabel: "Share-with", + btnIcon: "fa-light fa-share-nodes", + redirectUrl: "", + action: "sharewith" + }, { btnId: "2434", btnLabel: "Edit", diff --git a/apps/OpenSign/src/primitives/GetReportDisplay.js b/apps/OpenSign/src/primitives/GetReportDisplay.js index 259bad27c..f8e40ac22 100644 --- a/apps/OpenSign/src/primitives/GetReportDisplay.js +++ b/apps/OpenSign/src/primitives/GetReportDisplay.js @@ -24,6 +24,7 @@ import ReactQuill from "react-quill"; import "react-quill/dist/quill.snow.css"; import BulkSendUi from "../components/BulkSendUi"; import Loader from "./Loader"; +import Select from "react-select"; const ReportTable = (props) => { const navigate = useNavigate(); @@ -52,6 +53,10 @@ const ReportTable = (props) => { const [templateDeatils, setTemplateDetails] = useState({}); const [placeholders, setPlaceholders] = useState([]); const [isLoader, setIsLoader] = useState({}); + const [isShareWith, setIsShareWith] = useState({}); + const [departmentList, setDepartmentList] = useState([]); + const [selectedDepartments, setSelectedDepartments] = useState([]); + const onChange = (selectedOptions) => setSelectedDepartments(selectedOptions); // const [selectedPublicRole, setSelectedPublicRole] = useState(""); // const [isCelebration, setIsCelebration] = useState(false); // const [currentLists, setCurrentLists] = useState([]); @@ -125,9 +130,37 @@ const ReportTable = (props) => { // below useEffect reset currenpage to 1 if user change route useEffect(() => { checkTourStatus(); + fetchDepartmentList(); return () => setCurrentPage(1); + // eslint-disable-next-line }, []); + // `fetchDepartmentList` is used to fetch department list for share with functionality + const fetchDepartmentList = async () => { + if (props.ReportName === "Templates") { + try { + const extUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0]; + const department = new Parse.Query("contracts_Departments"); + department.equalTo("OrganizationId", { + __type: "Pointer", + className: "contracts_Organizations", + objectId: extUser.OrganizationId.objectId + }); + department.equalTo("IsActive", true); + const departmentRes = await department.find(); + if (departmentRes.length > 0) { + const _departmentRes = JSON.parse(JSON.stringify(departmentRes)); + const formatedList = _departmentRes.map((x) => ({ + label: x.Name, + value: x.objectId + })); + setDepartmentList(formatedList); + } + } catch (err) { + console.log("Err in fetch top level departmentlist", err); + } + } + }; // `formatRow` is used to show data in poper manner like // if data is of array type then it will join array items with "," // if data is of object type then it Name values will be show in row @@ -297,6 +330,16 @@ const ReportTable = (props) => { setIsResendMail({ [item.objectId]: true }); } else if (act.action === "bulksend") { handleBulkSend(item); + } else if (act.action === "sharewith") { + if (item?.SharedWith && item?.SharedWith.length > 0) { + // below code is used to get existing sharewith departments and formated them as per react-select + const formatedList = item?.SharedWith.map((x) => ({ + label: x.Name, + value: x.objectId + })); + setSelectedDepartments(formatedList); + } + setIsShareWith({ [item.objectId]: true }); } }; // Get current list @@ -915,6 +958,41 @@ const ReportTable = (props) => { // setTimeout(() => setIsAlert(false), 1500); // }; + // `handleShareWith` is used to save departments in sharedWith field + const handleShareWith = async (e, template) => { + e.preventDefault(); + e.stopPropagation(); + setIsShareWith({}); + setActLoader({ [template.objectId]: true }); + try { + const templateCls = new Parse.Object("contracts_Template"); + templateCls.id = template.objectId; + const departmentArr = selectedDepartments.map((x) => ({ + __type: "Pointer", + className: "contracts_Departments", + objectId: x.value + })); + templateCls.set("SharedWith", departmentArr); + const res = await templateCls.save(); + if (res) { + setIsAlert(true); + setAlertMsg({ + type: "success", + message: "Template Shared successfully." + }); + } + } catch (err) { + setIsAlert(true); + setAlertMsg({ + type: "danger", + message: "Something went wrong, Please try again later." + }); + } finally { + setActLoader({}); + setTimeout(() => setIsAlert(false), 1500); + } + }; + return (
{Object.keys(actLoader)?.length > 0 && ( @@ -1276,7 +1354,7 @@ const ReportTable = (props) => { )} {isOption[item.objectId] && act.action === "option" && ( -
))} + {isShareWith[item.objectId] && ( +
+
+

+ Share with +

+
setIsShareWith({})} + > + ✕ +
+
handleShareWith(e, item)} + > +