Skip to content

Commit

Permalink
added optional filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
lsylcy0307 committed May 14, 2024
1 parent 09ad124 commit 4700e8a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
27 changes: 21 additions & 6 deletions client/src/components/buttons/SearchDonorsButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ function SearchDonorsButton() {
};

const handleClose = () => {
setCampaign('');
setYearType('');
setMinDonation('');
setMaxDonation('');
setFilteredEmails('');
setStartTimePeriod(dayjs());
setEndTimePeriod(dayjs());
setOpen(false);
};

Expand Down Expand Up @@ -109,17 +116,25 @@ function SearchDonorsButton() {
donationDate.isSame(startTimePeriod)) &&
(donationDate.isBefore(endTimePeriod) ||
donationDate.isSame(endTimePeriod));
const matchesPurpose = donation.purpose_id === campaign;
let matchesAmount = false;
//initialize all true
let matchesYearType = true;
let matchesPurpose = true;
let matchesAmount = true;

//if filters are non-empty
if (campaign !== null && campaign!== undefined && campaign!== '') {
matchesPurpose = donation.purpose_id === campaign;
}

if (minDonation !== '' && maxDonation !== '') {
const minDonationNumber = Number(minDonation);
const maxDonationNumber = Number(maxDonation);
matchesAmount =
donation.amount >= minDonationNumber &&
donation.amount <= maxDonationNumber;
}
let matchesYearType = true;
if (donationType === 'grant') {

if (donationType === 'Grant') {
matchesYearType = donation.grant_year === yearType;
}

Expand Down Expand Up @@ -238,8 +253,8 @@ function SearchDonorsButton() {
value={yearType}
onChange={(e) => setYearType(e.target.value)}
>
<MenuItem value="single">Single Year</MenuItem>
<MenuItem value="multi">Multi Year</MenuItem>
<MenuItem value="single-year">Single Year</MenuItem>
<MenuItem value="multi-year">Multi Year</MenuItem>
</Select>
</FormControl>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions server/src/models/donation.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const DonationSchema = new mongoose.Schema({
enum: ['mail check', 'credit', 'paypal', 'other'],
required: true,
},
year: {
grant_year: {
type: String,
enum: ['multi-year', 'single-year'],
required: false,
Expand Down Expand Up @@ -45,7 +45,7 @@ interface IDonation extends mongoose.Document {
_id: string;
type: string;
payment_type: string;
year: string;
grant_year: string;
date: Date;
amount: number;
acknowledged: boolean;
Expand Down

0 comments on commit 4700e8a

Please sign in to comment.