Skip to content

Commit

Permalink
merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
lsylcy0307 committed Apr 28, 2024
2 parents 0c047c9 + 9df4703 commit 4b234f1
Show file tree
Hide file tree
Showing 18 changed files with 1,333 additions and 300 deletions.
Binary file added .DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
"@emotion/styled": "^11.11.0",
"@material-ui/icons": "^4.11.2",
"@mui/icons-material": "^5.15.9",
"@mui/material": "^5.15.9",
"@mui/material": "^5.5.3",
"@mui/system": "^5.5.2",
"@mui/x-charts": "^6.19.4",
"@mui/x-date-pickers": "^6.19.6",
"@reduxjs/toolkit": "^1.8.1",
"axios": "^1.1.2",
"dayjs": "^1.11.10",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
5 changes: 5 additions & 0 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-named-as-default */
import React from 'react';
import { ThemeProvider } from '@mui/material/styles';
import { CssBaseline } from '@mui/material';
Expand Down Expand Up @@ -25,6 +26,8 @@ import InviteRegisterPage from './Authentication/InviteRegisterPage';
import DonorProfilePage from './donorProfile/DonorProfilePage';
import ReportsPage from './Reports/ReportsPage';
import HomeDashboardPage from './HomeDashboard/HomeDashboard';
import NewDonationPage from './NewDonation/NewDonationPage';
import DonationInfoPage from './DonationInfo/DonationInfoPage';

function App() {
return (
Expand All @@ -36,6 +39,7 @@ function App() {
<CssBaseline>
<AlertPopup />
<Routes>
<Route path="/new-donation" element={<NewDonationPage />} />
{/* Routes accessed only if user is not authenticated */}
<Route element={<UnauthenticatedRoutesWrapper />}>
<Route path="/login" element={<LoginPage />} />
Expand Down Expand Up @@ -67,6 +71,7 @@ function App() {
<Route element={<ProtectedRoutesWrapper />}>
<Route path="/home" element={<HomePage />} />
</Route>
<Route path="/donationInfo" element={<DonationInfoPage />} />
<Route element={<AdminRoutesWrapper />}>
<Route path="/users" element={<AdminDashboardPage />} />
</Route>
Expand Down
165 changes: 165 additions & 0 deletions client/src/DonationInfo/DonationInfoPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
/* eslint-disable react-hooks/exhaustive-deps */
import React, { useEffect, useState } from 'react';
import {
Typography,
Box,
Button,
TableContainer,
Paper,
Table,
TableBody,
TableRow,
TableCell,
} from '@mui/material';
import { useNavigate } from 'react-router-dom';
import axios from 'axios';
import { useData } from '../util/api';
import { useAppDispatch } from '../util/redux/hooks';

function BasicTable({
customRows,
}: {
customRows: { label: string; value: string }[];
}) {
return (
<Box
border="none"
borderRadius={4}
p={2}
sx={{ width: 'min(500px, 100%)' }}
>
<TableContainer component={Paper}>
<Table sx={{ minWidth: 300 }} aria-label="simple table">
<TableBody>
{customRows.map((row) => (
<TableRow key={row.label}>
<TableCell component="th" scope="row">
{row.label}
</TableCell>
<TableCell align="right">{row.value}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
</Box>
);
}

function DonationInfoPage() {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const [donationData, setDonationData] = useState<any>([]);
const [customRows, setCustomRows] = useState<
{ label: string; value: string }[]
>([]);
const [donorName, setDonorName] = useState('');
const [purpose, setPurpose] = useState('');

// Fetch donation data from API
const donationID = '65daa89e6c34e8adb9f2d2c7';
const donation = useData(`donation/${donationID}`);

useEffect(() => {
const fetchDonorAndPurpose = async () => {
if (donation?.data) {
setDonationData(donation.data);
if (donation.data.donor_id) {
try {
const res = await axios.get(
`http://localhost:4000/api/donor/${donation.data.donor_id}`,
);
setDonorName(res.data.contact_name);
} catch (error) {
console.error('Failed to fetch donor name:', error);
}
}

if (donation.data.purpose_id) {
try {
const res = await axios.get(
`http://localhost:4000/api/purpose/${donation.data.purpose_id}`,
);
setPurpose(res.data.name);
} catch (error) {
console.error('Failed to fetch donor name:', error);
}
}
}
};

fetchDonorAndPurpose();
}, [donation?.data]);

function formatDateString(dateString: string): string {
if (dateString) {
const date = new Date(dateString);
const formattedDate = date.toISOString().slice(0, 10);
return formattedDate;
}
return '';
}

function setTableWithDonation() {
if (donationData) {
const updatedCustomRows = [
{
label: 'Donation Amount',
value: `$ ${donationData.amount}` || 'N/A',
},
{
label: 'Date Donated',
value: formatDateString(donationData.date) || 'N/A',
},
{ label: 'Donor', value: donorName || 'N/A' },
{
label: 'Payment Information',
value: donationData.payment_type || 'N/A',
},
{ label: 'Campaign Category', value: purpose || 'N/A' },
{
label: 'Acknowledged?',
value: donationData.acknowledged ? 'Yes' : 'No',
},
];
setCustomRows(updatedCustomRows);
}
}

useEffect(() => {
setTableWithDonation();
}, [donationData, donorName, purpose, setTableWithDonation]);

return (
<Box display="flex" flexDirection="column" alignItems="flex-start">
<Box
display="flex"
flexDirection="row"
alignItems="center"
marginBottom={2}
marginLeft={2}
>
<Typography variant="h5" gutterBottom>
Donation Information
</Typography>
</Box>

{/* Render the BasicTable component with the updated customRows data */}
<BasicTable customRows={customRows} />

{!donationData.acknowledged && (
<p style={{ marginTop: '16px', marginLeft: '16px' }}>
This donation has not been acknowledged.
</p>
)}
<Button
onClick={() => navigate('/home')}
style={{ marginLeft: '16px', background: 'blue', color: 'white' }}
>
Send them a message now
</Button>
</Box>
);
}

export default DonationInfoPage;
Loading

0 comments on commit 4b234f1

Please sign in to comment.