diff options
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)); }); } |