diff --git a/src/components/Organization/OrgUsers/OrgUsers.jsx b/src/components/Organization/OrgUsers/OrgUsers.jsx index 5850eb1e..11138ed8 100644 --- a/src/components/Organization/OrgUsers/OrgUsers.jsx +++ b/src/components/Organization/OrgUsers/OrgUsers.jsx @@ -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 ( + {show && } @@ -96,6 +103,7 @@ function Orgusers({ style={{ display: AddUser ? "flex" : "none" }} + onClick={showAddUserModal} > Add New diff --git a/src/components/Organization/OrgUsersCard/addOrgUserModal.jsx b/src/components/Organization/OrgUsersCard/addOrgUserModal.jsx index 376a863d..ab0333d2 100644 --- a/src/components/Organization/OrgUsersCard/addOrgUserModal.jsx +++ b/src/components/Organization/OrgUsersCard/addOrgUserModal.jsx @@ -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)}
Select user role diff --git a/src/components/Organization/ViewOrganization/index.jsx b/src/components/Organization/ViewOrganization/index.jsx index 10d6ddab..7892f61e 100644 --- a/src/components/Organization/ViewOrganization/index.jsx +++ b/src/components/Organization/ViewOrganization/index.jsx @@ -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( ({ diff --git a/src/components/Tutorials/NewTutorial/index.jsx b/src/components/Tutorials/NewTutorial/index.jsx index 8e3c92d8..f9eab6c6 100644 --- a/src/components/Tutorials/NewTutorial/index.jsx +++ b/src/components/Tutorials/NewTutorial/index.jsx @@ -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]); diff --git a/src/store/actions/authActions.js b/src/store/actions/authActions.js index 04b2f6a0..3889c227 100644 --- a/src/store/actions/authActions.js +++ b/src/store/actions/authActions.js @@ -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; } diff --git a/src/store/actions/orgActions.js b/src/store/actions/orgActions.js index 3a76f648..e4ee5d27 100644 --- a/src/store/actions/orgActions.js +++ b/src/store/actions/orgActions.js @@ -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);