diff options
author | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-01 20:46:52 -0400 |
---|---|---|
committer | Michael Foiani <mfoiani2019@communiyschoolnaples.org> | 2018-08-01 20:46:52 -0400 |
commit | 32fed7906a39e4bfa4d98fee1bdc5340d22cb63f (patch) | |
tree | 719f7bd92384927a0a6b994f67f020541be68723 /src/actions/firebase.js | |
parent | 7070c6f28d0e1fb6b519b44a83314c4bdb7a004d (diff) |
Fixed small glitch where snapshot would fire twice because the field in the database was called 'date.' Annoying. Also, fixed other bugs and finished the admin requests viewing, but need to connect the 'approve hours button.'
Diffstat (limited to 'src/actions/firebase.js')
-rw-r--r-- | src/actions/firebase.js | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js index 8dea81b..631599f 100644 --- a/src/actions/firebase.js +++ b/src/actions/firebase.js @@ -88,6 +88,8 @@ export const authSuccess = (_user) => { export const adminControls = () => (dispatch) => { dispatch(updateAdmin()); + dispatch(snapshotAdminRequests()); + dispatch(snapshotAdminCompList()); } export const updateAdmin = () => { @@ -193,6 +195,14 @@ export const snapshotRegisteredCompetitions = () => (dispatch, getState) => { }); } + +export const updateRegisteredCompetitions = (registeredComps) => { + return { + type: UPDATE_REGISTERED_COMPETITIONS, + payload: registeredComps + } +} + export const snapshotAdminCompList = () => (dispatch) => { var docRef = firestore.collection('competitions'); docRef.onSnapshot((querySnapshot) => { @@ -204,26 +214,26 @@ export const snapshotAdminCompList = () => (dispatch) => { }); } -export const updateRegisteredCompetitions = (registeredComps) => { +export const updateAdminCompList = (compList) => { return { - type: UPDATE_REGISTERED_COMPETITIONS, - payload: registeredComps + type: UPDATE_ADMIN_COMP_LIST, + payload: compList } } -export const REQUEST_HOURS = 'REQUEST_HOURS'; -export const FETCH_ADMIN_REQUESTS = 'FETCH_ADMIN_REQUESTS'; -export const UPDATE_ADMIN_REQUESTS = 'UPDATE_ADMIN_REQUESTS'; +export const REQUEST_HOURS = 'REQUEST_HOURS'; +export const SNAPSHOT_ADMIN_REQUESTS = 'SNAPSHOT_ADMIN_REQUESTS'; +export const UPDATE_ADMIN_REQUESTS = 'UPDATE_ADMIN_REQUESTS'; export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => { var docRef = firestore.collection('requests'); const _uid = getState().firebase.uid; - const _email = getState().firebase.email; + const _email = getState().firebase.userEmail; docRef.add({ time: _time, trainee: _trainee, - date: _date, + day: _date, uid: _uid, email: _email }); @@ -240,16 +250,15 @@ export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => }); } -export const fetchAdminRequests = () => (dispatch) => { +export const snapshotAdminRequests = () => (dispatch) => { var docRef = firestore.collection('requests'); - docRef.onSnapshot((query) => { - var requests = []; - query.forEach((doc) => { - requests.push(doc.data()); + docRef.onSnapshot((querySnapshot) => { + var requestList = []; + querySnapshot.forEach((doc) => { + requestList.push(doc.data()); }); - - dispatch(fetchAdminRequests(requests)); + dispatch(updateAdminRequests(requestList)); }); } |