Skip to content

Commit

Permalink
Merge pull request #8 from Giveth/Allow-to-filter-Donation-data-by-ve…
Browse files Browse the repository at this point in the history
…rified-project-donations

Allow to filter Donation data by verified project donations
  • Loading branch information
RamRamez authored May 20, 2024
2 parents b16e0d9 + 6cd7093 commit 4e22dae
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
8 changes: 8 additions & 0 deletions src/components/views/home/DonationsCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const DonationsCount = () => {
const [fromDate, setFromDate] = useState(firstOfGiveth());
const [toDate, setToDate] = useState(firstOfNextMonth());
const [fromOptimism, setFromOptimism] = useState(false);
const [onlyVerified, setOnlyVerified] = useState(false);
const { donationsCount, loading } = useDonationsCount(
fromDate,
toDate,
fromOptimism,
onlyVerified,
);

const { total, totalPerMonthAndYear } = donationsCount || {};
Expand Down Expand Up @@ -64,6 +66,12 @@ const DonationsCount = () => {
onChange={setFromOptimism}
label='From Optimism only'
/>
<br />
<CheckBox
checked={onlyVerified}
onChange={setOnlyVerified}
label='To verified projects only'
/>
</Col>
<Col md={1} />
<Col md={2}>
Expand Down
12 changes: 9 additions & 3 deletions src/components/views/home/TotalDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ const TotalDonations = () => {
const [fromDate, setFromDate] = useState(firstOfGiveth());
const [toDate, setToDate] = useState(firstOfNextMonth());
const [fromOptimism, setFromOptimism] = useState(false);
const [onlyVerified, setOnlyVerified] = useState(false);
const { totalDonations, loading: loadingTotal } = useTotalDonations(
fromDate,
toDate,
fromOptimism,
onlyVerified,
);
const { categoryDonations, loading: loadingCategories } =
useCategoryDonations(fromDate, toDate, fromOptimism);
useCategoryDonations(fromDate, toDate, fromOptimism, onlyVerified);

const totalCategoryDonations = categoryDonations?.reduce(
(i, j) => i + j.totalUsd,
0,
);

console.log('totalCategoryDonations', fromDate);

const norCategoryDonations = categoryDonations?.map(i => {
return {
...i,
Expand Down Expand Up @@ -84,6 +84,12 @@ const TotalDonations = () => {
onChange={setFromOptimism}
label='From Optimism only'
/>
<br />
<CheckBox
checked={onlyVerified}
onChange={setOnlyVerified}
label='To verified projects only'
/>
</Col>
<Col md={1} />
<Col md={2}>
Expand Down
6 changes: 6 additions & 0 deletions src/gql/gqlDonations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ export const fetchTotalDonationsUSD = `
$fromDate: String
$toDate: String
$fromOptimismOnly: Boolean
$onlyVerified: Boolean
) {
donationsTotalUsdPerDate (
fromDate: $fromDate
toDate: $toDate
fromOptimismOnly: $fromOptimismOnly
onlyVerified: $onlyVerified
) {
total
totalPerMonthAndYear {
Expand All @@ -23,11 +25,13 @@ export const fetchTotalDonationsPerCategory = `
$fromDate: String
$toDate: String
$fromOptimismOnly: Boolean
$onlyVerified: Boolean
) {
totalDonationsPerCategory (
fromDate: $fromDate
toDate: $toDate
fromOptimismOnly: $fromOptimismOnly
onlyVerified: $onlyVerified
) {
id
title
Expand All @@ -42,11 +46,13 @@ export const fetchDonationsCount = `
$fromDate: String
$toDate: String
$fromOptimismOnly: Boolean
$onlyVerified: Boolean
) {
totalDonationsNumberPerDate (
fromDate: $fromDate
toDate: $toDate
fromOptimismOnly: $fromOptimismOnly
onlyVerified: $onlyVerified
) {
total
totalPerMonthAndYear {
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useCategoryDonations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const useCategoryDonations = (
fromDate: Date,
toDate: Date,
fromOptimism?: boolean,
onlyVerified?: boolean,
) => {
const [categoryDonations, setCategoryDonations] =
useState<ITotalDonationsPerCategory[]>();
Expand All @@ -22,6 +23,7 @@ const useCategoryDonations = (
fromDate: formatDateToISO(fromDate),
toDate: formatDateToISO(toDate),
fromOptimismOnly: fromOptimism || false,
onlyVerified,
};
backendGQLRequest(fetchTotalDonationsPerCategory, variables)
.then((res: IFetchTotalDonationsPerCategory) => {
Expand All @@ -30,7 +32,7 @@ const useCategoryDonations = (
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, fromOptimism]);
}, [fromDate, toDate, fromOptimism, onlyVerified]);

return { categoryDonations, loading };
};
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useDonationsCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const useDonationsCount = (
fromDate: Date,
toDate: Date,
fromOptimism?: boolean,
onlyVerified?: boolean,
) => {
const [donationsCount, setDonationsCount] = useState<IResFormat>();
const [loading, setLoading] = useState<boolean>(true);
Expand All @@ -18,14 +19,15 @@ const useDonationsCount = (
fromDate: formatDateToISO(fromDate),
toDate: formatDateToISO(toDate),
fromOptimismOnly: fromOptimism || false,
onlyVerified,
};
backendGQLRequest(fetchDonationsCount, variables)
.then((res: IFetchDonationsCount) => {
setDonationsCount(res.data.totalDonationsNumberPerDate);
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, fromOptimism]);
}, [fromDate, toDate, fromOptimism, onlyVerified]);

return { donationsCount, loading };
};
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useTotalDonations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const useTotalDonations = (
fromDate: Date,
toDate: Date,
fromOptimism?: boolean,
onlyVerified?: boolean,
) => {
const [totalDonations, setTotalDonations] = useState<IResFormat>();
const [loading, setLoading] = useState<boolean>(true);
Expand All @@ -18,6 +19,7 @@ const useTotalDonations = (
fromDate: formatDateToISO(fromDate),
toDate: formatDateToISO(toDate),
fromOptimismOnly: fromOptimism || false,
onlyVerified,
};
backendGQLRequest(fetchTotalDonationsUSD, variables)
.then((res: IFetchTotalDonationsUSD) => {
Expand All @@ -26,7 +28,7 @@ const useTotalDonations = (
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, fromOptimism]);
}, [fromDate, toDate, fromOptimism, onlyVerified]);

return { totalDonations, loading };
};
Expand Down

0 comments on commit 4e22dae

Please sign in to comment.