From b4f34a54d9e9b0c182b829e17845fc1e4128d408 Mon Sep 17 00:00:00 2001 From: Thai Ngoc Nguyen Date: Sat, 4 Apr 2020 12:48:32 -0700 Subject: [PATCH] Fix bug with fetching admin time --- .../src/pages/AdminShiftDataPage.jsx | 4 +- .../src/pages/AdminVolunteerDataPage.jsx | 64 +++++++++---------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/aunt-leahs-app/src/pages/AdminShiftDataPage.jsx b/aunt-leahs-app/src/pages/AdminShiftDataPage.jsx index f590264..36cb8ce 100644 --- a/aunt-leahs-app/src/pages/AdminShiftDataPage.jsx +++ b/aunt-leahs-app/src/pages/AdminShiftDataPage.jsx @@ -77,7 +77,9 @@ const AdminShiftDataPage = () => { }) } + await getAdminHistory(); await getShifts(); + } catch (error) { console.log('Error clearing shift data ' + error); } @@ -108,7 +110,7 @@ const AdminShiftDataPage = () => { const response = await axios.get('http://localhost:7071/api/history?tableName=shift'); const adminHistory = { lastClearedTime: new Date(response.data.lastClearedTime).toDateString(), - lastExportedTime: new Date(response.data.lastClearedTime).toDateString() + lastExportedTime: new Date(response.data.lastExportedTime).toDateString() } setAdminHistory(adminHistory); } diff --git a/aunt-leahs-app/src/pages/AdminVolunteerDataPage.jsx b/aunt-leahs-app/src/pages/AdminVolunteerDataPage.jsx index b8253ff..c2cde90 100644 --- a/aunt-leahs-app/src/pages/AdminVolunteerDataPage.jsx +++ b/aunt-leahs-app/src/pages/AdminVolunteerDataPage.jsx @@ -1,7 +1,7 @@ import React, { useState, useEffect } from 'react'; import axios from 'axios'; import moment from 'moment'; -import { AzureAD, withAuthentication } from 'react-aad-msal'; +import { withAuthentication } from 'react-aad-msal'; import AdminHeader from '../components/AdminHeader'; import CustomTable from '../components/CustomTable'; @@ -10,9 +10,8 @@ import { ExportToCsv } from 'export-to-csv'; import { authProvider } from '../auth/authProvider'; import store from '../redux/store'; -function AdminVolunteerDataPage({ setCurrentPage }) { +function AdminVolunteerDataPage() { const [volunteerData, setVolunteerData] = useState(['']); - const [adminHistory, setAdminHistory] = useState({ lastClearedTime: null, lastExportedTime: null, @@ -36,9 +35,10 @@ function AdminVolunteerDataPage({ setCurrentPage }) { useKeysAsHeaders: true, // headers: ['Column 1', 'Column 2', etc...] <-- Won't work with useKeysAsHeaders present! }; + const csvExporter = new ExportToCsv(options); - const exportData = async () => { + async function exportData() { try { csvExporter.generateCsv(volunteerData); @@ -82,7 +82,9 @@ function AdminVolunteerDataPage({ setCurrentPage }) { }); } + await getAdminHistory(); await getVolunteers(); + } catch (error) { console.log('Error clearing volunteer data ' + error); } @@ -95,9 +97,7 @@ function AdminVolunteerDataPage({ setCurrentPage }) { ); const adminHistory = { lastClearedTime: new Date(response.data.lastClearedTime).toDateString(), - lastExportedTime: new Date( - response.data.lastClearedTime - ).toDateString(), + lastExportedTime: new Date(response.data.lastExportedTime).toDateString(), }; setAdminHistory(adminHistory); } catch (error) { @@ -106,40 +106,38 @@ function AdminVolunteerDataPage({ setCurrentPage }) { } return ( - +
+
- -
-
- +
+ +
+
+
+

Last cleared: {adminHistory ? adminHistory.lastClearedTime : 'Never'}

+

Last exported: {adminHistory ? adminHistory.lastExportedTime : 'Never'}

-
-
-

Last cleared: {adminHistory.lastClearedTime || 'Never'}

-

Last exported: {adminHistory.lastExportedTime || 'Never'}

-
-
-
- - Export Data +
+
+ + Export Data -
-
- - Clear Data +
+
+ + Clear Data -
- +
); }