diff options
author | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-03 16:31:36 -0400 |
---|---|---|
committer | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-03 16:31:36 -0400 |
commit | 37bad7137e3f64913705566f904938f98c4c88ef (patch) | |
tree | 002ae9e3f2959acebe224fe6c8e0d700b763e7a5 /src | |
parent | 9973b1d785c9d3c6c71ad149eb5ad5b65a6eb95d (diff) |
Allowd for account page to show correct division based on data in database.
Diffstat (limited to 'src')
-rw-r--r-- | src/actions/firebase.js | 21 | ||||
-rw-r--r-- | src/components/mao-account.js | 8 | ||||
-rw-r--r-- | src/reducers/firebase.js | 11 |
3 files changed, 28 insertions, 12 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js index 83aca5e..3ea710a 100644 --- a/src/actions/firebase.js +++ b/src/actions/firebase.js @@ -3,6 +3,8 @@ import { firebase, firestore } from '../firebase.js'; //Start Firbase Auth export const AUTH_FAIL = 'AUTH_FAIL'; export const AUTH_SUCCESS = 'AUTH_SUCCESS'; +export const FETCH_DIVISON = 'FETCH_DIVISON'; +export const UPDATE_DIVISON = 'UPDATE_DIVISON'; export const AUTH_SIGN_OUT = 'AUTH_SIGN_OUT'; export const CREATE_ACCOUNT = 'CREATE_ACCOUNT'; export const ADMIN_LISTENER = 'ADMIN_LISTENER'; @@ -40,6 +42,7 @@ export const signIn = (_email, _password, divison) => (dispatch) => { console.log(divison); dispatch(setUserData(divison)); } + dispatch(fetchDivison()); dispatch(snapshotHours()) dispatch(snapshotRegisteredCompetitions()); //Admin controls @@ -85,7 +88,6 @@ export const authFail = (errorCode) => { return { type: AUTH_FAIL, payload: false, - code: errorCode, uid: null } } @@ -95,12 +97,27 @@ export const authSuccess = (_user) => { return { type: AUTH_SUCCESS, payload: true, - code: "Success", uid: _user.uid, userEmail: _user.email } } +export const fetchDivison = () => (dispatch, getState) => { + const uid = getState().firebase.uid; + var docRef = firestore.collection('users').doc(uid); + + docRef.get().then((doc) => { + dispatch(updateDivison(doc.data().divison)); + }); +} + +export const updateDivison = (divison) => { + return { + type: UPDATE_DIVISON, + payload: divison + } +} + export const adminControls = () => (dispatch) => { dispatch(updateAdmin()); dispatch(snapshotAdminRequests()); diff --git a/src/components/mao-account.js b/src/components/mao-account.js index 7a654fd..e4a206e 100644 --- a/src/components/mao-account.js +++ b/src/components/mao-account.js @@ -103,7 +103,7 @@ class MaoAccount extends connect(store)(PageViewElement) { <p>${props.userEmail.replace("@communityschoolnaples.org", "")}</p> <h3>Divison</h3> - <p>Mu</p> + <p>${props.divison}</p> <h3 hidden="${props.registeredComps.length<1}">Registered Competitions</h3> <div id="competition-list"></div> @@ -149,15 +149,15 @@ class MaoAccount extends connect(store)(PageViewElement) { static get properties() { return { // This is the data from the store. signedIn: Boolean, - authMessage: String, userEmail: String, - registeredComps: Array + registeredComps: Array, + divison: String }} _stateChanged(state) { this.signedIn = state.firebase.initialized; - this.authMessage = state.firebase.authMessage; this.userEmail = state.firebase.userEmail; + this.divison = state.firebase.divison; this.registeredComps = state.firebase.registeredComps; this.createCompetitionList( this.registeredComps); diff --git a/src/reducers/firebase.js b/src/reducers/firebase.js index 5920910..773f874 100644 --- a/src/reducers/firebase.js +++ b/src/reducers/firebase.js @@ -9,9 +9,9 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN */ import { - AUTH_FAIL, AUTH_SUCCESS, AUTH_SIGN_OUT, + UPDATE_DIVISON, UPDATE_HOURS, UPDATE_REGISTERED_COMPETITIONS, UPDATE_FOURM_POSTS, @@ -21,23 +21,22 @@ import { } from '../actions/firebase.js'; -const firebase = (state = {initialized: false, authMessage: "", hours: -1, requestedHours: -1, uid: "", userEmail: "", registeredComps: [], fourmPosts: [], isAdmin: false, requests: [], compList: []}, action) => { +const firebase = (state = {initialized: false, hours: -1, requestedHours: -1, uid: "", userEmail: "", divison: "", registeredComps: [], fourmPosts: [], isAdmin: false, requests: [], compList: []}, action) => { switch (action.type) { case AUTH_SUCCESS: return { ...state, initialized: action.payload, - authMessage: action.code, uid: action.uid, userEmail: action.userEmail }; break; - case AUTH_FAIL: + case UPDATE_DIVISON: return { ...state, - authMessage: action.code - } + divison: action.payload + }; break; case AUTH_SIGN_OUT: |