Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Fix : Implemented The Option to Add&Remove Editor (1), Admins (2), Reviewers (0) to Organization ] #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[ Fix : Implemented The Option to Add&Remove Editor (1), Admins (2), …
…Reviewers (0) to Organization ]
rohitPandey469 committed Feb 22, 2025
commit bd5c5a5018ad608440f1542bb04957168486d3e0
8 changes: 8 additions & 0 deletions src/components/Organization/OrgUsers/OrgUsers.jsx
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ import { makeStyles } from "@mui/styles";
import React from "react";
import AddIcon from "@mui/icons-material/Add";
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
import OrgUsersCard from "../OrgUsersCard/orgUsersCard";

const useStyles = makeStyles(theme => ({
root: {
@@ -67,8 +68,14 @@ function Orgusers({
dataTestId
}) {
const classes = useStyles();
const [show, isShow] = React.useState(false);
const showAddUserModal = e => {
e.preventDefault();
isShow(true);
};
return (
<React.Fragment>
{show && <OrgUsersCard />}
<Paper elevation={0} className={classes.root} data-testid={dataTestId}>
<Grid container className={classes.gridPadding}>
<Grid container direction="row">
@@ -96,6 +103,7 @@ function Orgusers({
style={{
display: AddUser ? "flex" : "none"
}}
onClick={showAddUserModal}
>
<AddIcon />
Add New
17 changes: 11 additions & 6 deletions src/components/Organization/OrgUsersCard/addOrgUserModal.jsx
Original file line number Diff line number Diff line change
@@ -39,10 +39,16 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {

useEffect(() => {
setUsers([]);
firebase.ref(`cl_user_handle/`).on("value", snapshot => {
snapshot.forEach(snap => {
setUsers(prev => [...prev, { title: snap.key, value: snap.key }]);
const db = firebase.firestore();
db.collection("cl_user").onSnapshot(snapshot => {
const uniqueHandles = new Set();
snapshot.forEach(doc => {
const handle = doc.data().handle;
const userId = doc.id;
uniqueHandles.add({ title: handle, value: userId });
});
const uniqueUsers = Array.from(uniqueHandles);
setUsers(uniqueUsers);
});
}, [firebase]);

@@ -104,7 +110,7 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {
org_handle: currentOrgHandle,
permissions: parseInt(selected.split("_")[1]),
handle: handle
})(firestore, dispatch);
})(firestore, firebase, dispatch);
}
};

@@ -119,7 +125,7 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {
variant="outlined"
id="Search"
autoComplete="off"
onChange={e => setHandle(e.target.innerHTML)}
onChange={(event, value) => setHandle(value.value)}
helperText={handleValidateError ? handleValidateErrorMessage : null}
options={users}
getOptionLabel={option => option.title}
@@ -135,7 +141,6 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {
/>
)}
/>
{console.log(users)}
<Grid container justify="flex-end">
<div style={{ padding: "10px" }}>
<span style={{ paddingRight: "10px" }}>Select user role</span>
15 changes: 8 additions & 7 deletions src/components/Organization/ViewOrganization/index.jsx
Original file line number Diff line number Diff line change
@@ -124,6 +124,7 @@ const ViewOrganization = () => {
});
}, [db, profileData.uid]);

const [currentOrgData, setCurrentOrgData] = useState(CurrentOrg);
const handleOrgSubscription = async () => {
if (!currentOrgData.userSubscription)
await subscribeOrg(handle)(firebase, firestore, dispatch);
@@ -138,13 +139,13 @@ const ViewOrganization = () => {
}) => loading
);

const currentOrgData = useSelector(
({
org: {
data: { data }
}
}) => data
);
// const currentOrgData = useSelector(
// ({
// org: {
// data: { data }
// }
// }) => data
// );

const organizations = useSelector(
({
8 changes: 4 additions & 4 deletions src/components/Tutorials/NewTutorial/index.jsx
Original file line number Diff line number Diff line change
@@ -96,17 +96,17 @@ const NewTutorial = ({ viewModal, onSidebarClick, viewCallback, active }) => {
}));
}, [tags]);

const organizations = useSelector(
const {organizations, isEmpty} = useSelector(
({
profile: {
data: { organizations }
data: { organizations, isEmpty }
}
}) => organizations
}) => ({ organizations, isEmpty })
);
// console.log("organizations", organizations);

useEffect(() => {
if (!organizations) {
if (!organizations && !isEmpty) {
getProfileData()(firebase, firestore, dispatch);
}
}, [firestore, firebase, dispatch, organizations]);
10 changes: 6 additions & 4 deletions src/store/actions/authActions.js
Original file line number Diff line number Diff line change
@@ -194,10 +194,12 @@ export const resendVerifyEmail = email => async dispatch => {
*/
export const checkUserHandleExists = userHandle => async firebase => {
try {
const handle = await firebase
.ref(`/cl_user_handle/${userHandle}`)
.once("value");
return handle.exists();
const userSnapshot = await firebase
.firestore()
.collection("cl_user")
.doc(userHandle)
.get();
return userSnapshot.exists;
} catch (e) {
throw e.message;
}
15 changes: 9 additions & 6 deletions src/store/actions/orgActions.js
Original file line number Diff line number Diff line change
@@ -46,22 +46,25 @@ export const getOrgUserData = org_handle => async (firestore, dispatch) => {
// adds a user to organization's users list with a set of permissions
export const addOrgUser =
({ org_handle, handle, permissions }) =>
async (firestore, dispatch) => {
async (firestore, firebase, dispatch) => {
try {
dispatch({ type: actions.ADD_ORG_USER_START });
const userDoc = await firestore
const userDoc = await firebase
.firestore()
.collection("cl_user")
.where("handle", "==", handle)
.doc(handle)
.get();
if (userDoc.docs.length === 1) {
const uid = userDoc.docs[0].get("uid");

if (userDoc.exists) {
const userData = userDoc.data();
const uid = userData.uid;
await firestore
.collection("org_users")
.doc(`${org_handle}_${uid}`)
.set({
uid: uid,
org_handle: org_handle,
permissions: permissions
permissions: [permissions]
});

await getOrgUserData(org_handle)(firestore, dispatch);