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