Skip to content

Commit

Permalink
Fix all errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Pulkith committed Jun 8, 2024
1 parent b3702b9 commit d6ac4b2
Show file tree
Hide file tree
Showing 9 changed files with 379 additions and 515 deletions.
10 changes: 5 additions & 5 deletions client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ function App() {
{/* Routes accessed only if user is authenticated */}
<Route element={<ProtectedRoutesWrapper />}>
<Route path="/home" element={<HomePage />} />
<Route
path="/donationInfo"
element={<DonationInfoPage />}
/>
<Route
path="/donationInfo"
element={<DonationInfoPage />}
/>
<Route path="/reports" element={<ReportsPage />} />
<Route
path="/communications"
Expand Down Expand Up @@ -128,4 +128,4 @@ function App() {
);
}

export default App;
export default App;
52 changes: 35 additions & 17 deletions client/src/Communications/CommunicationsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable jsx-a11y/anchor-is-valid */
/* eslint-disable no-underscore-dangle */
import React, { useEffect, useState } from 'react';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
import SearchDonorsButton from '../components/buttons/SearchDonorsButton';
import axios from 'axios';
import {
Typography,
Expand All @@ -20,6 +21,7 @@ import {
TableHead,
Link,
} from '@mui/material';
import SearchDonorsButton from '../components/buttons/SearchDonorsButton';
import AddEditGroupsModal from '../components/AddEditGroupsModal';
import IDonor from '../util/types/donor';
import IGroup from '../util/types/group';
Expand Down Expand Up @@ -126,7 +128,7 @@ type RowItem = {
};

interface DonorInfo {
email: string
email: string;
name: string;
_id: string;
}
Expand All @@ -148,7 +150,7 @@ function CommunicationsPage() {
const allDonors: any | null = useData('donor/all');
const allDonations: any | null = useData('donation/all');
const allGroups: any | null = useData('group/all');

const handleUnackDonoModalOpen = async () => {
try {
console.log('opened');
Expand All @@ -164,6 +166,7 @@ function CommunicationsPage() {
return;
}
const donorInfo = donorInfoResponse.data;
// eslint-disable-next-line consistent-return
return {
...donation,
donorName: donorInfo.contact_name,
Expand Down Expand Up @@ -274,7 +277,6 @@ function CommunicationsPage() {
setGroupSearchValue(null);
};


const handleGroupChange = (
event: React.SyntheticEvent,
value: IGroup | null,
Expand All @@ -289,12 +291,9 @@ function CommunicationsPage() {
};

const copyEmails = () => {
rows.forEach((row) =>
console.log(row.contact_email)
);
rows.forEach((row) => console.log(row.contact_email));
};


const handleRemovePerson = (idToRemove: string) => {
setRows((prevRows) => prevRows.filter((row) => row.id !== idToRemove));
};
Expand All @@ -308,7 +307,11 @@ function CommunicationsPage() {
return '';
}

function handleAddUnackDonation(selectedName: string, selectedEmail: string, selectedId: string) {
function handleAddUnackDonation(
selectedName: string,
selectedEmail: string,
selectedId: string,
) {
if (selectedId) {
const selectedPerson = donors.find(
(person) => extractId(person._id) === selectedId,
Expand All @@ -333,7 +336,7 @@ function CommunicationsPage() {
console.log('Received filtered donors:', filteredDonors);
filteredDonors.forEach((donor: DonorInfo) => {
handleAddUnackDonation(donor.name, donor.email, donor._id);
})
});
};

return (
Expand Down Expand Up @@ -368,6 +371,7 @@ function CommunicationsPage() {
sx={{ width: 300, marginBottom: '15px' }}
onChange={handleNameChange}
renderInput={(params) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<TextField {...params} label="Search Name" />
)}
/>
Expand Down Expand Up @@ -402,7 +406,10 @@ function CommunicationsPage() {
>
Add / Edit Groups
</Button>
<AddEditGroupsModal open={editGroupModalOpen} onClose={handleGroupModalClose} />
<AddEditGroupsModal
open={editGroupModalOpen}
onClose={handleGroupModalClose}
/>
<Stack
spacing={{ xs: 2 }}
direction="row"
Expand All @@ -418,6 +425,7 @@ function CommunicationsPage() {
value={groupSearchValue}
onChange={handleGroupChange}
renderInput={(params) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<TextField {...params} label="Search Name" />
)}
/>
Expand Down Expand Up @@ -507,15 +515,19 @@ function CommunicationsPage() {
Contact Unacknowledged Donations
</Typography>
{unacknowledgedDonations.map((donation) => (
<Box key={donation._id}
<Box
key={donation._id}
sx={{
p: 2,
my: 1,
borderRadius: 2,
boxShadow: 3,
}}>
}}
>
<Typography variant="body1">Amount: {donation.amount}</Typography>
<Typography variant="body1">Date: {formatDateString(donation.date) || 'N/A'}</Typography>
<Typography variant="body1">
Date: {formatDateString(donation.date) || 'N/A'}
</Typography>
<Typography variant="body1">
Donor Name: {donation.donorName}
</Typography>
Expand All @@ -526,11 +538,17 @@ function CommunicationsPage() {
variant="contained"
color="primary"
size="medium"
style={{ marginTop: '10px' }}
onClick={() => handleAddUnackDonation(donation.donorName, donation.donorEmail, donation.donorId)}
style={{ marginTop: '10px' }}
onClick={() =>
handleAddUnackDonation(
donation.donorName,
donation.donorEmail,
donation.donorId,
)
}
>
Select
</Button >
</Button>
</Box>
))}
<Button onClick={handleUnackDonoModalClose}>Close</Button>
Expand Down
3 changes: 1 addition & 2 deletions client/src/DonationInfo/DonationInfoPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const style = {
overflow: 'scroll',
height: '80%',
};

function BasicTable({
customRows,
}: {
Expand Down Expand Up @@ -170,7 +170,6 @@ function DonationInfoPage() {

useEffect(() => {
if (donationData) {

const updatedCustomRows = [
{
label: 'Donation Amount',
Expand Down
45 changes: 28 additions & 17 deletions client/src/components/AddEditGroupsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-underscore-dangle */
import React, { useState, useEffect } from 'react';
import {
Dialog,
Expand Down Expand Up @@ -56,18 +57,20 @@ const updateGroupDonorsAPI = (selectedGroup: Group, donorIds: string[]) => {
donor_ids: donorIds,
};
console.log(updatedGroup);

return postData('group/edit', updatedGroup);
};

export default function AddEditGroupsModal({ open, onClose }) {
export default function AddEditGroupsModal({ open, onClose }: any) {
// const [open, setOpen] = React.useState(false);
const [groups, setGroups] = useState<Group[]>([]);
const [selectedGroup, setSelectedGroup] = useState<Group | null>(null);
const [selectedDonors, setSelectedDonors] = useState<Donor[]>([]);
const [unselectedDonors, setUnselectedDonors] = useState<Donor[]>([]);
const [allDonors, setAllDonors] = useState<Donor[]>([]);
const [selectedDonorName, setSelectedDonorName] = useState<string | null>(null);
const [selectedDonorName, setSelectedDonorName] = useState<string | null>(
null,
);
const [isNewGroup, setIsNewGroup] = useState(false);

const group = useData(`group/all`);
Expand All @@ -86,29 +89,30 @@ export default function AddEditGroupsModal({ open, onClose }) {
// console.log(data);
}, [group]);


useEffect(() => {
if (selectedGroup) {
const selected = allDonors.filter((donor) =>
selectedGroup.donor_ids.includes(donor._id),
(selectedGroup.donor_ids || []).includes(donor._id),
);

const unselected = allDonors.filter(
(donor) => !selectedGroup.donor_ids.includes(donor._id),
(donor) => !(selectedGroup.donor_ids || []).includes(donor._id),
);

setSelectedDonors(selected);
setUnselectedDonors(unselected);

} else {
setSelectedDonors([]);
setUnselectedDonors(allDonors);
}
setSelectedDonorName(''); // Reset selected donor value when group changes
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedGroup]);

const handleAddDonor = () => {
const donor = unselectedDonors.find((d) => d.contact_name === selectedDonorName);
const donor = unselectedDonors.find(
(d) => d.contact_name === selectedDonorName,
);
if (donor) {
setSelectedDonors([...selectedDonors, donor]);
setUnselectedDonors(unselectedDonors.filter((d) => d._id !== donor._id));
Expand All @@ -126,7 +130,7 @@ export default function AddEditGroupsModal({ open, onClose }) {
// console.log(selectedGroup);
const donorIds = selectedDonors.map((donor) => donor._id);

updateGroupDonorsAPI(selectedGroup, donorIds) //update group
updateGroupDonorsAPI(selectedGroup, donorIds) // update group
.then(() => {
setSelectedDonorName(''); // Reset selected donor value after submit
})
Expand All @@ -152,7 +156,7 @@ export default function AddEditGroupsModal({ open, onClose }) {
})
.catch((error) => {
console.log(error);
});
});
}
};

Expand All @@ -169,7 +173,7 @@ export default function AddEditGroupsModal({ open, onClose }) {
</IconButton>
</DialogTitle>
<DialogContent>
<Autocomplete
<Autocomplete
value={selectedGroup}
onChange={(event, newValue) => {
setIsNewGroup(false);
Expand All @@ -191,7 +195,9 @@ export default function AddEditGroupsModal({ open, onClose }) {

const { inputValue } = params;
// Suggest the creation of a new value
const isExisting = options.some((option) => inputValue === option.group_name);
const isExisting = options.some(
(option) => inputValue === option.group_name,
);
if (inputValue !== '' && !isExisting) {
filtered.push({
inputValue,
Expand All @@ -213,18 +219,22 @@ export default function AddEditGroupsModal({ open, onClose }) {
}
// Add "xxx" option created dynamically
if (option.title) {
return option.group_name;
return option.group_name ?? '';
}
// Regular option
return option.group_name || '';
}}
renderOption={(props, option) => (
<li {...props}>{option.title ? option.title : option.group_name}</li>
// eslint-disable-next-line react/jsx-props-no-spreading
<li {...props}>
{option.title ? option.title : option.group_name}
</li>
)}
sx={{ width: 300 }}
freeSolo
renderInput={(params) => (
<TextField
// eslint-disable-next-line react/jsx-props-no-spreading
{...params}
label="Group"
required
Expand All @@ -239,6 +249,7 @@ export default function AddEditGroupsModal({ open, onClose }) {
freeSolo
options={unselectedDonors.map((option) => option.contact_name)}
renderInput={(params) => (
// eslint-disable-next-line react/jsx-props-no-spreading
<TextField {...params} label="Donor / Sponsor" margin="normal" />
)}
value={selectedDonorName}
Expand Down Expand Up @@ -296,4 +307,4 @@ export default function AddEditGroupsModal({ open, onClose }) {
</DialogContent>
</Dialog>
);
}
}
Loading

0 comments on commit d6ac4b2

Please sign in to comment.