Skip to content

Commit

Permalink
extract data from the right table
Browse files Browse the repository at this point in the history
  • Loading branch information
codemist committed Sep 12, 2024
1 parent f9e6186 commit e2d14bd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 30 deletions.
5 changes: 0 additions & 5 deletions locales-pending/settings-premium.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions locales/en/settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
};

Expand All @@ -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";
Expand Down Expand Up @@ -175,27 +180,25 @@ export const AlertAddressForm = (props: Props) => {
</AlertAddressRadio>
</AlertAddressContext.Provider>
)}

{props.enabledFeatureFlags.includes("MonthlyActivityEmail") &&
hasPremium(props.user) && (
<ActivateEmailsCheckbox
isSelected={activateMonthlyMonitorReport}
onChange={handleMonthlyMonitorReportToggle}
>
<div>
<b>
{l10n.getString(
"settings-alert-preferences-allow-monthly-monitor-plus-report-title",
)}
</b>
<p>
{l10n.getString(
"settings-alert-preferences-allow-monthly-monitor-plus-report-subtitle",
)}
</p>
</div>
</ActivateEmailsCheckbox>
)}
{props.enabledFeatureFlags.includes("MonthlyActivityEmail") && (
<ActivateEmailsCheckbox
isSelected={activateMonthlyMonitorReport}
onChange={handleMonthlyMonitorReportToggle}
>
<div>
<b>
{l10n.getString(
"settings-alert-preferences-allow-monthly-monitor-report-title",
)}
</b>
<p>
{l10n.getString(
"settings-alert-preferences-allow-monthly-monitor-report-subtitle",
)}
</p>
</div>
</ActivateEmailsCheckbox>
)}
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -97,6 +99,7 @@ export const SettingsView = (props: Props) => {
<AlertAddressForm
user={props.user}
subscriber={props.subscriber}
data={props.data}
enabledFeatureFlags={props.enabledFeatureFlags}
/>
{hasPremium(props.user) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/v1/user/update-comm-option/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion src/db/tables/subscriber_email_preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface SubscriberPlusEmailPreferencesInput {
monthly_monitor_report_at?: Date;
}

interface SubscriberEmailPreferencesOutput {
export interface SubscriberEmailPreferencesOutput {
id?: number;
primary_email?: string;
unsubscribe_token?: string;
Expand Down

0 comments on commit e2d14bd

Please sign in to comment.