Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
carolineychen8 committed Apr 14, 2024
1 parent 575b418 commit b2cbddb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
8 changes: 4 additions & 4 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ function App() {
<Route path="/users" element={<AdminDashboardPage />} />
</Route>
<Route path="/reports" element={<ReportsPage />} />
<Route
path="/communications"
element={<CommunicationsPage />}
/>
<Route
path="/communications"
element={<CommunicationsPage />}
/>
{/* <Route element={<ReportsPage />}>
<Route path="/reports" element={<ReportsPage />} />
</Route> */}
Expand Down
46 changes: 28 additions & 18 deletions client/src/Communications/CommunicationsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable react/jsx-props-no-spreading */
/* eslint-disable no-underscore-dangle */
/* eslint-disable no-alert */
Expand Down Expand Up @@ -146,17 +147,17 @@ function CommunicationsPage() {
value: { name: string; id: string | { $oid: string } } | null,
) => {
if (value) {
setRows([]);
// setRows([]);
const selectedPerson = donors.find(
(person) => extractId(person._id) === value.id,
);
if (selectedPerson) {
// const existingRow = rows.find(
// (row) => row.id === extractId(selectedPerson._id),
// );
// if (existingRow) {
// return;
// }
const existingRow = rows.find(
(row) => row.id === extractId(selectedPerson._id),
);
if (existingRow) {
return;
}
const newItem: RowItem = {
id: extractId(selectedPerson._id),
contact_name: selectedPerson.contact_name,
Expand Down Expand Up @@ -184,15 +185,15 @@ function CommunicationsPage() {

// Filter out duplicates by comparing with existing rows
const newRows = groupDonors.reduce((accumulator: RowItem[], donor) => {
// const existingRow = rows.find((row) => row.id === extractId(donor._id));
// if (!existingRow) {
const newItem: RowItem = {
id: extractId(donor._id),
contact_name: donor.contact_name,
contact_email: donor.contact_email,
};
accumulator.push(newItem);
// }
const existingRow = rows.find((row) => row.id === extractId(donor._id));
if (!existingRow) {
const newItem: RowItem = {
id: extractId(donor._id),
contact_name: donor.contact_name,
contact_email: donor.contact_email,
};
accumulator.push(newItem);
}
return accumulator;
}, []);

Expand All @@ -217,6 +218,10 @@ function CommunicationsPage() {
setRows([]);
};

const handleRemovePerson = (idToRemove: string) => {
setRows((prevRows) => prevRows.filter((row) => row.id !== idToRemove));
};

return (
<div>
<Grid container sx={{ m: 3 }} spacing={2}>
Expand All @@ -226,7 +231,7 @@ function CommunicationsPage() {
</Typography>
</Grid>
<Grid item xs={12}>
<Typography variant="h6">
<Typography variant="h6" sx={{ width: '80%' }}>
Send emails to individual users, groups of individuals, and mailing
lists. Clicking the “email” button, will open a popup with the
respective emails, which you can then copy and paste into your email
Expand Down Expand Up @@ -351,7 +356,12 @@ function CommunicationsPage() {
</TableCell>
<TableCell>{row.contact_email}</TableCell>
<TableCell>
<Link href="/">Remove {row.contact_name}</Link>
<Link
href="#"
onClick={() => handleRemovePerson(row.id)}
>
Remove {row.contact_name}
</Link>
</TableCell>
<TableCell>
<Link href="/">View</Link>
Expand Down

0 comments on commit b2cbddb

Please sign in to comment.