aboutsummaryrefslogtreecommitdiff
path: root/src/actions/firebaseFirestore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/firebaseFirestore.js')
-rw-r--r--src/actions/firebaseFirestore.js27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/actions/firebaseFirestore.js b/src/actions/firebaseFirestore.js
index 49e79c7..1e2296c 100644
--- a/src/actions/firebaseFirestore.js
+++ b/src/actions/firebaseFirestore.js
@@ -4,6 +4,7 @@ export const UPDATE_DIVISON = 'UPDATE_DIVISON';
export const UPDATE_HOURS = 'UPDATE_HOURS';
export const UPDATE_REGISTERED_COMPETITIONS = 'UPDATE_REGISTERED_COMPETITIONS';
export const UPDATE_FORUM_POSTS = 'UPDATE_FORUM_POSTS';
+export const UPDATE_NOTIFICATION = 'UPDATE_NOTIFICATION';
export const updateDivison = (divison) => {
return {
@@ -14,7 +15,7 @@ export const updateDivison = (divison) => {
export const updateHours = (hours, reqHours) => {
return {
- type: 'UPDATE_HOURS',
+ type: UPDATE_HOURS,
approvedHours: hours,
requestedHours: reqHours
}
@@ -34,6 +35,13 @@ export const updateForumPosts = (_forumPosts) => {
}
}
+export const updateNotification = (status) => {
+ return {
+ type: UPDATE_NOTIFICATION,
+ payload: status
+ }
+}
+
//Middleware to dispatches
export const fetchDivison = () => (dispatch, getState) => {
@@ -44,7 +52,6 @@ export const fetchDivison = () => (dispatch, getState) => {
});
}
-var isAdminUpdate = false;
export const snapshotHours = () => (dispatch, getState) => {
const currentAuthState = getState().firebaseAuth;
if(currentAuthState.signedIn) {
@@ -54,7 +61,7 @@ export const snapshotHours = () => (dispatch, getState) => {
docRefUsers.onSnapshot((doc) => {
totalHours = doc.data().hours;
docRefReq.onSnapshot((query) => {
- if(isAdminUpdate) {
+ if(getState().firebaseFirestore.isAdminUpdate) {
alert("One of your hours requests has been approved or denied.\nGo to dashboard to see changes.")
}
var requestedHours = 0;
@@ -62,7 +69,7 @@ export const snapshotHours = () => (dispatch, getState) => {
requestedHours += docs.data().time;
});
dispatch(updateHours(totalHours, requestedHours));
- isAdminUpdate = true;
+ dispatch(updateNotification(true));
});
});
}
@@ -95,11 +102,13 @@ export const snapshotForums = () => (dispatch) => {
//Do not dipatch to store, only update firebaseFirestore
export const setUserData = (_divison) => (dispatch, getState) => {
- const uid = getState().firebaseAuth.uid;
- var docRef = firestore.collection('users').doc(uid);
- docRef.set({
+ var _uid = getState().firebaseAuth.uid;
+ var username = getState().firebaseAuth.userEmail.replace('@communityschoolnaples.org', '');
+ firestore.collection('users').doc(_uid)
+ .set({
hours: 0,
- divison: _divison
+ divison: _divison,
+ username
}).catch((error) => {
console.log(error);
})
@@ -109,7 +118,7 @@ export const requestHours = (_time, _trainee, _location, _subject, _date, _pictu
if(getState().app.offline) {
alert("Failed to create forum post. Must have internet connection.")
} else {
- isAdminUpdate = false;
+ dispatch(updateNotification(false));
var docRef = firestore.collection('requests');
const _uid = getState().firebaseAuth.uid;
const _email = getState().firebaseAuth.userEmail;