Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update campaign donation component #1307

Merged
merged 13 commits into from
Jan 31, 2023
6 changes: 4 additions & 2 deletions public/locales/bg/campaigns.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"apply": "Кандидатствайте",
"support": "Дарете",
"support-cause-today": "Подкрепете кауза днес!",
"share": "Сподели",
"support-now": "Подкрепете сега",
"see-all": "Разгледайте всички",
"see-less": "Вижте по-малко",
Expand Down Expand Up @@ -84,8 +83,11 @@
"reached": "събрани",
"target": "цел",
"from": "от",
"noCommissionInfo": "Подкрепи.бг работи с 0% комисиона. Заплащат се единствено банкови такси, които изрично се упоменават преди да направите дарението си.",
"donors": "дарители",
"shares": "споделяния",
"documents": "документи",
"guarantor": "гарант",
"others": "други",
"profile": "Профил:",
"status": "Статус:",
"messages": "Послания:",
Expand Down
1 change: 0 additions & 1 deletion public/locales/bg/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"success-deleted": "Успешно изтрито!"
},
"close": "Затвори",
"support": "Подкрепи",
"link": "Линк",
"components": {
"footer": {
Expand Down
6 changes: 4 additions & 2 deletions public/locales/en/campaigns.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"apply": "Apply",
"support": "Donate",
"support-cause-today": "Support a campaign today!",
"share": "Share",
"support-now": "Support now",
"see-all": "See all",
"see-less": "See less",
Expand Down Expand Up @@ -83,8 +82,11 @@
"reached": "reached",
"target": "target",
"from": "from",
"noCommissionInfo": "Podkrepi.bg works with 0% commission. Only bank charges are paid, which are explicitly mentioned before you make your donation.",
"donors": "donors",
"shares": "shares",
"documents": "documents",
"guarantor": "guarantor",
"others": "others",
"messages": "Messages:",
"profile": "Profile:",
"status": "Status:",
Expand Down
1 change: 0 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
},
"close": "Close",
"link": "Link",
"support": "Donate",
"components": {
"footer": {
"donatе": "Donate",
Expand Down
2 changes: 1 addition & 1 deletion src/common/util/money.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const moneyPublic = (
if (currency === 'USD') {
return `${amount} $`
}
return `${amount} лв.`
return `${amount} лева`
}
return new Intl.NumberFormat(i18n.language, {
style: 'currency',
Expand Down
1 change: 1 addition & 0 deletions src/components/campaigns/DonationWishes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function DonationWishes({ campaignId, pageSize = 12 }: Props) {
<Grid2 container direction="column" rowGap={3}>
{isSuccess &&
data &&
data.items &&
data.items.map((wish) => (
<Grid2
gap={2}
Expand Down
61 changes: 39 additions & 22 deletions src/components/campaigns/DonorsAndDonations.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { useMemo, useState } from 'react'

import { useTranslation } from 'next-i18next'

import { CampaignDonation } from 'gql/campaigns'

import AccountCircleIcon from '@mui/icons-material/AccountCircle'
import FiberManualRecordIcon from '@mui/icons-material/FiberManualRecord'
import { Button, Grid, Typography } from '@mui/material'
import { Grid, Typography } from '@mui/material'
import { styled } from '@mui/material/styles'

import theme from 'common/theme'
import { moneyPublic } from 'common/util/money'
import { formatDistanceStrict, parseISO } from 'date-fns'
import { bg, enUS } from 'date-fns/locale'
import { CampaignDonation } from 'gql/campaigns'
import { useTranslation } from 'next-i18next'
import { useMemo, useState } from 'react'

const PREFIX = 'DonorsAndDonations'

Expand All @@ -17,31 +20,52 @@ const classes = {
donationItemWrapper: `${PREFIX}-donationItemWrapper`,
donationQuantityAndTimeWrapper: `${PREFIX}-donationQuantityAndTimeWrapper`,
separatorIcon: `${PREFIX}-separatorIcon`,
donatorName: `${PREFIX}-donatorName`,
donatorAvatar: `${PREFIX}-donatorAvatar`,
}

const Root = styled('div')(({ theme }) => ({
[`& .${classes.donationsWrapper}`]: {
marginTop: theme.spacing(5),
maxHeight: 400,
overflowY: 'scroll',
},

[`& .${classes.donationItemWrapper}`]: {
display: 'flex',
gap: theme.spacing(1),
alignItems: 'center',
marginBottom: theme.spacing(2),
marginBottom: theme.spacing(1.7),
maxHeight: theme.spacing(4.5),

'&:last-of-type': {
marginBottom: 0,
},
},

[`& .${classes.donationQuantityAndTimeWrapper}`]: {
display: 'flex',
gap: theme.spacing(1),
color: theme.palette.grey[500],
color: '#909090',
alignItems: 'center',
lineHeight: '145%',

'& p': {
fontSize: theme.typography.pxToRem(12),
},
},

[`& .${classes.separatorIcon}`]: {
fontSize: theme.spacing(1),
alignSelf: 'center',
fontSize: theme.typography.pxToRem(21),
fontWeight: 200,
},

[`& .${classes.donatorName}`]: {
color: theme.palette.common.black,
},

[`& .${classes.donatorAvatar}`]: {
width: theme.spacing(4.5),
flexBasis: 'fit-content',
height: theme.spacing(5.25),
},
}))

Expand All @@ -52,7 +76,7 @@ export default function DonorsAndDonations({
}) {
const { t, i18n } = useTranslation()
const [all, setAll] = useState<boolean>(false)
const shownDonationsNumber = 5
const shownDonationsNumber = 3
const donationsToShow = useMemo(() => {
if (all) {
return donations
Expand All @@ -66,16 +90,16 @@ export default function DonorsAndDonations({
{donationsToShow && donationsToShow.length !== 0 ? (
donationsToShow.map(({ person, amount, createdAt, currency }, key) => (
<Grid key={key} className={classes.donationItemWrapper}>
<AccountCircleIcon fontSize="large" color="disabled" />
<AccountCircleIcon color="disabled" className={classes.donatorAvatar} />
<Grid>
<Typography>
<Typography className={classes.donatorName}>
{person
? `${person.firstName} ${person.lastName}`
: t('campaigns:donations.anonymous')}
</Typography>
<Grid className={classes.donationQuantityAndTimeWrapper}>
<Typography>{moneyPublic(amount, currency)}</Typography>
<FiberManualRecordIcon className={classes.separatorIcon} />
<span className={classes.separatorIcon}>|</span>
<Typography>
{formatDistanceStrict(parseISO(createdAt), new Date(), {
locale: i18n.language == 'bg' ? bg : enUS,
Expand All @@ -92,13 +116,6 @@ export default function DonorsAndDonations({
</Typography>
)}
</Grid>
<Grid>
{donations && donations.length > shownDonationsNumber && (
<Button onClick={() => setAll((prev) => !prev)} variant="outlined">
{all ? t('campaigns:cta.see-less') : t('campaigns:cta.see-all')}
</Button>
)}
</Grid>
</Root>
)
}
Loading