Skip to content

Commit

Permalink
Merge pull request #850 from shivareddy6/refactor/userOrgDatabaseDesign
Browse files Browse the repository at this point in the history
Refactor/user org database design
  • Loading branch information
ABHISHEK-PANDEY2 committed Aug 17, 2023
2 parents cd67173 + aaa331e commit 0ceb7f0
Show file tree
Hide file tree
Showing 17 changed files with 605 additions and 513 deletions.
16 changes: 7 additions & 9 deletions functions/cloud_functions/onCreateFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,17 @@ exports.createOrganizationHandler = async (snapshot, context) => {
});

/**
* create org_users sub-collection => set user uid and respective permissions
* create org_users collection => set user uid and respective permissions
* @type {Promise<FirebaseFirestore.WriteResult>}
*/
const setOrgUsers = db
.collection("cl_org_general")
.doc(org_handle)
.collection("cl_org_users")
.doc("users")
.collection("org_users")
.doc(`${org_handle}_${user_uid}`)
.set({
[user_uid]: [3],
createdAt: admin.firestore.FieldValue.serverTimestamp(),
updatedAt: admin.firestore.FieldValue.serverTimestamp()
});
uid: user_uid,
org_handle,
permissions: [3]
})

await Promise.all([registerOrgHandle, setOrgMetrics, setOrgUsers]);
return console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ const App = () => {
return <Routes />;
};

export default App;
export default App;
2 changes: 1 addition & 1 deletion src/components/NavBar/new/MainNavbar/RightMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const RightMenu = ({ mode, onClick }) => {
}) => organizations
);

console.log("Nav Orgs", organizations);
// console.log("Nav Orgs", organizations);

const allowOrgs = organizations && organizations.length > 0;

Expand Down
72 changes: 27 additions & 45 deletions src/components/Organization/ViewOrganization/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useParams } from "react-router-dom";
import {
clearOrgData,
getOrgData,
addFollower,
removeFollower
subscribeOrg,
unSubscribeOrg
} from "../../../store/actions";
import Banner from "../../ProfileBanner/Organization";
import { Container } from "@mui/material";
Expand Down Expand Up @@ -107,49 +107,29 @@ const ViewOrganization = () => {
];

useEffect(() => {
const unsubscribe = db
.collection("cl_org_general")
.doc(handle)
.onSnapshot(snap => {
const data = snap.data();
setPeople(data.followers);
db.collection("org_subscribers")
.where("org_handle", "==", handle)
.get()
.then(querySnapshot => {
setPeople(querySnapshot.forEach(doc => doc.data()))
});

return () => unsubscribe();
}, [db, handle]);

useEffect(() => {
const unsubscribe = db
.collection("cl_user")
.doc(profileData.uid)
.onSnapshot(snap => {
const data = snap.data();
setOrgFollowed(data.orgFollowed);
db.collection("org_subscribers")
.where("uid", "==", profileData.uid)
.get()
.then(querySnapshot => {
setOrgFollowed(querySnapshot.forEach(doc => doc.data()))
});

return () => unsubscribe();
}, [db, profileData.uid]);

const addfollower = (e, people, handle, orgFollowed) => {
e.preventDefault();
addFollower(
profileData.handle,
people,
handle,
orgFollowed,
profileData.uid
)(firestore, dispatch);
};
const removefollower = (e, val, people, handle, orgFollowed) => {
e.preventDefault();
removeFollower(
val,
people,
handle,
orgFollowed,
profileData.uid
)(firestore, dispatch);
};
const handleOrgSubscription = async () => {
if (!currentOrgData.userSubscription)
await subscribeOrg(handle)(firebase, firestore, dispatch);
else
await unSubscribeOrg(handle)(firebase, firestore, dispatch);
}

const loading = useSelector(
({
Expand Down Expand Up @@ -205,16 +185,18 @@ const ViewOrganization = () => {
<React.Fragment>
<Banner
bannerImage="https://i.postimg.cc/zXvv1vwL/Org-Banner-Demo.png"
contributors={402}
feed={40}
followers={402}
name={CurrentOrg.org_name}
contributors={currentOrgData.contributorsCount}
feed={currentOrgData.feedCount}
followers={currentOrgData.followerCount}
name={currentOrgData.org_name}
profileImage={
CurrentOrg.org_image ? CurrentOrg.org_image : NoImage
currentOrgData.org_image ? currentOrgData.org_image : NoImage
}
story="Think Different"
handle={handle}
isOrgBelongsToUser={organizations.includes(handle)}
isUserSubscribed={currentOrgData.userSubscription}
handleOrgSubscription={handleOrgSubscription}
/>
<Container
maxWidth="xl"
Expand Down Expand Up @@ -273,13 +255,13 @@ const ViewOrganization = () => {
<Grid item>
<Description
Heading={"Description"}
Content={CurrentOrg.org_description}
Content={currentOrgData.org_description}
/>
</Grid>
<Grid item>
<Description
Heading={"CodeLabz you may like"}
Content={CurrentOrg.org_description}
Content={currentOrgData.org_description}
/>
</Grid>
<Grid item>
Expand Down
Loading

0 comments on commit 0ceb7f0

Please sign in to comment.