Fix undefined mostRecentDonor
This commit is contained in:
parent
a992773a65
commit
963f1c156a
|
@ -6,6 +6,7 @@ import {
|
||||||
sortBy,
|
sortBy,
|
||||||
debounce,
|
debounce,
|
||||||
uniqBy,
|
uniqBy,
|
||||||
|
last,
|
||||||
} from 'lodash'
|
} from 'lodash'
|
||||||
import { useState, useMemo } from 'react'
|
import { useState, useMemo } from 'react'
|
||||||
import { charities, Charity as CharityType } from 'common/charity'
|
import { charities, Charity as CharityType } from 'common/charity'
|
||||||
|
@ -36,7 +37,8 @@ export async function getStaticProps() {
|
||||||
])
|
])
|
||||||
const matches = quadraticMatches(txns, totalRaised)
|
const matches = quadraticMatches(txns, totalRaised)
|
||||||
const numDonors = uniqBy(txns, (txn) => txn.fromId).length
|
const numDonors = uniqBy(txns, (txn) => txn.fromId).length
|
||||||
const mostRecentDonor = await getUser(txns[txns.length - 1].fromId)
|
const donorId = last(txns)?.fromId
|
||||||
|
const mostRecentDonor = donorId ? await getUser(donorId) : undefined
|
||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
|
@ -89,7 +91,7 @@ export default function Charity(props: {
|
||||||
matches: { [charityId: string]: number }
|
matches: { [charityId: string]: number }
|
||||||
txns: Txn[]
|
txns: Txn[]
|
||||||
numDonors: number
|
numDonors: number
|
||||||
mostRecentDonor: User
|
mostRecentDonor?: User
|
||||||
}) {
|
}) {
|
||||||
const { totalRaised, charities, matches, numDonors, mostRecentDonor } = props
|
const { totalRaised, charities, matches, numDonors, mostRecentDonor } = props
|
||||||
|
|
||||||
|
@ -140,8 +142,8 @@ export default function Charity(props: {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Most recent donor',
|
name: 'Most recent donor',
|
||||||
stat: mostRecentDonor.name ?? 'Nobody',
|
stat: mostRecentDonor?.name ?? 'Nobody',
|
||||||
url: `/${mostRecentDonor.username}`,
|
url: `/${mostRecentDonor?.username}`,
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user