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 ] #77

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/components/Organization/OrgUsers/OrgUsers.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -96,6 +103,7 @@ function Orgusers({
style={{
display: AddUser ? "flex" : "none"
}}
onClick={showAddUserModal}
>
<AddIcon />
Add New
Expand Down
25 changes: 15 additions & 10 deletions src/components/Organization/OrgUsersCard/addOrgUserModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down Expand Up @@ -74,10 +80,7 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {
}, [userProps]);

const onFinish = async () => {
const handleExists = await checkUserHandleExists(handle)(
firebase,
dispatch
);
const handleExists = await checkUserHandleExists(handle)(firebase);

if (handle.length < 1) {
setHandleValidateError(true);
Expand Down Expand Up @@ -107,7 +110,7 @@ const AddOrgUserModal = ({ currentOrgHandle }) => {
org_handle: currentOrgHandle,
permissions: parseInt(selected.split("_")[1]),
handle: handle
})(firestore, dispatch);
})(firestore, firebase, dispatch);
}
};

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

const [currentOrgData, setCurrentOrgData] = useState(CurrentOrg);

const handleOrgSubscription = async () => {
if (!currentOrgData.userSubscription)
await subscribeOrg(handle)(firebase, firestore, dispatch);
Expand All @@ -138,13 +140,13 @@ const ViewOrganization = () => {
}) => loading
);

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

const organizations = useSelector(
({
Expand Down
10 changes: 6 additions & 4 deletions src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,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;
}
Expand Down
17 changes: 10 additions & 7 deletions src/store/actions/orgActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -73,7 +76,7 @@ export const addOrgUser =
});
}
} catch (e) {
console.log(e);
console.error("Error adding org user:", e);
dispatch({ type: actions.ADD_ORG_USER_FAIL, payload: e.message });
}
};
Expand Down
Loading