Skip to content

Commit

Permalink
MNTOR-3723 - Fix wrong state for users for email data point count
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Oct 28, 2024
1 parent 0da0296 commit 25387c8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
17 changes: 7 additions & 10 deletions src/emails/components/EmailDataPointCount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"
Expand Down Expand Up @@ -73,7 +66,9 @@ export const DataPointCount = (props: Props) => {
line-height="68px"
>
{hasRunFreeScan
? sumOfUnresolvedDataPoints
? calculateSanitizedDataPoints(
props.dataSummary.unresolvedSanitizedDataPoints,
)
: unresolvedDataBreaches}
</mj-text>
<mj-text
Expand All @@ -89,7 +84,9 @@ export const DataPointCount = (props: Props) => {
: "email-monthly-report-no-scan-results-data-points-label",
{
data_point_count: hasRunFreeScan
? sumOfUnresolvedDataPoints
? calculateSanitizedDataPoints(
props.dataSummary.unresolvedSanitizedDataPoints,
)
: unresolvedDataBreaches,
},
)}
Expand Down
18 changes: 18 additions & 0 deletions src/emails/functions/reduceSanitizedDataPoints.ts
Original file line number Diff line number Diff line change
@@ -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<string, number>) => {
const dataPointValue = Object.values(currentDataPoint)[0] as number;
return accumulatedValue + dataPointValue;
},
0,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
};

Expand All @@ -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 (
Expand Down

0 comments on commit 25387c8

Please sign in to comment.