diff options
Diffstat (limited to 'src/actions/firebase.js')
-rw-r--r-- | src/actions/firebase.js | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js index 5f24170..8e440eb 100644 --- a/src/actions/firebase.js +++ b/src/actions/firebase.js @@ -12,7 +12,7 @@ export const UPDATE_ADMIN = 'UPDATE_ADMIN'; const auth = firebase.auth(); -export const createAccount = (_email, _password) => (dispatch) => { +export const createAccount = (_email, _password, divison) => (dispatch) => { var authTrue = false; firebase.auth().createUserWithEmailAndPassword(_email, _password).then(() => { dispatch(signIn(_email, _password)); @@ -231,6 +231,9 @@ export const updateAdminCompList = (compList) => { } export const REQUEST_HOURS = 'REQUEST_HOURS'; +export const ADMIN_APPROVE_HOURS = 'ADMIN_APPROVE_HOURS'; +export const ADMIN_REJECT_HOURS = 'ADMIN_REJECT_HOURS'; +export const ADMIN_DELETE_REQUEST = 'ADMIN_DELETE_REQUEST'; export const SNAPSHOT_ADMIN_REQUESTS = 'SNAPSHOT_ADMIN_REQUESTS'; export const UPDATE_ADMIN_REQUESTS = 'UPDATE_ADMIN_REQUESTS'; @@ -252,8 +255,7 @@ export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => docRef.get().then((doc) => { if(doc.exists) { docRef.set({ - hours: doc.data().hours, - requestedHours: doc.data().requestedHours + _time + hours: doc.data().hours }); } }); @@ -265,7 +267,10 @@ export const snapshotAdminRequests = () => (dispatch) => { docRef.onSnapshot((querySnapshot) => { var requestList = []; querySnapshot.forEach((doc) => { - requestList.push(doc.data()); + requestList.push({ + ...doc.data(), + docId: doc.id + }); }); dispatch(updateAdminRequests(requestList)); }); @@ -278,6 +283,36 @@ export const updateAdminRequests = (requests) => { } } +export const adminApproveHours = (_uid, _time, _id) => (dispatch) => { + + var docRef = firestore.collection('users').doc(_uid); + var currentApprHours = 0; + + docRef.get().then((doc) => { + if(doc.exists) { + currentApprHours = doc.data().hours; + } + }); + + docRef.update({ + hours: (currentApprHours + _time) + }); + + dispatch(adminDeleteRequest(_id)); +} + +export const adminRejectHours = (_id) => (dispatch) => { + dispatch(adminDeleteRequest(_id)); +} + +export const adminDeleteRequest = (_id) => (dispatch) => { + var docRef = firestore.collection('requests').doc(_id); + docRef.delete().then(() => { + console.log('Deleted request with id ' + _id); + }); +} + + export const CREATE_FOURM_POST = 'CREATE_FOURM_POST'; export const SNAPSHOT_FOURM = 'SNAPSHOT_FOURM'; export const UPDATE_FOURM_POSTS = 'UPDATE_FOURM_POSTS'; |