-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from Giveth/add-new-donors-count
add new donors count
- Loading branch information
Showing
8 changed files
with
309 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useState } from 'react'; | ||
import { | ||
H2, | ||
H4, | ||
H6, | ||
IconHelpFilled16, | ||
neutralColors, | ||
Subline, | ||
} from '@giveth/ui-design-system'; | ||
import styled from 'styled-components'; | ||
import { Col, Row } from '../../styled-components/grid'; | ||
import { StyledDatePicker } from '../../styled-components/datePicker'; | ||
import Spinner from '../../Spinner'; | ||
import { | ||
firstOfNextMonth, | ||
thousandsSeparator, | ||
firstOfThisMonth, | ||
} from '../../../lib/helpers'; | ||
import { IconWithTooltip } from '../../IconWithTooltip'; | ||
import { FlexCenter } from '../../styled-components/flex'; | ||
import useNewDonorsCount from '../../../hooks/useNewDonorsCount'; | ||
|
||
const DonorsCount = () => { | ||
const [fromDate, setFromDate] = useState(firstOfThisMonth()); | ||
const [toDate, setToDate] = useState(firstOfNextMonth()); | ||
const { newDonorsCount, loading } = useNewDonorsCount(fromDate, toDate); | ||
|
||
return ( | ||
<RowStyled> | ||
<Col md={4}> | ||
<FlexCenter gap='10px'> | ||
<H4>New Donors Count </H4> | ||
<IconWithTooltip | ||
icon={<IconHelpFilled16 />} | ||
direction={'top'} | ||
> | ||
<TooltipBody> | ||
The number of new donors that have arrived to the | ||
platform between two dates (users who have made | ||
their first donations) | ||
</TooltipBody> | ||
</IconWithTooltip> | ||
</FlexCenter> | ||
</Col> | ||
<Col md={4}> | ||
<div> | ||
From: | ||
<StyledDatePicker | ||
selected={fromDate} | ||
dateFormat='yyyy-MM' | ||
onChange={(e: Date) => setFromDate(e)} | ||
showPopperArrow={false} | ||
showMonthYearPicker | ||
placeholderText='Select a date' | ||
/> | ||
</div> | ||
<br /> | ||
<div> | ||
To: | ||
<StyledDatePicker | ||
selected={toDate} | ||
dateFormat='yyyy-MM' | ||
onChange={(e: Date) => setToDate(e)} | ||
showPopperArrow={false} | ||
showMonthYearPicker | ||
placeholderText='Select a date' | ||
/> | ||
</div> | ||
</Col> | ||
<Col md={1} /> | ||
<Col md={2}> | ||
<H6>Total:</H6> | ||
{loading ? ( | ||
<Spinner /> | ||
) : ( | ||
<H2>{thousandsSeparator(newDonorsCount)}</H2> | ||
)} | ||
</Col> | ||
</RowStyled> | ||
); | ||
}; | ||
|
||
const TooltipBody = styled(Subline)` | ||
color: ${neutralColors.gray[100]}; | ||
width: 270px; | ||
`; | ||
|
||
const RowStyled = styled(Row)` | ||
margin-top: 40px; | ||
align-items: center; | ||
margin-bottom: 40px; | ||
`; | ||
|
||
export default DonorsCount; |
101 changes: 101 additions & 0 deletions
101
src/components/views/home/NewDonorsDonationTotalUsd.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { useState } from 'react'; | ||
import { | ||
H2, | ||
H4, | ||
H6, | ||
IconHelpFilled16, | ||
neutralColors, | ||
Subline, | ||
} from '@giveth/ui-design-system'; | ||
import styled from 'styled-components'; | ||
import { Col, Row } from '../../styled-components/grid'; | ||
import { StyledDatePicker } from '../../styled-components/datePicker'; | ||
import Spinner from '../../Spinner'; | ||
import { | ||
firstOfNextMonth, | ||
thousandsSeparator, | ||
firstOfThisMonth, | ||
} from '../../../lib/helpers'; | ||
import { IconWithTooltip } from '../../IconWithTooltip'; | ||
import { FlexCenter } from '../../styled-components/flex'; | ||
import useNewDonorsDonationTotalUsd from '../../../hooks/useNewDonorsDonationTotalUsd'; | ||
|
||
const NewDonorsDonationTotalUsd = () => { | ||
const [fromDate, setFromDate] = useState(firstOfThisMonth()); | ||
const [toDate, setToDate] = useState(firstOfNextMonth()); | ||
const { newDonorsDonationTotalUsd, loading } = useNewDonorsDonationTotalUsd( | ||
fromDate, | ||
toDate, | ||
); | ||
|
||
return ( | ||
<RowStyled> | ||
<Col md={4}> | ||
<FlexCenter gap='10px'> | ||
<H4>New Donors Donation Total USD </H4> | ||
<IconWithTooltip | ||
icon={<IconHelpFilled16 />} | ||
direction={'top'} | ||
> | ||
<TooltipBody> | ||
The volume of donations made in USD from new donors | ||
between two dates (the total USD value of the first | ||
donations made by users) | ||
</TooltipBody> | ||
</IconWithTooltip> | ||
</FlexCenter> | ||
</Col> | ||
<Col md={4}> | ||
<div> | ||
From: | ||
<StyledDatePicker | ||
selected={fromDate} | ||
dateFormat='yyyy-MM' | ||
onChange={(e: Date) => setFromDate(e)} | ||
showPopperArrow={false} | ||
showMonthYearPicker | ||
placeholderText='Select a date' | ||
/> | ||
</div> | ||
<br /> | ||
<div> | ||
To: | ||
<StyledDatePicker | ||
selected={toDate} | ||
dateFormat='yyyy-MM' | ||
onChange={(e: Date) => setToDate(e)} | ||
showPopperArrow={false} | ||
showMonthYearPicker | ||
placeholderText='Select a date' | ||
/> | ||
</div> | ||
</Col> | ||
<Col md={1} /> | ||
<Col md={2}> | ||
<H6>Total (USD):</H6> | ||
{loading ? ( | ||
<Spinner /> | ||
) : ( | ||
<H2> | ||
{thousandsSeparator( | ||
newDonorsDonationTotalUsd?.toFixed(), | ||
)} | ||
</H2> | ||
)} | ||
</Col> | ||
</RowStyled> | ||
); | ||
}; | ||
|
||
const TooltipBody = styled(Subline)` | ||
color: ${neutralColors.gray[100]}; | ||
width: 270px; | ||
`; | ||
|
||
const RowStyled = styled(Row)` | ||
margin-top: 40px; | ||
align-items: center; | ||
margin-bottom: 40px; | ||
`; | ||
|
||
export default NewDonorsDonationTotalUsd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { backendGQLRequest } from '../lib/requests'; | ||
import { IFetchNewDonorsCount } from '../types/gql'; | ||
import { formatDateToISO, showToastError } from '../lib/helpers'; | ||
import { fetchNewDonorsCount } from '../gql/gqlDonors'; | ||
|
||
const useNewDonorsCount = (fromDate: Date, toDate: Date) => { | ||
const [newDonorsCount, setNewDonorsCount] = useState<number>(); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
!loading && setLoading(true); | ||
const variables = { | ||
fromDate: formatDateToISO(fromDate), | ||
toDate: formatDateToISO(toDate), | ||
}; | ||
backendGQLRequest(fetchNewDonorsCount, variables) | ||
.then((res: IFetchNewDonorsCount) => { | ||
setNewDonorsCount(res.data.newDonorsCountPerDate.total); | ||
}) | ||
.catch(showToastError) | ||
.finally(() => setLoading(false)); | ||
}, [fromDate, toDate]); | ||
|
||
return { newDonorsCount, loading }; | ||
}; | ||
|
||
export default useNewDonorsCount; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { backendGQLRequest } from '../lib/requests'; | ||
import { IFetchNewDonorsDonationTotalUsd } from '../types/gql'; | ||
import { formatDateToISO, showToastError } from '../lib/helpers'; | ||
import { fetchNewDonorsDonationTotalUsd } from '../gql/gqlDonors'; | ||
|
||
const useNewDonorsDonationTotalUsd = (fromDate: Date, toDate: Date) => { | ||
const [newDonorsDonationTotalUsd, setNewDonorsDonationTotalUsd] = | ||
useState<number>(); | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
!loading && setLoading(true); | ||
const variables = { | ||
fromDate: formatDateToISO(fromDate), | ||
toDate: formatDateToISO(toDate), | ||
}; | ||
backendGQLRequest(fetchNewDonorsDonationTotalUsd, variables) | ||
.then((res: IFetchNewDonorsDonationTotalUsd) => { | ||
setNewDonorsDonationTotalUsd( | ||
res.data.newDonorsDonationTotalUsdPerDate.total, | ||
); | ||
}) | ||
.catch(showToastError) | ||
.finally(() => setLoading(false)); | ||
}, [fromDate, toDate]); | ||
|
||
return { newDonorsDonationTotalUsd, loading }; | ||
}; | ||
|
||
export default useNewDonorsDonationTotalUsd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters