aboutsummaryrefslogtreecommitdiff
path: root/src/components/request-element.js
blob: c2bfa349b82f7e8ed075e7b6e24528d26c83c7a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
@license
Copyright (c) 2018 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/

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/firebaseAdmin.js';

// Import button styles
import { ButtonSharedStyles } from './button-shared-styles.js';

// Import paper elements
import '@polymer/paper-card/paper-card.js';
import '@polymer/paper-button/paper-button.js';

class RequestElement extends connect(store)(LitElement) {
  _render(props) {
    return html`
      ${ButtonSharedStyles}

      <style>

        paper-card {
            --paper-card-background-color: #ffffff;
            width:      100%;
            text-align: center;
        }

        .info-tab > p {
          word-break: break-all;
        }

      </style>
      <paper-card
      onmouseover   ="${() => this.toggleTab()}"
      onmouseout    ="${() => this.toggleTab()}">
        <div class="card-content">
            <h3>From: ${'\t' + props.email.replace('@communityschoolnaples.org', '')}</h3>
            <h4>Date: ${'\t' + props.date}</h4>
            <div class="info-tab" hidden="${!props.infoTabOpen}">
              <p><em>Location:</em> ${'\t' + this.location   }</p>
              <p><em>Minutes: </em> ${'\t' + (this.time*60)  }</p>
              <p><em>Trainee: </em> ${'\t' +  this.trainee   }</p>
            </div>
        </div>
        <div hidden="${!props.infoTabOpen}" class="card-actions">
          <paper-button
          class="info"
          raised
          on-tap=   "${() => this.approveHours()}">
            Approve Time
          </paper-button>
          <paper-button
          class="alert"
          raised
          on-tap=   "${() => this.rejectHours()}">
            Reject Time
          </paper-button>
        </div>
      </paper-card>
    `;
  }

  static get properties() { return {
    email:    String,
    date:     String,
    location: String,
    time:     Number,
    trainee:  String,
    uid:      String,
    id:       String,

    infoTabOpen:  Boolean
  }};

  constructor() {
    super();

    this.email    = "Unknown email";
    this.date     = "Unknown date";
    this.location = "Unknown location";
    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*60) + ' minutes for ' + this.email +' ?')) {
      store.dispatch(adminApproveHours(this.uid, this.time, this.docId));
    }
  }

  rejectHours() {
    if(confirm('Are you sure you want to REJECT ' + (this.time*60) + ' minutes for ' + this.email +' ?')) {
      store.dispatch(adminRejectHours(this.docId));
    }
  }


}

window.customElements.define('request-element', RequestElement);