diff --git a/src/emails/components/EmailDataPointCount.tsx b/src/emails/components/EmailDataPointCount.tsx index 3a927ebfa0..7f8deca561 100644 --- a/src/emails/components/EmailDataPointCount.tsx +++ b/src/emails/components/EmailDataPointCount.tsx @@ -10,6 +10,7 @@ import { DashboardSummary } from "../../app/functions/server/dashboard"; import { getSignupLocaleCountry } from "../functions/getSignupLocaleCountry"; import { isEligibleForPremium } from "../../app/functions/universal/premium"; import { SanitizedSubscriberRow } from "../../app/functions/server/sanitize"; +import { calculateSanitizedDataPoints } from "../functions/reduceSanitizedDataPoints"; type Props = { l10n: ExtendedReactLocalization; @@ -24,14 +25,6 @@ export const DataPointCount = (props: Props) => { const assumedCountryCode = getSignupLocaleCountry(props.subscriber); const unresolvedDataBreaches = props.dataSummary.dataBreachUnresolvedNum; - const sumOfUnresolvedDataPoints = - props.dataSummary.unresolvedSanitizedDataPoints.reduce( - (total, dataPointSummary) => { - return total + Object.values(dataPointSummary)[0]; - }, - 0, - ); - const hasRunFreeScan = typeof props.subscriber.onerep_profile_id === "number"; const utmContentSuffix = isEligibleForPremium(assumedCountryCode) ? "-us" @@ -73,7 +66,9 @@ export const DataPointCount = (props: Props) => { line-height="68px" > {hasRunFreeScan - ? sumOfUnresolvedDataPoints + ? calculateSanitizedDataPoints( + props.dataSummary.unresolvedSanitizedDataPoints, + ) : unresolvedDataBreaches} { : "email-monthly-report-no-scan-results-data-points-label", { data_point_count: hasRunFreeScan - ? sumOfUnresolvedDataPoints + ? calculateSanitizedDataPoints( + props.dataSummary.unresolvedSanitizedDataPoints, + ) : unresolvedDataBreaches, }, )} diff --git a/src/emails/functions/reduceSanitizedDataPoints.ts b/src/emails/functions/reduceSanitizedDataPoints.ts new file mode 100644 index 0000000000..3f279c1a89 --- /dev/null +++ b/src/emails/functions/reduceSanitizedDataPoints.ts @@ -0,0 +1,18 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* eslint-disable */ +import { SanitizedDataPoints } from "../../app/functions/server/dashboard"; + +export function calculateSanitizedDataPoints( + data: SanitizedDataPoints, +): number { + return data.reduce( + (accumulatedValue: number, currentDataPoint: Record) => { + const dataPointValue = Object.values(currentDataPoint)[0] as number; + return accumulatedValue + dataPointValue; + }, + 0, + ); +} diff --git a/src/emails/templates/monthlyActivityFree/MonthlyActivityFreeEmail.tsx b/src/emails/templates/monthlyActivityFree/MonthlyActivityFreeEmail.tsx index 5673b1c3b4..dc6f0c7098 100644 --- a/src/emails/templates/monthlyActivityFree/MonthlyActivityFreeEmail.tsx +++ b/src/emails/templates/monthlyActivityFree/MonthlyActivityFreeEmail.tsx @@ -13,6 +13,7 @@ import { isEligibleForPremium } from "../../../app/functions/universal/premium"; import { getSignupLocaleCountry } from "../../functions/getSignupLocaleCountry"; import { HeaderStyles, MetaTags } from "../HeaderStyles"; import { SanitizedSubscriberRow } from "../../../app/functions/server/sanitize"; +import { calculateSanitizedDataPoints } from "../../functions/reduceSanitizedDataPoints"; export type MonthlyActivityFreeEmailProps = { l10n: ExtendedReactLocalization; @@ -78,19 +79,16 @@ export const MonthlyActivityFreeEmail = ( // Show a sum of resolved data breach & broker exposures if a scan has been run // Otherwise, only show resolved data breaches dataPointValue: hasRunFreeScan - ? props.dataSummary.fixedSanitizedDataPoints.reduce( - (total, dataPointSummary) => { - return total + Object.values(dataPointSummary)[0]; - }, - 0, - ) + ? calculateSanitizedDataPoints(props.dataSummary.fixedSanitizedDataPoints) : props.dataSummary.dataBreachResolvedNum, // The resolved box would be active if // a user has run a free scan and they have resolved data breaches, and or brokers (count number of resolved data points) // if a user hasn't run a free scan but they have resolved data breaches (count number of resolved breach cards) activeState: (hasRunFreeScan && - props.dataSummary.fixedSanitizedDataPoints.length > 0) || + calculateSanitizedDataPoints( + props.dataSummary.fixedSanitizedDataPoints, + ) > 0) || (!hasRunFreeScan && props.dataSummary.dataBreachResolvedNum > 0), }; @@ -101,7 +99,9 @@ export const MonthlyActivityFreeEmail = ( preScan: !hasRunFreeScan && props.dataSummary.dataBreachUnresolvedNum === 0, postScan: hasRunFreeScan && - props.dataSummary.unresolvedSanitizedDataPoints.length === 0, + calculateSanitizedDataPoints( + props.dataSummary.unresolvedSanitizedDataPoints, + ) === 0, }; return (