Skip to content

Commit

Permalink
Add a total of all the approved expenses on the campaign page (#1483)
Browse files Browse the repository at this point in the history
* Fix the isAdmin function - we can have resource_access OR realm_access. The restrictions were too tight and we were not considering an admin user as such in some cases.

* Add an aggregation of the total approved expenses. This should help when there are too many expenses in the list and it is not obvious to count them.

* Fix a lint warning. Found a prettier icon for the receipts.
  • Loading branch information
slavcho authored Jul 13, 2023
1 parent 895e150 commit e7d8ecd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/components/client/campaigns/CampaignDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { useCampaignApprovedExpensesList } from 'common/hooks/expenses'
import { Assessment } from '@mui/icons-material'
import { routes } from 'common/routes'
import { useCanEditCampaign } from 'common/hooks/campaigns'
import { moneyPublic } from 'common/util/money'
import ReceiptLongIcon from '@mui/icons-material/ReceiptLong'

const ReactQuill = dynamic(() => import('react-quill'), { ssr: false })
const CampaignNewsSection = dynamic(() => import('./CampaignNewsSection'), { ssr: false })
Expand Down Expand Up @@ -98,6 +100,7 @@ export default function CampaignDetails({ campaign }: Props) {
const sliderImages = campaignSliderUrls(campaign)
const canEditCampaign = useCanEditCampaign(campaign.slug)
const { data: expensesList } = useCampaignApprovedExpensesList(campaign.slug)
const totalExpenses = expensesList?.reduce((acc, expense) => acc + expense.amount, 0)

return (
<StyledGrid item xs={12} md={8}>
Expand Down Expand Up @@ -125,7 +128,7 @@ export default function CampaignDetails({ campaign }: Props) {
{expensesList?.length || canEditCampaign ? (
<Grid item xs={12} id="expenses">
<Grid item xs={12}>
<Typography variant="h4" component="h4" my={8}>
<Typography variant="h4" component="h4" my={4}>
{t('campaigns:campaign.financial-report')} <Assessment />
{canEditCampaign ? (
<Tooltip title={t('campaigns:cta.edit')}>
Expand All @@ -140,6 +143,12 @@ export default function CampaignDetails({ campaign }: Props) {
)}
</Typography>
</Grid>
<Grid item xs={12}>
<Typography>
<ReceiptLongIcon /> {t('expenses:reported')}:{' '}
{moneyPublic(totalExpenses || 0, campaign.currency)}
</Typography>
</Grid>
<Grid item xs={12} mt={2}>
<CampaignPublicExpensesGrid slug={campaign.slug} />
</Grid>
Expand Down

0 comments on commit e7d8ecd

Please sign in to comment.