Skip to content

Commit

Permalink
Merge pull request #40 from Giveth/endaoment_option_to_main
Browse files Browse the repository at this point in the history
add only Endaoment checkbox to fetch only endaoment projects to Production
  • Loading branch information
HrithikSampson authored Oct 7, 2024
2 parents 0dc808a + 0279370 commit 10325b5
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 5 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 @@ -28,11 +28,13 @@ const DonationsCount = () => {
const [toDate, setToDate] = useState(firstOfNextMonth());
const [selectedNetworkId, setSelectedNetworkId] = useState<number>();
const [onlyVerified, setOnlyVerified] = useState(false);
const [onlyEndaoment, setOnlyEndaoment] = useState<boolean>(false);
const { donationsCount, loading } = useDonationsCount(
fromDate,
toDate,
selectedNetworkId,
onlyVerified,
onlyEndaoment,
);

const { total, totalPerMonthAndYear } = donationsCount || {};
Expand Down Expand Up @@ -81,6 +83,12 @@ const DonationsCount = () => {
onChange={setOnlyVerified}
label='To verified projects only'
/>
<br />
<CheckBox
checked={onlyEndaoment}
onChange={setOnlyEndaoment}
label='To endaoment projects only'
/>
</Col>
<Col md={1} />
<Col md={2}>
Expand Down
10 changes: 10 additions & 0 deletions src/components/views/home/DonorsCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ import { FlexCenter } from '../../styled-components/flex';
import DonorsChart from './charts/DonorsChart';
import DatePicker from '../../DatePicker';
import NetworkSelect from '../../NetworkSelect';
import CheckBox from '../../CheckBox';

const DonorsCount = () => {
const [fromDate, setFromDate] = useState(firstOfGiveth());
const [toDate, setToDate] = useState(firstOfNextMonth());
const [selectedNetworkId, setSelectedNetworkId] = useState<number>();
const [onlyEndaoment, setOnlyEndaoment] = useState<boolean>(false);
const { donorsCount, loading } = useDonorsCount(
fromDate,
toDate,
selectedNetworkId,
onlyEndaoment,
);

const handleNetworkChange = (
Expand Down Expand Up @@ -71,6 +74,13 @@ const DonorsCount = () => {
selectedNetwork={selectedNetworkId}
onNetworkChange={handleNetworkChange}
/>
<br />
<br />
<CheckBox
checked={onlyEndaoment}
onChange={setOnlyEndaoment}
label='To endaoment projects only'
/>
</Col>
<Col md={1} />
<Col md={2}>
Expand Down
16 changes: 15 additions & 1 deletion src/components/views/home/TotalDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ const TotalDonations = () => {
const [toDate, setToDate] = useState(firstOfNextMonth());
const [selectedNetworkId, setSelectedNetworkId] = useState<number>();
const [onlyVerified, setOnlyVerified] = useState(false);
const [onlyEndaoment, setOnlyEndaoment] = useState<boolean>(false);
const { totalDonations, loading: loadingTotal } = useTotalDonations(
fromDate,
toDate,
selectedNetworkId,
onlyVerified,
onlyEndaoment,
);
const { categoryDonations, loading: loadingCategories } =
useCategoryDonations(fromDate, toDate, selectedNetworkId, onlyVerified);
useCategoryDonations(
fromDate,
toDate,
selectedNetworkId,
onlyVerified,
onlyEndaoment,
);

const totalCategoryDonations = categoryDonations?.reduce(
(i, j) => i + j.totalUsd,
Expand Down Expand Up @@ -99,6 +107,12 @@ const TotalDonations = () => {
onChange={setOnlyVerified}
label='To verified projects only'
/>
<br />
<CheckBox
checked={onlyEndaoment}
onChange={setOnlyEndaoment}
label='To endaoment 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 @@ -4,12 +4,14 @@ export const fetchTotalDonationsUSD = `
$toDate: String
$networkId: Float
$onlyVerified: Boolean
$onlyEndaoment: Boolean
) {
donationsTotalUsdPerDate (
fromDate: $fromDate
toDate: $toDate
networkId: $networkId
onlyVerified: $onlyVerified
onlyEndaoment: $onlyEndaoment
) {
total
totalPerMonthAndYear {
Expand All @@ -26,12 +28,14 @@ export const fetchTotalDonationsPerCategory = `
$toDate: String
$networkId: Float
$onlyVerified: Boolean
$onlyEndaoment: Boolean
) {
totalDonationsPerCategory (
fromDate: $fromDate
toDate: $toDate
networkId: $networkId
onlyVerified: $onlyVerified
onlyEndaoment: $onlyEndaoment
) {
id
title
Expand All @@ -47,12 +51,14 @@ export const fetchDonationsCount = `
$toDate: String
$networkId: Float
$onlyVerified: Boolean
$onlyEndaoment: Boolean
) {
totalDonationsNumberPerDate (
fromDate: $fromDate
toDate: $toDate
networkId: $networkId
onlyVerified: $onlyVerified
onlyEndaoment: $onlyEndaoment
) {
total
totalPerMonthAndYear {
Expand Down
2 changes: 2 additions & 0 deletions src/gql/gqlDonors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ export const fetchDonorsCount = `
$fromDate: String
$toDate: String
$networkId: Float
$onlyEndaoment: Boolean
) {
totalDonorsCountPerDate(
fromDate: $fromDate
toDate: $toDate
networkId: $networkId
onlyEndaoment: $onlyEndaoment
) {
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 @@ -12,6 +12,7 @@ const useCategoryDonations = (
toDate: Date,
selectedNetworkId?: number,
onlyVerified?: boolean,
onlyEndaoment?: boolean,
) => {
const [categoryDonations, setCategoryDonations] =
useState<ITotalDonationsPerCategory[]>();
Expand All @@ -24,6 +25,7 @@ const useCategoryDonations = (
toDate: formatDateToISO(toDate),
networkId: selectedNetworkId,
onlyVerified,
onlyEndaoment,
};
backendGQLRequest(fetchTotalDonationsPerCategory, variables)
.then((res: IFetchTotalDonationsPerCategory) => {
Expand All @@ -32,7 +34,7 @@ const useCategoryDonations = (
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, selectedNetworkId, onlyVerified]);
}, [fromDate, toDate, selectedNetworkId, onlyVerified, onlyEndaoment]);

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 @@ -9,6 +9,7 @@ const useDonationsCount = (
toDate: Date,
selectedNetworkId?: number,
onlyVerified?: boolean,
onlyEndaoment?: boolean,
) => {
const [donationsCount, setDonationsCount] = useState<IResFormat>();
const [loading, setLoading] = useState<boolean>(true);
Expand All @@ -20,14 +21,15 @@ const useDonationsCount = (
toDate: formatDateToISO(toDate),
networkId: selectedNetworkId,
onlyVerified,
onlyEndaoment,
};
backendGQLRequest(fetchDonationsCount, variables)
.then((res: IFetchDonationsCount) => {
setDonationsCount(res.data.totalDonationsNumberPerDate);
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, selectedNetworkId, onlyVerified]);
}, [fromDate, toDate, selectedNetworkId, onlyVerified, onlyEndaoment]);

return { donationsCount, loading };
};
Expand Down
4 changes: 3 additions & 1 deletion src/hooks/useDonorsCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const useDonorsCount = (
fromDate: Date,
toDate: Date,
selectedNetworkId?: number,
onlyEndaoment?: boolean,
) => {
const [donorsCount, setDonorsCount] = useState<IResFormat>();
const [loading, setLoading] = useState<boolean>(true);
Expand All @@ -18,14 +19,15 @@ const useDonorsCount = (
fromDate: formatDateToISO(fromDate),
toDate: formatDateToISO(toDate),
networkId: selectedNetworkId,
onlyEndaoment,
};
backendGQLRequest(fetchDonorsCount, variables)
.then((res: IFetchDonorsCount) => {
setDonorsCount(res.data.totalDonorsCountPerDate);
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, selectedNetworkId]);
}, [fromDate, toDate, selectedNetworkId, onlyEndaoment]);

return { donorsCount, 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 @@ -9,6 +9,7 @@ const useTotalDonations = (
toDate: Date,
selectedNetworkId?: number,
onlyVerified?: boolean,
onlyEndaoment?: boolean,
) => {
const [totalDonations, setTotalDonations] = useState<IResFormat>();
const [loading, setLoading] = useState<boolean>(true);
Expand All @@ -20,6 +21,7 @@ const useTotalDonations = (
toDate: formatDateToISO(toDate),
networkId: selectedNetworkId,
onlyVerified,
onlyEndaoment,
};
backendGQLRequest(fetchTotalDonationsUSD, variables)
.then((res: IFetchTotalDonationsUSD) => {
Expand All @@ -28,7 +30,7 @@ const useTotalDonations = (
})
.catch(showToastError)
.finally(() => setLoading(false));
}, [fromDate, toDate, selectedNetworkId, onlyVerified]);
}, [fromDate, toDate, selectedNetworkId, onlyVerified, onlyEndaoment]);

return { totalDonations, loading };
};
Expand Down

0 comments on commit 10325b5

Please sign in to comment.