-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port breach alert email to new email template
- Loading branch information
Showing
12 changed files
with
317 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/emails/templates/breachAlert/BreachAlertEmail.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* 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/. */ | ||
|
||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { FC } from "react"; | ||
import { Props, BreachAlertEmail } from "./BreachAlertEmail"; | ||
import { StorybookEmailRenderer } from "../../StorybookEmailRenderer"; | ||
import { getL10n } from "../../../app/functions/l10n/storybookAndJest"; | ||
import { createRandomHibpListing } from "../../../apiMocks/mockData"; | ||
|
||
const meta: Meta<FC<Props>> = { | ||
title: "Emails/Breach alert", | ||
component: (props: Props) => ( | ||
<StorybookEmailRenderer> | ||
<BreachAlertEmail {...props} /> | ||
</StorybookEmailRenderer> | ||
), | ||
args: { | ||
l10n: getL10n("en"), | ||
utmCampaignId: "breach-alert", | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<FC<Props>>; | ||
|
||
export const BreachAlertEmailStory: Story = { | ||
name: "Breach alert", | ||
args: { | ||
breach: createRandomHibpListing(), | ||
breachedEmail: "example@example.com", | ||
}, | ||
}; |
45 changes: 45 additions & 0 deletions
45
src/emails/templates/breachAlert/BreachAlertEmail.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* 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/. */ | ||
|
||
import { it, expect } from "@jest/globals"; | ||
import { composeStory } from "@storybook/react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import Meta, { BreachAlertEmailStory } from "./BreachAlertEmail.stories"; | ||
import { createRandomHibpListing } from "../../../apiMocks/mockData"; | ||
|
||
it("lists compromised data", () => { | ||
const ComposedEmail = composeStory(BreachAlertEmailStory, Meta); | ||
render(<ComposedEmail />); | ||
|
||
const breachCard = screen.getByText("Compromised data:"); | ||
expect(breachCard).toBeInTheDocument(); | ||
}); | ||
|
||
it("displays a breach icon if available", () => { | ||
const ComposedEmail = composeStory(BreachAlertEmailStory, Meta); | ||
const { container } = render( | ||
<ComposedEmail | ||
breach={createRandomHibpListing({ | ||
FaviconUrl: "https://example.com/image.webp", | ||
})} | ||
/>, | ||
); | ||
|
||
expect( | ||
container.querySelector("img[src='https://example.com/image.webp']"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("does not display a breach icon if none is available", () => { | ||
const ComposedEmail = composeStory(BreachAlertEmailStory, Meta); | ||
const { container } = render( | ||
<ComposedEmail | ||
breach={createRandomHibpListing({ FaviconUrl: undefined })} | ||
/>, | ||
); | ||
|
||
expect( | ||
container.querySelector("img:not([src^='http://localhost'])"), | ||
).not.toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* 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/. */ | ||
|
||
import React from "react"; | ||
import { ExtendedReactLocalization } from "../../../app/functions/l10n"; | ||
import { EmailFooter } from "../EmailFooter"; | ||
import { EmailHeader } from "../EmailHeader"; | ||
import { HibpLikeDbBreach } from "../../../utils/hibp"; | ||
import { formatDate } from "../../../utils/formatDate"; | ||
import { getLocale } from "../../../app/functions/universal/getLocale"; | ||
|
||
export type Props = { | ||
l10n: ExtendedReactLocalization; | ||
breach: HibpLikeDbBreach; | ||
breachedEmail: string; | ||
utmCampaignId: string; | ||
}; | ||
|
||
export const BreachAlertEmail = (props: Props) => { | ||
const l10n = props.l10n; | ||
const listFormatter = new Intl.ListFormat(getLocale(l10n)); | ||
|
||
return ( | ||
<mjml> | ||
<mj-head> | ||
<mj-preview>{l10n.getString("email-spotted-new-breach")}</mj-preview> | ||
<mj-style> | ||
{` | ||
.metadata-heading { | ||
color: #5e5e72; | ||
} | ||
img.breach-logo { | ||
display: inline-block; | ||
} | ||
`} | ||
</mj-style> | ||
</mj-head> | ||
<mj-body> | ||
<EmailHeader l10n={l10n} utm_campaign={props.utmCampaignId} /> | ||
<mj-section padding="20px"> | ||
<mj-column> | ||
<mj-text align="center" font-size="16px" line-height="24px"> | ||
{l10n.getFragment("email-breach-detected-2", { | ||
vars: { "email-address": props.breachedEmail }, | ||
elems: { b: <b /> }, | ||
})} | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
<mj-wrapper border="1px solid #eee" text-align="center" padding="0"> | ||
<mj-section background-color="#eee"> | ||
<mj-column vertical-align="middle"> | ||
<mj-text | ||
font-size="18px" | ||
line-height="24px" | ||
align="center" | ||
height="32px" | ||
> | ||
<BreachLogo breach={props.breach} /> | ||
<span style={{ paddingInlineStart: "4px" }}> | ||
{props.breach.Title} | ||
</span> | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
<mj-section padding="20px"> | ||
<mj-column> | ||
<mj-text align="center" font-size="16px" padding="24px"> | ||
<p className="metadata-heading"> | ||
{l10n.getString("breach-added-label")} | ||
</p> | ||
<p> | ||
<b> | ||
{formatDate(props.breach.AddedDate, getLocale(props.l10n))} | ||
</b> | ||
</p> | ||
{Array.isArray(props.breach.DataClasses) && | ||
props.breach.DataClasses.length > 0 && ( | ||
<> | ||
<p className="metadata-heading"> | ||
{l10n.getString("compromised-data")} | ||
</p> | ||
<p> | ||
<b> | ||
{listFormatter.format( | ||
props.breach.DataClasses.map((classKey) => | ||
l10n.getString(classKey), | ||
), | ||
)} | ||
</b> | ||
</p> | ||
</> | ||
)} | ||
</mj-text> | ||
</mj-column> | ||
</mj-section> | ||
</mj-wrapper> | ||
<mj-section padding="20px"> | ||
<mj-column> | ||
<mj-button | ||
href={`${process.env.SERVER_URL}/user/dashboard/action-needed?utm_source=monitor-product&utm_medium=email&utm_campaign=${props.utmCampaignId}&utm_content=view-your-dashboard-us`} | ||
background-color="#0060DF" | ||
font-weight={600} | ||
font-size="15px" | ||
line-height="22px" | ||
> | ||
{l10n.getString("email-dashboard-cta")} | ||
</mj-button> | ||
</mj-column> | ||
</mj-section> | ||
<EmailFooter l10n={l10n} utm_campaign={props.utmCampaignId} /> | ||
</mj-body> | ||
</mjml> | ||
); | ||
}; | ||
|
||
const BreachLogo = (props: { breach: HibpLikeDbBreach }) => { | ||
if (props.breach.FaviconUrl) { | ||
return ( | ||
// eslint-disable-next-line @next/next/no-img-element | ||
<img | ||
src={props.breach.FaviconUrl} | ||
alt="" | ||
width="32px" | ||
height="32px" | ||
className="breach-logo" | ||
/> | ||
); | ||
} | ||
|
||
return null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.