Skip to content

Commit 200ae2c

Browse files
committed
Allow for possible lack of data
1 parent 1a8da5b commit 200ae2c

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

src/app/pages/renewal-form/renewal-form.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function EnsureLoggedIn() {
176176
const [adoptionInfo, setAdoptionInfo] = React.useState(defaultMsg);
177177

178178
React.useEffect(
179-
() => adoptionsPromise.then(setAdoptionInfo),
179+
() => adoptionsPromise.then((info) => info && setAdoptionInfo(info)),
180180
[]
181181
);
182182

src/app/pages/renewal-form/salesforce-data.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ const asUSD = new Intl.NumberFormat('en-US', {
55
currency: 'USD'
66
});
77

8-
98
function createThanksStatement({adoptions}: AdoptionData) {
109
const firstYear = Math.min(...adoptions.map((a) => a.baseYear));
1110
const sumStudents = adoptions
1211
.map((a) => a.students)
1312
.filter((s): s is Exclude<typeof s, null> => s !== null)
1413
.reduce((a, b) => a + b);
15-
const sumSavings = adoptions
16-
.map((a) => a.savings)
17-
.reduce((a, b) => a + b);
14+
const sumSavings = adoptions.map((a) => a.savings).reduce((a, b) => a + b);
1815

19-
return `Thanks for being an adopter of our books since ${firstYear}.
20-
You've impacted ${sumStudents} students, saving them a total of
21-
${asUSD.format(sumSavings)}.`;
16+
return (
17+
(firstYear
18+
? `Thanks for being an adopter of our books since ${firstYear}. `
19+
: '') +
20+
(sumSavings
21+
? `You've impacted ${sumStudents} students, saving them a total of
22+
${asUSD.format(sumSavings)}.`
23+
: '')
24+
);
2225
}
2326

2427
export default adoptionPromise.then(createThanksStatement);

0 commit comments

Comments
 (0)