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/actions | |
| 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/actions')
| -rw-r--r-- | src/actions/firebaseAdmin.js | 10 | ||||
| -rw-r--r-- | src/actions/firebaseAuth.js | 9 | ||||
| -rw-r--r-- | src/actions/firebaseFirestore.js | 27 |
3 files changed, 35 insertions, 11 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; |
