Merge pull request #964 from OpenSignLabs/multiuser_issue

This commit is contained in:
Amol
2024-07-23 19:44:46 +05:30
committed by GitHub
14 changed files with 422 additions and 120 deletions
File diff suppressed because one or more lines are too long
+33 -69
View File
@@ -17,15 +17,8 @@ const AddTeam = (props) => {
const getTeamList = async () => {
setIsLoader(true);
try {
const extUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
const teamCls = new Parse.Query("contracts_Teams");
teamCls.equalTo("OrganizationId", {
__type: "Pointer",
className: "contracts_Organizations",
objectId: extUser.OrganizationId.objectId
});
teamCls.equalTo("IsActive", true);
const teamRes = await teamCls.find();
const teams = await Parse.Cloud.run("getteams");
const teamRes = JSON.parse(JSON.stringify(teams));
if (teamRes.length > 0) {
const _teamRes = JSON.parse(JSON.stringify(teamRes));
const allUsersteam = _teamRes.find((x) => x.Name === "All Users");
@@ -73,76 +66,47 @@ const AddTeam = (props) => {
}
}
try {
const localUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
setIsLoader(true);
const team = new Parse.Query("contracts_Teams");
team.equalTo("Name", formdata.name);
let data = { Name: formdata.name };
if (updatedAncestors.length > 0) {
const ParentId = updatedAncestors[updatedAncestors.length - 1];
team.equalTo("ParentId", ParentId);
data["ParentId"] = ParentId?.objectId;
data["Ancestors"] = updatedAncestors;
}
if (localUser && localUser.OrganizationId) {
team.equalTo("OrganizationId", {
__type: "Pointer",
className: "contracts_Organizations",
objectId: localUser.OrganizationId.objectId
const newTeamRes = await Parse.Cloud.run("addteam", data);
// console.log("teamRes ", newTeamRes);
if (updatedAncestors.length > 0) {
const ParentId = teamList.find((x) => x.objectId === formdata.team);
props.handleTeamInfo({
objectId: newTeamRes.id,
Name: formdata.name,
ParentId: ParentId,
Ancestors: updatedAncestors,
IsActive: true
});
}
const isTeam = await team.first();
if (isTeam) {
props.setIsAlert({ type: "info", msg: "Teams already exists." });
setIsLoader(false);
} else {
const newTeam = new Parse.Object("contracts_Teams");
newTeam.set("Name", formdata.name);
if (updatedAncestors.length > 0) {
const ParentId = updatedAncestors[updatedAncestors.length - 1];
newTeam.set("ParentId", ParentId);
newTeam.set("Ancestors", updatedAncestors);
}
if (localUser && localUser.OrganizationId) {
newTeam.set("OrganizationId", {
__type: "Pointer",
className: "contracts_Organizations",
objectId: localUser.OrganizationId.objectId
});
}
newTeam.set("IsActive", true);
const newTeamRes = await newTeam.save();
if (updatedAncestors.length > 0) {
const ParentId = teamList.find((x) => x.objectId === formdata.team);
props.handleTeamInfo({
objectId: newTeamRes.id,
Name: formdata.name,
ParentId: ParentId,
Ancestors: updatedAncestors,
IsActive: true
});
} else {
props.handleTeamInfo({
objectId: newTeamRes.id,
Name: formdata.name,
ParentId: "",
Ancestors: "",
IsActive: true
});
}
if (props.closePopup) {
props.closePopup();
}
setFormdata({
name: "",
team: { name: "", objectId: "" }
});
props.setIsAlert({
type: "success",
msg: "Team created successfully."
props.handleTeamInfo({
objectId: newTeamRes.id,
Name: formdata.name,
ParentId: "",
Ancestors: "",
IsActive: true
});
}
if (props.closePopup) {
props.closePopup();
}
setFormdata({ name: "", team: { name: "", objectId: "" } });
props.setIsAlert({ type: "success", msg: "Team created successfully." });
} catch (err) {
console.log("err in save team", err);
props.setIsAlert({ type: "danger", msg: "Something went wrong." });
if (err.code === 137) {
props.setIsAlert({ type: "danger", msg: "Teams already exists." });
} else if (err.code === 102) {
props.setIsAlert({ type: "warning", msg: "Provide team name." });
} else {
props.setIsAlert({ type: "danger", msg: "Something went wrong." });
}
} finally {
setTimeout(() => props.setIsAlert({ type: "success", msg: "" }), 1500);
setIsLoader(false);
+7 -7
View File
@@ -3,10 +3,10 @@ export const templateCls = "contracts_Template";
export const documentCls = "contracts_Document";
export const themeColor = "#47a3ad";
export const iconColor = "#686968";
export const isEnableSubscription =
process.env.REACT_APP_ENABLE_SUBSCRIPTION &&
process.env.REACT_APP_ENABLE_SUBSCRIPTION?.toLowerCase() === "true"
? true
: false;
export const isStaging =
window.location.origin === "https://staging-app.opensignlabs.com";
export const isEnableSubscription = true;
// process.env.REACT_APP_ENABLE_SUBSCRIPTION &&
// process.env.REACT_APP_ENABLE_SUBSCRIPTION?.toLowerCase() === "true"
// ? true
// : false;
export const isStaging = "http://localhost:3001";
// window.location.origin === "https://staging-app.opensignlabs.com";
+11 -18
View File
@@ -113,16 +113,9 @@ const TeamList = () => {
: false;
setIsAdmin(admin);
}
const teamCls = new Parse.Query("contracts_Teams");
teamCls.equalTo("OrganizationId", {
__type: "Pointer",
className: "contracts_Organizations",
objectId: extUser.OrganizationId.objectId
});
teamCls.descending("createdAt");
const teamRes = await teamCls.find();
if (teamRes.length > 0) {
const _teamRes = JSON.parse(JSON.stringify(teamRes));
const teams = await Parse.Cloud.run("getteams");
if (teams.length > 0) {
const _teamRes = JSON.parse(JSON.stringify(teams));
setTeamList(_teamRes);
}
} catch (err) {
@@ -169,10 +162,11 @@ const TeamList = () => {
newArray[index] = { ...newArray[index], IsActive: !IsActive };
setTeamList(newArray);
try {
const teamCls = new Parse.Object("contracts_Teams");
teamCls.id = team.objectId;
teamCls.set("IsActive", !IsActive);
await teamCls.save();
await Parse.Cloud.run("updateteam", {
IsActive: !IsActive,
TeamId: team.objectId
});
// console.log("teamRes ", teamRes);
setIsAlert({
type: !IsActive === false ? "danger" : "success",
msg: !IsActive === false ? "Team disabled." : "Team enabled."
@@ -203,10 +197,9 @@ const TeamList = () => {
setIsActLoader({ [team.objectId]: true });
setIsEditModal({});
try {
const teamCls = new Parse.Object("contracts_Teams");
teamCls.id = team?.objectId;
teamCls.set("Name", team.Name);
await teamCls.save();
const data = { Name: team.Name, TeamId: team.objectId };
await Parse.Cloud.run("updateteam", data);
// console.log("updateTeamRes ", updateTeamRes);
setIsAlert({ type: "success", msg: "Team Update successfully." });
} catch (Err) {
console.log("Err in update team name"), Err;
@@ -145,14 +145,7 @@ const ReportTable = (props) => {
try {
const extUser = JSON.parse(localStorage.getItem("Extand_Class"))?.[0];
if (extUser?.OrganizationId?.objectId) {
const team = new Parse.Query("contracts_Teams");
team.equalTo("OrganizationId", {
__type: "Pointer",
className: "contracts_Organizations",
objectId: extUser.OrganizationId.objectId
});
team.notEqualTo("IsActive", false);
const teamtRes = await team.find();
const teamtRes = await Parse.Cloud.run("getteams");
if (teamtRes.length > 0) {
const _teamRes = JSON.parse(JSON.stringify(teamtRes));
const formatedList = _teamRes.map((x) => ({