Skip to content

Commit

Permalink
Merge pull request #15 from hack4impact-upenn/task27
Browse files Browse the repository at this point in the history
Task 27 Email Unack. Popup
  • Loading branch information
Pulkith authored Apr 30, 2024
2 parents eb05132 + 37eddc2 commit dfd903b
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 2 deletions.
84 changes: 82 additions & 2 deletions client/src/Communications/CommunicationsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/* eslint-disable consistent-return */
/* eslint-disable react-hooks/rules-of-hooks */
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable no-empty */
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable no-underscore-dangle */
Expand Down Expand Up @@ -30,6 +35,25 @@ import IDonor from '../util/types/donor';
import IGroup from '../util/types/group';
import { useData } from '../util/api';

const BACKENDURL = process.env.PUBLIC_URL
? process.env.PUBLIC_URL
: 'http://localhost:4000';

const modalStyle = {
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
maxWidth: '80%',
maxHeight: '80%',
overflow: 'auto',
width: 600, // Adjust width as needed
bgcolor: 'background.paper',
border: '2px solid #000',
boxShadow: 24,
p: 4,
};

const testDonors = [
{
_id: '65daa67d6c34e8adb9f2d2c4',
Expand Down Expand Up @@ -113,7 +137,48 @@ type RowItem = {

function CommunicationsPage() {
const [unackDonoModalOpen, setUnackDonoModalOpen] = React.useState(false);
const handleUnackDonoModalOpen = () => setUnackDonoModalOpen(true);
const [unacknowledgedDonations, setUnacknowledgedDonations] = useState<any[]>(
[],
);

const handleUnackDonoModalOpen = async () => {
try {
console.log('opened');
const allDonationsResponse = await axios.get(
`${BACKENDURL}/api/donation/all`,
);
if (!allDonationsResponse) {
return;
}
const allDonations = allDonationsResponse.data;
console.log('here');
console.log(allDonations);
const temp = allDonations.filter(
(donation: any) => !donation.acknowledged,
);
const tempWithDonorInfo = await Promise.all(
temp.map(async (donation: any) => {
const donorInfoResponse = await axios.get(
`${BACKENDURL}/api/donor/id/${donation.donor_id}`,
);
console.log(donorInfoResponse);
if (!donorInfoResponse) {
return;
}
const donorInfo = donorInfoResponse.data;
return {
...donation,
donorName: donorInfo.contact_name,
donorEmail: donorInfo.contact_email,
};
}),
);
setUnacknowledgedDonations(tempWithDonorInfo);
} catch (error) {
console.log(error);
}
setUnackDonoModalOpen(true);
};
const handleUnackDonoModalClose = () => setUnackDonoModalOpen(false);
const [groupSearchValue, setGroupSearchValue] = useState(null);

Expand Down Expand Up @@ -398,10 +463,25 @@ function CommunicationsPage() {
aria-labelledby="Email Unacknowledged Donations Modal"
aria-describedby="Email Unacknowledged Donations Modal"
>
<Box sx={style}>
<Box sx={modalStyle}>
<Typography variant="h6" component="h2">
Email Unacknowledged Donations
</Typography>
{unacknowledgedDonations.map((donation) => (
<Box key={donation._id} sx={{ border: 1, p: 2, my: 1 }}>
<Typography variant="body1">
Donation ID: {donation._id}
</Typography>
<Typography variant="body1">Amount: {donation.amount}</Typography>
<Typography variant="body1">Date: {donation.date}</Typography>
<Typography variant="body1">
Donor Name: {donation.donorName}
</Typography>
<Typography variant="body1">
Donor Email: {donation.donorEmail}
</Typography>
</Box>
))}
<Button onClick={handleUnackDonoModalClose}>Close</Button>
</Box>
</Modal>
Expand Down
4 changes: 4 additions & 0 deletions server/src/routes/donor.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ router.get('/all', getAllDonorsController);

router.get('/:id', isAuthenticated, getDonorByIdController);


// router.get('/id/:id', isAuthenticated, getDonorByIdController);
router.get('/id/:id', getDonorByIdController);

router.get('/type/:type', isAuthenticated, getAllDonorsOfType);

router.get('type/:type', isAuthenticated, getAllDonorsOfType);
Expand Down

0 comments on commit dfd903b

Please sign in to comment.