aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/actions/firebase.js43
-rw-r--r--src/components/button-shared-styles.js4
-rw-r--r--src/components/mao-admin.js1
-rw-r--r--src/components/request-element.js38
4 files changed, 79 insertions, 7 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';
diff --git a/src/components/button-shared-styles.js b/src/components/button-shared-styles.js
index 5f426a4..eb03eef 100644
--- a/src/components/button-shared-styles.js
+++ b/src/components/button-shared-styles.js
@@ -34,5 +34,9 @@ export const ButtonSharedStyles = html`
paper-button.success {
background-color: #b7e1cd;
}
+
+ paper-button.alert {
+ background-color: #db4437;
+ }
</style>
`;
diff --git a/src/components/mao-admin.js b/src/components/mao-admin.js
index 4d8b28e..dc78616 100644
--- a/src/components/mao-admin.js
+++ b/src/components/mao-admin.js
@@ -170,6 +170,7 @@ class MaoAdmin extends connect(store)(PageViewElement) {
requestElement.time = this.requests[i].time;
requestElement.trainee = this.requests[i].trainee;
requestElement.uid = this.requests[i].uid;
+ requestElement.docId = this.requests[i].docId;
requestGrid.appendChild(requestElement);
}
diff --git a/src/components/request-element.js b/src/components/request-element.js
index 0e65d0d..164dc3e 100644
--- a/src/components/request-element.js
+++ b/src/components/request-element.js
@@ -9,6 +9,20 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
import { LitElement, html } from '@polymer/lit-element';
+import { connect } from 'pwa-helpers/connect-mixin.js';
+
+// This element is connected to the Redux store.
+import { store } from '../store.js';
+
+//These are the actions needed by this element.
+import { adminApproveHours, adminRejectHours } from '../actions/firebase.js';
+
+// We are lazy loading its reducer.
+import firebase from '../reducers/firebase.js';
+
+store.addReducers({
+ firebase
+});
// Import button styles
import { ButtonSharedStyles } from './button-shared-styles.js';
@@ -17,7 +31,7 @@ import { ButtonSharedStyles } from './button-shared-styles.js';
import '@polymer/paper-card/paper-card.js';
import '@polymer/paper-button/paper-button.js';
-class RequestElement extends LitElement {
+class RequestElement extends connect(store)(LitElement) {
_render(props) {
return html`
${ButtonSharedStyles}
@@ -53,6 +67,12 @@ class RequestElement extends LitElement {
on-tap= "${() => this.approveHours()}">
Approve Hours
</paper-button>
+ <paper-button
+ class="alert"
+ raised
+ on-tap= "${() => this.rejectHours()}">
+ Reject Hours
+ </paper-button>
</div>
</paper-card>
`;
@@ -64,6 +84,7 @@ class RequestElement extends LitElement {
time: Number,
trainee: String,
uid: String,
+ id: String,
infoTabOpen: Boolean
}};
@@ -76,17 +97,28 @@ class RequestElement extends LitElement {
this.time = -1;
this.trainee = "Unknown trainee";
this.uid = "Unknown uid";
+ this.docId = "Unknown docId";
this.infoTabOpen = false;
}
+ _stateChanged(state) {
+ //lmao just need this here for the memes
+ }
+
toggleTab() {
this.infoTabOpen = !this.infoTabOpen;
}
approveHours() {
- if(confirm('Are you sure you want to approve ' + this.time + ' hours for ' + this.email +' ?')) {
- this.dispatchEvent(new CustomEvent('approve-hours'));
+ if(confirm('Are you sure you want to APPROVE ' + this.time + ' hours for ' + this.email +' ?')) {
+ store.dispatch(adminApproveHours(this.uid, this.time, this.docId));
+ }
+ }
+
+ rejectHours() {
+ if(confirm('Are you sure you want to REJECT ' + this.time + ' hours for ' + this.email +' ?')) {
+ store.dispatch(adminRejectHours(this.docId));
}
}