Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with fetching admin time #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aunt-leahs-app/src/pages/AdminShiftDataPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ const AdminShiftDataPage = () => {
})
}

await getAdminHistory();
await getShifts();

} catch (error) {
console.log('Error clearing shift data ' + error);
}
Expand Down Expand Up @@ -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);
}
Expand Down
64 changes: 31 additions & 33 deletions aunt-leahs-app/src/pages/AdminVolunteerDataPage.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -82,7 +82,9 @@ function AdminVolunteerDataPage({ setCurrentPage }) {
});
}

await getAdminHistory();
await getVolunteers();

} catch (error) {
console.log('Error clearing volunteer data ' + error);
}
Expand All @@ -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) {
Expand All @@ -106,40 +106,38 @@ function AdminVolunteerDataPage({ setCurrentPage }) {
}

return (
<AzureAD provider={authProvider} reduxStore={store} forceLogin={true}>
<div>
<AdminHeader />
<div>
<AdminHeader />
<div>
<div className='volunteer-data-table-body'>
<CustomTable data={volunteerData} />
<div className='volunteer-data-table-body'>
<CustomTable data={volunteerData} />
</div>
<div className='volunteer-data-bottom'>
<div className='lastModified'>
<p>Last cleared: {adminHistory ? adminHistory.lastClearedTime : 'Never'}</p>
<p>Last exported: {adminHistory ? adminHistory.lastExportedTime : 'Never'}</p>
</div>
<div className='volunteer-data-bottom'>
<div className='lastModified'>
<p>Last cleared: {adminHistory.lastClearedTime || 'Never'}</p>
<p>Last exported: {adminHistory.lastExportedTime || 'Never'}</p>
</div>
<div className='volunteer-data-buttons'>
<div className='export-btn'>
<CustomButton
size={'small'}
color={'primary'}
onClick={exportData}>
Export Data
<div className='volunteer-data-buttons'>
<div className='export-btn'>
<CustomButton
size={'small'}
color={'primary'}
onClick={exportData}>
Export Data
</CustomButton>
</div>
<div className='clearBtn'>
<CustomButton
size={'small'}
color={'secondary'}
onClick={clearData}>
Clear Data
</div>
<div className='clearBtn'>
<CustomButton
size={'small'}
color={'secondary'}
onClick={clearData}>
Clear Data
</CustomButton>
</div>
</div>
</div>
</div>
</div>
</AzureAD>
</div>
);
}

Expand Down