diff --git a/packages/api/admin.js b/packages/api/admin.js index 6262ca7..94176f5 100644 --- a/packages/api/admin.js +++ b/packages/api/admin.js @@ -706,6 +706,46 @@ deleteEventTemplate = function(req, res) { }) } +getVolunteerHistory = async function(req, res) { + try { + let response_data = [] + client = this.dbClient + collection = client.db('events-form').collection('events') + let cursor = collection.aggregate([ + {$match: {'categories.submissions.volunteer_email': req.body.email}}, + {$unwind: '$categories'}, + {$match: {'categories.submissions.volunteer_email': req.body.email}}, + {$unwind: '$categories.submissions'}, + {$match: {'categories.submissions.volunteer_email': req.body.email}} + ]) + + while(await cursor.hasNext()) { + let doc = await cursor.next() + response_data.push({ + date: doc.date, + name: doc.categories.submissions.volunteer_name, + email: doc.categories.submissions.volunteer_email, + type: doc.categories.name, + desc: doc.categories.submissions.description, + servings: doc.categories.submissions.servings, + vegan: doc.categories.submissions.vegan, + vegetarian: doc.categories.submissions.vegetarian, + gluten_free: doc.categories.submissions.gluten_free + }) + } + + res.send({ + sub_info: response_data, + status: 'SUCCESS' + }) + } catch (err) { + console.log('Error retrieving volunteer history', err) + res.send({ + status: 'FAILURE' + }) + } +} + module.exports.addPhotos = addPhotos module.exports.removePhotos = removePhotos module.exports.removeImagesFromFrontPage = removeImagesFromFrontPage @@ -726,4 +766,5 @@ module.exports.editEventTemplate = editEventTemplate module.exports.getEventTemplate = getEventTemplate module.exports.deleteEventTemplate = deleteEventTemplate module.exports.editedStory = editedStory -module.exports.getStoryCount = getStoryCount \ No newline at end of file +module.exports.getStoryCount = getStoryCount +module.exports.getVolunteerHistory = getVolunteerHistory diff --git a/packages/api/server.js b/packages/api/server.js index ccb5468..b11d50e 100644 --- a/packages/api/server.js +++ b/packages/api/server.js @@ -140,4 +140,5 @@ app.get('/api/getEventTemplate', ensureAuthenticated, adminHandlers.getEventTemp app.post('/api/editEventTemplate', ensureAuthenticated, adminHandlers.editEventTemplate.bind({dbClient: client})) app.post('/api/deleteEventTemplate', ensureAuthenticated, adminHandlers.deleteEventTemplate.bind({dbClient: client})) app.post('/api/editedStory', ensureAuthenticated, adminHandlers.editedStory.bind({dbClient: client})) -app.get('/api/storiesCount', ensureAuthenticated, adminHandlers.getStoryCount.bind({dbClient: client})) \ No newline at end of file +app.get('/api/storiesCount', ensureAuthenticated, adminHandlers.getStoryCount.bind({dbClient: client})) +app.post('/api/volunteerHistory', ensureAuthenticated, adminHandlers.getVolunteerHistory.bind({dbClient: client})) diff --git a/packages/ui/src/Components/Dashboard/VolunteerList.js b/packages/ui/src/Components/Dashboard/VolunteerList.js index 1f40b3a..18213f1 100644 --- a/packages/ui/src/Components/Dashboard/VolunteerList.js +++ b/packages/ui/src/Components/Dashboard/VolunteerList.js @@ -72,7 +72,7 @@ class VolunteerList extends Component { as={Link} to="/VolunteerSubmissions" onClick={() => { - this.props.updateActiveEmail(item.name) + this.props.updateActiveEmail(item.email) }} className="volunteer" > diff --git a/packages/ui/src/Components/Dashboard/VolunteerSubmissions.js b/packages/ui/src/Components/Dashboard/VolunteerSubmissions.js index 0342b48..3c7515c 100644 --- a/packages/ui/src/Components/Dashboard/VolunteerSubmissions.js +++ b/packages/ui/src/Components/Dashboard/VolunteerSubmissions.js @@ -1,26 +1,41 @@ import React, { Component } from 'react' import { Header, Icon, Table } from 'semantic-ui-react' +import Axios from 'axios' +import moment from 'moment' class VolunteerSubmissions extends Component { constructor(props) { super(props) this.state = { - submissions: [ - { - date: '06-10-19', - name: 'Pablo Escobar', - email: 'pablito@gmail.com', - type: 'Main', - desc: 'Pizza', - servings: 100, - vegan: false, - vegetarian: false, - gluten_free: true - } - ] + submissions: [] } } + componentDidMount() { + Axios.post('/api/volunteerHistory', {email: this.props.email}) + .then(res => { + let tempSubs = res.data.sub_info + + tempSubs.forEach(e => { + e.sortDate = moment(e.date, 'MM-DD-YY') + }) + + tempSubs.sort((older, newer) => { + if(moment(older.sortDate).isBefore(moment(newer.sortDate))) { + return 1 + } else { + return -1 + } + }) + + this.setState({ + submissions: tempSubs + }) + }).catch(err => { + console.log('Error retrieving volunteer history', err) + }) + } + renderIcon = value => { if (value) { return @@ -30,9 +45,89 @@ class VolunteerSubmissions extends Component { } render() { + let stats = { + name: null, + events: 0, + categories: [], + avg_servings: 0, + vegan_pct: 0.0, + vegetarian_pct: 0.0, + gf_pct: 0.0, + counts: {} + } + + this.state.submissions.forEach(e => { + if(!stats.name) { + stats.name = e.name + } + stats.events++ + stats.avg_servings += e.servings + if(e.vegan) { + stats.vegan_pct++ + } + if(e.vegetarian) { + stats.vegetarian_pct++ + } + if(e.gluten_free) { + stats.gf_pct++ + } + if(!stats.categories.includes(e.type)) { + stats.categories.push(e.type) + stats.counts[e.type] = 1 + } else { + stats.counts[e.type]++ + } + }) + + stats.avg_servings = stats.avg_servings / this.state.submissions.length + stats.vegan_pct = 100 * (stats.vegan_pct / this.state.submissions.length) + stats.vegetarian_pct = 100* (stats.vegetarian_pct / this.state.submissions.length) + stats.gf_pct = 100 * (stats.gf_pct / this.state.submissions.length) + + stats.categories.sort((a, b) => { + return stats.counts[b] - stats.counts[a] + }) + + return (
-
Pablo Escobar
+
{stats.name}
+
+
Stats
+ + + + Total Events + Top 3 Categories + Avgerage Servings + % Vegan + % Vegetarian + % Gluten-Free + + + + {stats.events > 0 && + + {stats.events} + +
    + {stats.categories[0] &&
  1. {stats.categories[0]}
  2. } + {stats.categories[1] &&
  3. {stats.categories[1]}
  4. } + {stats.categories[2] &&
  5. {stats.categories[2]}
  6. } +
+
+ {stats.avg_servings} + {stats.vegan_pct} + {stats.vegetarian_pct} + {stats.gf_pct} +
+ } +
+
+
+
+
+
Signup History
@@ -68,6 +163,7 @@ class VolunteerSubmissions extends Component { ))}
+
) } diff --git a/packages/ui/src/Components/Stylesheets/EventTemplate.css b/packages/ui/src/Components/Stylesheets/EventTemplate.css index f915e40..0b3dac7 100644 --- a/packages/ui/src/Components/Stylesheets/EventTemplate.css +++ b/packages/ui/src/Components/Stylesheets/EventTemplate.css @@ -1,10 +1,10 @@ .input-wrapper span{ - visibility: hidden; + /* visibility: hidden; */ color: #008000; } .input-wrapper.has-error span{ - visibility: visible; + /* visibility: visible; */ color: #FF0000; }