Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
added user event sign on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
leandergangso committed May 8, 2022
1 parent b39ffd5 commit 878f7ee
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 14 deletions.
18 changes: 18 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ const REGION = 'europe-west1';
// on signup add to user.events - ok
exports.onSignup = functions.region(REGION).firestore.document('organizations/{orgID}/events/{eventID}/signup_list/{userID}').onCreate((snap, context) => {
const id = context.params.orgID + '/' + context.params.eventID;
// increment event signup counter
const eventRef = admin.firestore().collection('organizations').doc(context.params.orgID).collection('events').doc(context.params.eventID);
eventRef.get().then((doc) => {
curCount = doc.data().signup_count;
eventRef.update({
signup_count: curCount + 1
});
});
// add event to user event list
const userRef = admin.firestore().collection('users').doc(context.params.userID);
return userRef.get().then((doc) => {
let list = [];
Expand All @@ -38,6 +47,15 @@ exports.onSignup = functions.region(REGION).firestore.document('organizations/{o
exports.onSignoff = functions.region(REGION).firestore.document('organizations/{orgID}/events/{eventID}/signup_list/{userID}').onDelete((snap, context) => {
const id = context.params.orgID + '/' + context.params.eventID;
const userRef = admin.firestore().collection('users').doc(context.params.userID);
// decrement event signup counter
const eventRef = admin.firestore().collection('organizations').doc(context.params.orgID).collection('events').doc(context.params.eventID);
eventRef.get().then((doc) => {
curCount = doc.data().signup_count;
eventRef.update({
signup_count: curCount - 1
});
});
// remove event from user event list
return userRef.get().then((doc) => {
if (Array.isArray(doc.data().events)) {
let list = doc.data().events;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"axios": "^0.26.0",
"dotenv": "^16.0.0",
"firebase": "^9.6.6",
"firebase-functions": "^3.20.0",
"firebase-functions": "^3.21.0",
"framer-motion": "^6.2.3",
"react": "^17.0.2",
"react-beautiful-dnd": "^13.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Singelton/TheLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Layout() {

if (state.organizations.length === 0) {
sidebarNav = sidebarNav.filter(item => {
return ![4, 5].includes(item.id);
return ![3, 4, 5].includes(item.id);
});
}

Expand Down
13 changes: 10 additions & 3 deletions src/pages/Participant/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ const Event = () => {
const qrCode = urlID + '/' + state.user.id;

const signon = () => {
if (event.forms.length > 0) {
navigate('form');
}
// ! uncomment to use form on signup
// if (event.forms.length > 0) {
// navigate('form');
// }
const code = event.is_ticket ? qrCode : '';
eventSignup(state.user.id, orgID, eventID, code);

// local fast update
setEvent({ ...event, signup_count: event.signup_count + 1, });
};

const signoff = () => {
eventSignoff(state.user.id, orgID, eventID);

// local fast update
setEvent({ ...event, signup_count: event.signup_count - 1, });
};

useEffect(async () => {
Expand Down
2 changes: 0 additions & 2 deletions src/pages/Users/Index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useAppState } from "../../contexts/AppContext";
import { Link } from "react-router-dom";
// import { useEffect } from "react";

import Input from "../../components/Actions/Input";
import Button from "../../components/Actions/Button";
Expand Down Expand Up @@ -39,7 +38,6 @@ const Index = () => {
email: userData.email,
});
});
console.log("final:", newList[0].users);
setRoleList(newList);
}, []);

Expand Down
16 changes: 16 additions & 0 deletions src/pages/Users/components/UserRoleList.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
import { MdDelete, MdModeEdit } from 'react-icons/md';

const UserRoleList = ({ roleList, onClick }) => {

// ! demo data
roleList = [
{
role: "Administrator",
users: [{
name: "Demo user",
email: "[email protected]"
}],
},
{
role: "Medlem",
users: [],
}
];

return (
<div className="rounded-md shadow-sm border border-border bg-light max-h-[550px] md:h-full overflow-y-auto overflow-x-hidden">
{roleList.map(item => (
Expand Down

0 comments on commit 878f7ee

Please sign in to comment.