From 963f1c156a48f4e9beecf809d8b9b8baf0dd27de Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 19 Jul 2022 13:59:24 -0700 Subject: [PATCH] Fix undefined mostRecentDonor --- web/pages/charity/index.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/web/pages/charity/index.tsx b/web/pages/charity/index.tsx index b1cfc353..dd5653fc 100644 --- a/web/pages/charity/index.tsx +++ b/web/pages/charity/index.tsx @@ -6,6 +6,7 @@ import { sortBy, debounce, uniqBy, + last, } from 'lodash' import { useState, useMemo } from 'react' import { charities, Charity as CharityType } from 'common/charity' @@ -36,7 +37,8 @@ export async function getStaticProps() { ]) const matches = quadraticMatches(txns, totalRaised) 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 { props: { @@ -89,7 +91,7 @@ export default function Charity(props: { matches: { [charityId: string]: number } txns: Txn[] numDonors: number - mostRecentDonor: User + mostRecentDonor?: User }) { const { totalRaised, charities, matches, numDonors, mostRecentDonor } = props @@ -140,8 +142,8 @@ export default function Charity(props: { }, { name: 'Most recent donor', - stat: mostRecentDonor.name ?? 'Nobody', - url: `/${mostRecentDonor.username}`, + stat: mostRecentDonor?.name ?? 'Nobody', + url: `/${mostRecentDonor?.username}`, }, ]} />