diff options
author | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-09-15 17:41:31 -0400 |
---|---|---|
committer | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-09-15 17:41:31 -0400 |
commit | fc6efa43834795e4736734bf6abf24ddeacfca00 (patch) | |
tree | 369e481c8e265acf065c0e652a0c932b043d144e /src | |
parent | 7073f6545544277673c0806606834225907797d7 (diff) |
Created way to update accounts with username. On signin, it updates the account. Also made some changed to admin console.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/firebaseAdmin.js | 10 | ||||
-rw-r--r-- | src/actions/firebaseAuth.js | 9 | ||||
-rw-r--r-- | src/actions/firebaseFirestore.js | 27 | ||||
-rw-r--r-- | src/components/mao-admin.js | 11 | ||||
-rw-r--r-- | src/reducers/firebaseFirestore.js | 12 |
5 files changed, 50 insertions, 19 deletions
diff --git a/src/actions/firebaseAdmin.js b/src/actions/firebaseAdmin.js index 6009d46..0171fc3 100644 --- a/src/actions/firebaseAdmin.js +++ b/src/actions/firebaseAdmin.js @@ -144,3 +144,13 @@ export const adminApproveHours = (_uid, _time, _id, _path) => (dispatch) => { }); dispatch(adminDeleteRequest(_id, _path)); } + +export const updateUserName = () => (dispatch, getState) => { + var username = getState().firebaseAuth.userEmail.replace('@communityschoolnaples.org', ''); + firestore.collection('users').doc(getState().firebaseAuth.uid) + .update({ + username + }).catch((error) => { + alert(error); + }); +}
\ No newline at end of file diff --git a/src/actions/firebaseAuth.js b/src/actions/firebaseAuth.js index 37f6643..82afc1a 100644 --- a/src/actions/firebaseAuth.js +++ b/src/actions/firebaseAuth.js @@ -48,12 +48,14 @@ import { setUserData, fetchDivison, snapshotHours, - snapshotRegisteredCompetitions + snapshotRegisteredCompetitions, + updateNotification } from './firebaseFirestore.js'; import { adminListener, - adminClose + adminClose, + updateUserName } from './firebaseAdmin.js' export const signIn = (_email, _password, divison) => (dispatch) => { @@ -70,6 +72,8 @@ export const signIn = (_email, _password, divison) => (dispatch) => { */ dispatch(authSuccess(user)); if(divison) { dispatch(setUserData(divison)); } + dispatch(updateNotification(false)); + dispatch(updateUserName()); dispatch(fetchDivison()); dispatch(snapshotHours()) dispatch(snapshotRegisteredCompetitions()); @@ -89,6 +93,7 @@ export const signIn = (_email, _password, divison) => (dispatch) => { export const signOut = () => (dispatch) => { auth.signOut().then(() => { + dispatch(updateNotification(false)); dispatch(authSignOut()); dispatch(adminClose()); }); 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; diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js index be04fb2..0e8825e 100644 --- a/src/components/mao-admin.js +++ b/src/components/mao-admin.js @@ -52,11 +52,10 @@ class MaoAdmin extends connect(store)(PageViewElement) { grid-template-columns: 1fr; } - tbody { - text-aliign: center; + td { + text-align: center; } - @media (min-width: 460px) { .main-grid { grid-template-columns: 1fr 1fr 1fr; @@ -102,7 +101,7 @@ class MaoAdmin extends connect(store)(PageViewElement) { </div> <section hidden="${!props.isAdmin || props.usersHidden}"> - <table> + <table style="width: 100%;"> <thead> <tr> <th>Username</th> @@ -233,7 +232,7 @@ class MaoAdmin extends connect(store)(PageViewElement) { var tableRow = document.createElement('tr'); var userEle = document.createElement('td'); - userEle.innerHTML = "Username"; + userEle.innerHTML = user['username'] ? user['username'] : "Unknown"; var hoursEle = document.createElement('td'); @@ -244,7 +243,7 @@ class MaoAdmin extends connect(store)(PageViewElement) { } else if (user['hours'] < 5.0) { - hoursEle.style.color = 'yellow'; + hoursEle.style.color = '#f09300'; } else { diff --git a/src/reducers/firebaseFirestore.js b/src/reducers/firebaseFirestore.js index 43b5f87..8ea946f 100644 --- a/src/reducers/firebaseFirestore.js +++ b/src/reducers/firebaseFirestore.js @@ -12,11 +12,12 @@ import { UPDATE_DIVISON, UPDATE_HOURS, UPDATE_REGISTERED_COMPETITIONS, - UPDATE_FORUM_POSTS + UPDATE_FORUM_POSTS, + UPDATE_NOTIFICATION } from '../actions/firebaseFirestore.js'; -const firebaseFirestore = (state = {hours: -1, requestedHours: -1, registeredComps: [], forumPosts: []}, action) => { +const firebaseFirestore = (state = {hours: -1, requestedHours: -1, registeredComps: [], forumPosts: [], isAdminUpdate: false}, action) => { switch (action.type) { case UPDATE_DIVISON: @@ -48,6 +49,13 @@ const firebaseFirestore = (state = {hours: -1, requestedHours: -1, registeredCom } break; + case UPDATE_NOTIFICATION: + return { + ...state, + isAdminUpdate : action.payload + } + break; + default: return state; } |