Skip to content

Commit

Permalink
refactor details page ,implement new logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhaniivanov committed Aug 5, 2023
1 parent e26fa7b commit c509b46
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 69 deletions.
15 changes: 9 additions & 6 deletions public/locales/bg/campaigns.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"placeholder": "Стойността по подразбиране е същата като 'Име на кампанията'"
},
"amount": "Необходима сума",
"type": "Тип кампания",
"type": "Тип кампания:",
"state": "Статус",
"from": "от",
"noCommissionInfo": "Подкрепи.бг работи с 0% комисиона. Заплащат се единствено банкови такси, които изрично се упоменават преди да направите дарението си.",
Expand All @@ -101,6 +101,7 @@
"financial-report": "Финансови отчети",
"report-campaign": "Докладвайте кампанията",
"feedback": "Обратна връзка",
"altImageText": "Снимка на",
"images": {
"add": "Добави снимки",
"add-more": "Добави още",
Expand Down Expand Up @@ -152,13 +153,15 @@
"indefinite": "Безсрочна",
"tag": "Таг:",
"date": "Дата:",
"chipsLabels": {
"chipLabels": {
"categories": {
"aboutCampaign": "За кампанията",
"transparency": "Прозрачност"
},
"news": "Новини",
"docs": "Документи",
"reports": "Отчети",
"experts": "Експертен съвет",
"guarantor": "Гарант",
"signals": "Сигнали",
"others": "Други"
"guarantor": "Гарант"
}
},
"info-graphics": {
Expand Down
18 changes: 11 additions & 7 deletions public/locales/en/campaigns.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"coordinator": "Coordinator",
"organizer": "Organizer",
"beneficiary": "Beneficiary",
"campaignType": "Campaign type",
"campaignType": "Campaign type:",
"description": "Description",
"targetAmount": "Target amount",
"donationsAmount": "Donations amount",
Expand Down Expand Up @@ -96,6 +96,8 @@
"financial-report": "Financial report",
"report-campaign": "Report the campaign",
"feedback": "Feedback",
"altImageText": "Image of",

"images": {
"add": "Add image",
"add-more": "Add more",
Expand Down Expand Up @@ -146,13 +148,15 @@
"end-date": "End date:",
"tag": "Tag:",
"date": "Date:",
"chipsLabels": {
"chipLabels": {
"categories": {
"aboutCampaign": "About campaign",
"transparency": "Transparency"
},
"news": "News",
"docs": "Documents",
"experts": "Experts",
"guarantor": "Guarantor",
"signals": "Signals",
"others": "Others"
"reports": "Reports",
"experts": "Our expert members",
"guarantor": "Guarantor"
}
},
"info-graphics": {
Expand Down
54 changes: 39 additions & 15 deletions src/components/client/campaigns/CampaignDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'

import { useTranslation } from 'next-i18next'
import dynamic from 'next/dynamic'
import { useRouter } from 'next/router'

import { CampaignResponse } from 'gql/campaigns'

Expand Down Expand Up @@ -102,14 +103,15 @@ export default function CampaignDetails({ campaign }: Props) {
const canEditCampaign = useCanEditCampaign(campaign.slug)
const { data: expensesList } = useCampaignApprovedExpensesList(campaign.slug)
const totalExpenses = expensesList?.reduce((acc, expense) => acc + expense.amount, 0)
const router = useRouter()

const chipsLabel = {
news: t('campaigns:campaign.chipsLabels.news'),
docs: t('campaigns:campaign.chipsLabels.docs'),
experts: t('campaigns:campaign.chipsLabels.experts'),
guarantor: t('campaigns:campaign.chipsLabels.guarantor'),
signals: t('campaigns:campaign.chipsLabels.signals'),
others: t('campaigns:campaign.chipsLabels.others'),
const chipLabelsCampaign = {
experts: t('campaigns:campaign.chipLabels.experts'),
guarantor: t('campaigns:campaign.chipLabels.guarantor'),
}
const chipLabelsTransparency = {
news: t('campaigns:campaign.chipLabels.news'),
reports: t('campaigns:campaign.chipLabels.reports'),
}

const scrollToSection = (sectionId: string) => {
Expand All @@ -119,6 +121,10 @@ export default function CampaignDetails({ campaign }: Props) {
}
}

const redirectToExperts = () => {
router.push('https://podkrepi.bg/blog/ekspertni-saveti')
}

return (
<StyledGrid item xs={12} md={8}>
<Typography variant="h1" component="h1" mb={8} className={classes.campaignTitle}>
Expand All @@ -129,26 +135,44 @@ export default function CampaignDetails({ campaign }: Props) {
showExpensesLink={(expensesList && expensesList?.length > 0) || canEditCampaign}
/>
<Grid container spacing={8}>
<Grid item xs={12}>
<ReactQuill readOnly theme="bubble" value={campaign.description} />
<Grid container item xs={12}>
<Grid item xs={12} display="flex" alignItems="center" marginBottom="8px">
<Typography component="p" marginRight="10px">
{t('campaigns:campaign.chipLabels.categories.aboutCampaign')}
</Typography>
{Object.entries(chipLabelsCampaign).map(([id, label]) => (
<CampaignDetailsChip
key={id}
chip={label}
onClick={id === 'experts' ? redirectToExperts : () => scrollToSection(id)}
/>
))}
</Grid>
<Grid item xs={12} display="flex" alignItems="center">
<Typography component="p" marginRight="10px">
{t('campaigns:campaign.chipLabels.categories.transparency')}
</Typography>
{Object.entries(chipLabelsTransparency).map(([id, label]) => (
<CampaignDetailsChip key={id} chip={label} onClick={() => scrollToSection(id)} />
))}
</Grid>
<Grid item xs={12}>
<ReactQuill readOnly theme="bubble" value={campaign.description} />
</Grid>
</Grid>
<Grid item xs={12}>
<CampaignSlider sliderImages={sliderImages} />
</Grid>
<Grid item xs={12}>
<Divider />
</Grid>
<Grid container item xs={12}>
{Object.entries(chipsLabel).map(([id, label]) => (
<CampaignDetailsChip key={id} chip={label} onClick={() => scrollToSection(id)} />
))}
</Grid>

<Grid item xs={12}>
<CampaignInfoOperator campaign={campaign} />
</Grid>
<CampaignInfoGraphics />
{expensesList?.length || canEditCampaign ? (
<Grid item xs={12} id="expenses">
<Grid item xs={12} id="reports">
<Grid item xs={12}>
<Typography variant="h4" component="h4" my={4}>
{t('campaigns:campaign.financial-report')} <Assessment />
Expand Down
4 changes: 3 additions & 1 deletion src/components/client/campaigns/CampaignDetailsChip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface CampaingDetailsChipProps {
}

const CampaignDetailsChip: React.FC<CampaingDetailsChipProps> = ({ chip, onClick }) => {
return <Chip label={chip} sx={{ marginX: '2px' }} onClick={onClick} />
return (
<Chip label={chip} sx={{ marginX: '2px' }} onClick={onClick} color="primary" size="small" />
)
}
export default CampaignDetailsChip
62 changes: 34 additions & 28 deletions src/components/client/campaigns/CampaignInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { styled } from '@mui/material/styles'
import { getExactDate } from 'common/util/date'
import CampaignInfoOrganizer from './CampaignInfoOrganizer'
import { Assessment } from '@mui/icons-material'
import CampaignInfoBeneficiary from './CampaignInfoBeneficiary'

const PREFIX = 'CampaignInfo'

Expand Down Expand Up @@ -55,7 +56,7 @@ const StyledGrid = styled(Grid)(({ theme }) => ({

[`& .${classes.campaignTextWithIcon}`]: {
flexWrap: 'wrap',
fontSize: theme.typography.pxToRem(16),
fontSize: theme.typography.pxToRem(11),
lineHeight: '150%',
fontWeight: 700,
},
Expand All @@ -72,36 +73,41 @@ export default function CampaignInfo({ campaign, showExpensesLink }: Props) {

return (
<StyledGrid mb={5}>
<Grid container spacing={2} alignItems="center" marginBottom="15px">
<Grid item xs={12} md={3}>
<Typography
variant="subtitle2"
component="span"
fontWeight={700}
className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.type')} {campaign.campaignType.name}
</Typography>
</Grid>
<Grid item xs={12} md={3}>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.start-date')} {getExactDate(campaign.startDate, locale)}
</Typography>
</Grid>
<Grid item xs={12} md={3}>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.end-date')}{' '}
{campaign.endDate
? getExactDate(campaign.endDate, locale)
: t('campaigns:campaign.indefinite')}
</Typography>
</Grid>
<Grid item xs={12} md={3}>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.status')} {t(`campaigns:campaign-status.${campaign.state}`)}
</Typography>
</Grid>
</Grid>
<Grid container item xs={12} className={classes.infoBlockWrapper}>
<Grid item container xs={12} lg={5} spacing={0} className={classes.infoDetailsWrapper}>
<Grid item>
<Typography
variant="subtitle2"
component="p"
fontWeight={700}
className={classes.campaignTextWithIcon}>
{campaign.campaignType.name}
</Typography>
</Grid>
<Grid item>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.start-date')} {getExactDate(campaign.startDate, locale)}
</Typography>
</Grid>
<Grid item>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.end-date')}{' '}
{campaign.endDate
? getExactDate(campaign.endDate, locale)
: t('campaigns:campaign.indefinite')}
</Typography>
</Grid>
<Grid item>
<Typography variant="subtitle2" component="p" className={classes.campaignTextWithIcon}>
{t('campaigns:campaign.status')} {t(`campaigns:campaign-status.${campaign.state}`)}
</Typography>
<CampaignInfoBeneficiary campaign={campaign} />
</Grid>
{showExpensesLink && (
{/* {showExpensesLink && (
<Grid item>
<Button
startIcon={<Assessment />}
Expand All @@ -110,7 +116,7 @@ export default function CampaignInfo({ campaign, showExpensesLink }: Props) {
{t('campaigns:campaign.financial-report')}
</Button>
</Grid>
)}
)} */}
</Grid>
<Divider className={classes.divider} />
<Grid item xs={12} lg={7}>
Expand Down
96 changes: 96 additions & 0 deletions src/components/client/campaigns/CampaignInfoBeneficiary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import React from 'react'

import { useTranslation } from 'next-i18next'
import Image from 'next/image'

import { CampaignResponse } from 'gql/campaigns'

import { Button, Grid, Typography } from '@mui/material'
import EmailIcon from '@mui/icons-material/Email'
import { styled } from '@mui/material/styles'

import { organizerCampaignPictureUrl } from 'common/util/campaignImageUrls'

const PREFIX = 'CampaignInfoOrganizer'

const classes = {
infoButtonIcon: `${PREFIX}-infoButtonIcon`,
personAvatar: `${PREFIX}-personAvatar`,
avatarWrapper: `${PREFIX}-avatarWrapper`,
trustedButton: `${PREFIX}-trustedButton`,
organizer: `${PREFIX}-organizer`,
}

const StyledGrid = styled(Grid)(({ theme }) => ({
[`& .${classes.avatarWrapper}`]: {
paddingLeft: theme.spacing(2.5),

[theme.breakpoints.up('lg')]: {
paddingLeft: theme.spacing(0),
},
},

[`& .${classes.personAvatar}`]: {
borderRadius: '50%',
objectFit: 'cover',
},

[`& .${classes.trustedButton}`]: {
color: theme.palette.primary.main,
textDecoration: 'underline',
fontSize: theme.spacing(1.75),
padding: 0,
paddingLeft: 2,

'&:hover': {
backgroundColor: 'unset',
textDecoration: 'underline',
},
},

[`& .${classes.infoButtonIcon}`]: {
marginRight: theme.spacing(1),
},

[`& .${classes.organizer}`]: {
fontSize: theme.typography.pxToRem(14),
fontWight: 700,
},
}))

type Props = {
campaign: CampaignResponse
}

export default function CampaignInfoBeneficiary({ campaign }: Props) {
const { t } = useTranslation()
const organizerAvatarSource = organizerCampaignPictureUrl(campaign)

return (
<StyledGrid container item gap={3}>
<Grid item className={classes.avatarWrapper} minWidth="max-content" flex={1}>
<Image
src={organizerAvatarSource}
//TODO check alt
alt={
t('campaigns:campaign.organizer.name') +
`${campaign.organizer?.person.firstName} ${campaign.organizer?.person.lastName}`
}
width={100}
height={100}
className={classes.personAvatar}
/>
</Grid>
<Grid item flex={6}>
<Typography variant="subtitle2" component="p" className={classes.organizer}>
{t('campaigns:campaign.beneficiary.name')}
</Typography>
<Typography variant="subtitle2" component="p" className={classes.organizer}>
{campaign?.beneficiary?.person
? campaign?.beneficiary?.person?.firstName + campaign?.beneficiary?.person?.lastName
: campaign?.beneficiary?.company?.companyName}
</Typography>
</Grid>
</StyledGrid>
)
}
Loading

0 comments on commit c509b46

Please sign in to comment.