From e2d14bd6b3bbd70875a68923fd7542d767dae0d0 Mon Sep 17 00:00:00 2001 From: Kaitlyn Date: Fri, 30 Aug 2024 08:57:22 -0400 Subject: [PATCH] extract data from the right table --- locales-pending/settings-premium.ftl | 5 -- locales/en/settings.ftl | 5 ++ .../(dashboard)/settings/AlertAddressForm.tsx | 49 ++++++++++--------- .../user/(dashboard)/settings/View.tsx | 3 ++ .../user/(dashboard)/settings/page.tsx | 2 +- .../api/v1/user/update-comm-option/route.ts | 2 + src/db/tables/subscriber_email_preferences.ts | 2 +- 7 files changed, 38 insertions(+), 30 deletions(-) diff --git a/locales-pending/settings-premium.ftl b/locales-pending/settings-premium.ftl index db666e8ceb4..92d2d42f8f8 100644 --- a/locales-pending/settings-premium.ftl +++ b/locales-pending/settings-premium.ftl @@ -2,11 +2,6 @@ # 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/. -## Email preferences - -settings-alert-preferences-allow-monthly-monitor-plus-report-title = Monthly { -brand-monitor-plus } report -settings-alert-preferences-allow-monthly-monitor-plus-report-subtitle = A monthly update of new exposures, what’s been fixed, and what needs your attention. - ## Cancel Plus subscription settings-cancel-plus-title = Cancel { -brand-monitor-plus } subscription diff --git a/locales/en/settings.ftl b/locales/en/settings.ftl index 0433c420f0f..efaec1b6780 100644 --- a/locales/en/settings.ftl +++ b/locales/en/settings.ftl @@ -58,3 +58,8 @@ settings-delete-monitor-free-account-dialog-cta-label = Delete account settings-delete-monitor-free-account-dialog-cancel-button-label = Never mind, take me back settings-delete-monitor-account-confirmation-toast-label-2 = Your { -brand-monitor } account is now deleted. settings-delete-monitor-account-confirmation-toast-dismiss-label = Dismiss + +## Monthly Monitor Report + +settings-alert-preferences-allow-monthly-monitor-report-title = Monthly { -brand-monitor } report +settings-alert-preferences-allow-monthly-monitor-report-subtitle = A monthly update of new exposures, what’s been fixed, and what needs your attention. diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/AlertAddressForm.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/AlertAddressForm.tsx index b4f0a6074b6..a90259eb12c 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/AlertAddressForm.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/AlertAddressForm.tsx @@ -29,13 +29,15 @@ import { VisuallyHidden } from "../../../../../../components/server/VisuallyHidd import { useSession } from "next-auth/react"; import { FeatureFlagName } from "../../../../../../../db/tables/featureFlags"; import { Session } from "next-auth"; -import { hasPremium } from "../../../../../../functions/universal/user"; import { useRouter } from "next/navigation"; import { SubscriberRow } from "knex/types/tables"; +import { SubscriberEmailPreferencesOutput } from "../../../../../../../db/tables/subscriber_email_preferences"; +import { hasPremium } from "../../../../../../functions/universal/user"; export type Props = { user: Session["user"]; subscriber: SubscriberRow; + data: SubscriberEmailPreferencesOutput; enabledFeatureFlags: FeatureFlagName[]; }; @@ -48,7 +50,10 @@ export const AlertAddressForm = (props: Props) => { const breachAlertsEmailsAllowed = props.subscriber.all_emails_to_primary; - const monitorReportAllowed = props.subscriber.monthly_monitor_report; + // Extract monthly report preference from the right column + const monitorReportAllowed = hasPremium(props.user) + ? props.data.monthly_monitor_report + : props.data.monthly_monitor_report_free; const defaultActivateAlertEmail = typeof breachAlertsEmailsAllowed === "boolean"; @@ -175,27 +180,25 @@ export const AlertAddressForm = (props: Props) => { )} - - {props.enabledFeatureFlags.includes("MonthlyActivityEmail") && - hasPremium(props.user) && ( - -
- - {l10n.getString( - "settings-alert-preferences-allow-monthly-monitor-plus-report-title", - )} - -

- {l10n.getString( - "settings-alert-preferences-allow-monthly-monitor-plus-report-subtitle", - )} -

-
-
- )} + {props.enabledFeatureFlags.includes("MonthlyActivityEmail") && ( + +
+ + {l10n.getString( + "settings-alert-preferences-allow-monthly-monitor-report-title", + )} + +

+ {l10n.getString( + "settings-alert-preferences-allow-monthly-monitor-report-subtitle", + )} +

+
+
+ )} ); diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/View.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/View.tsx index bcec42408bc..cbf66ee5a1c 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/View.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/View.tsx @@ -22,11 +22,13 @@ import { DeleteAccountButton } from "./DeleteAccountButton"; import { FeatureFlagName } from "../../../../../../../db/tables/featureFlags"; import { CancelFlow } from "./CancelFlow"; import { ExperimentData } from "../../../../../../../telemetry/generated/nimbus/experiments"; +import { SubscriberEmailPreferencesOutput } from "../../../../../../../db/tables/subscriber_email_preferences"; export type Props = { l10n: ExtendedReactLocalization; user: Session["user"]; subscriber: SubscriberRow; + data: SubscriberEmailPreferencesOutput; monthlySubscriptionUrl: string; yearlySubscriptionUrl: string; subscriptionBillingAmount: { @@ -97,6 +99,7 @@ export const SettingsView = (props: Props) => { {hasPremium(props.user) && ( diff --git a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/page.tsx b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/page.tsx index 899f430665e..efa57e875fe 100644 --- a/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/page.tsx +++ b/src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/page.tsx @@ -105,7 +105,7 @@ export default async function SettingsPage({ searchParams }: Props) { l10n={getL10n()} user={session.user} subscriber={userData} - // emailPreference={emailPreference} + data={settingsData} emailAddresses={emailAddresses} breachCountByEmailAddress={breachCountByEmailAddress} fxaSettingsUrl={fxaSettingsUrl} diff --git a/src/app/api/v1/user/update-comm-option/route.ts b/src/app/api/v1/user/update-comm-option/route.ts index 46d7612153c..0e53060490d 100644 --- a/src/app/api/v1/user/update-comm-option/route.ts +++ b/src/app/api/v1/user/update-comm-option/route.ts @@ -31,12 +31,14 @@ export async function POST(req: NextRequest) { monthlyMonitorReport, }: EmailUpdateCommOptionRequest = await req.json(); const subscriber = await getSubscriberByFxaUid(token.subscriber?.fxa_uid); + if (!subscriber) { throw new Error("No subscriber found for current session."); } // "null" = Do not send instant notifications. Newly added in MNTOR-1368 // "affected" = Send breach alerts to the corresponding affected emails. // "primary" = Send all breach alerts to user's primary email address. + let allEmailsToPrimary; switch (instantBreachAlerts) { case "primary": diff --git a/src/db/tables/subscriber_email_preferences.ts b/src/db/tables/subscriber_email_preferences.ts index 453bcf41157..3f69f758028 100644 --- a/src/db/tables/subscriber_email_preferences.ts +++ b/src/db/tables/subscriber_email_preferences.ts @@ -21,7 +21,7 @@ interface SubscriberPlusEmailPreferencesInput { monthly_monitor_report_at?: Date; } -interface SubscriberEmailPreferencesOutput { +export interface SubscriberEmailPreferencesOutput { id?: number; primary_email?: string; unsubscribe_token?: string;