Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(newletter): deprecate newsletter #12499

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions client/src/blog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { BlogImage, BlogPostMetadata } from "../../../libs/types/blog.js";

import "./index.scss";
import { Button } from "../ui/atoms/button";
import { SignUpSection as NewsletterSignUp } from "../newsletter";

interface BlogIndexData {
posts: BlogPostMetadata[];
Expand Down Expand Up @@ -105,7 +104,6 @@ function BlogIndex(props: HydrationData) {
})}
</section>
</main>
<NewsletterSignUp />
</>
);
}
2 changes: 0 additions & 2 deletions client/src/blog/post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "../../../libs/types/blog";
import { useDecorateCodeExamples, useRunSample } from "../document/hooks";
import { DEFAULT_LOCALE } from "../../../libs/constants";
import { SignUpSection as NewsletterSignUp } from "../newsletter";
import { TOC } from "../document/organisms/toc";
import { SidePlacement } from "../ui/organisms/placement";
import { PlayQueue } from "../playground/queue";
Expand Down Expand Up @@ -211,7 +210,6 @@ export function BlogPost(props: HydrationData) {
<RenderDocumentBody doc={doc} />
{blogMeta.links && <PreviousNext links={blogMeta.links} />}
</article>
<NewsletterSignUp />
<PlayQueue standalone={true} />
</main>
)}
Expand Down
93 changes: 10 additions & 83 deletions client/src/newsletter/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { createElement, useState } from "react";
import React, { createElement } from "react";

import { useIsServer, useLocale } from "../hooks";
import { Button } from "../ui/atoms/button";
import { MainContentContainer } from "../ui/atoms/page-content";
import { useUserData } from "../user-context";

Expand All @@ -10,7 +9,7 @@ import "./index.scss";
export function Newsletter() {
return (
<MainContentContainer className="section-newsletter">
<SignUpForm />
<SignUpForm sendUsersToSettings={true} />
</MainContentContainer>
);
}
Expand All @@ -19,98 +18,26 @@ function SignUpForm({ sendUsersToSettings = false, section = false }) {
const isServer = useIsServer();
const user = useUserData();
const locale = useLocale();
const [pending, setPending] = useState(false);
const [error, setError] = useState(false);
const [submitted, setSubmitted] = useState(false);
const [email, setEmail] = useState("");
const submit = async (event: React.FormEvent) => {
event.preventDefault();
setPending(true);
try {
const response = await fetch("/api/v1/newsletter", {
body: JSON.stringify({ email }),
method: "POST",
headers: {
"content-type": "application/json",
},
});
if (!response.ok) {
throw Error();
}
} catch {
setError(true);
setPending(false);
return;
}
setSubmitted(true);
};

return submitted ? (
<>
{createElement(section ? "h2" : "h1", null, "Thanks!")}
<p>
If you haven't previously confirmed a subscription to a Mozilla-related
newsletter, you may have to do so. Please check your inbox or your spam
filter for an email from us.
</p>
</>
) : (
return (
<>
{createElement(section ? "h2" : "h1", null, "Stay Informed with MDN")}
<p>We're decommissioning our MDN Plus newsletter.</p>
<p>
Get the MDN newsletter and never miss an update on the latest web
development trends, tips, and best practices.
<strong>
We will automatically unsubscribe you and purge all related data in
the near future.
</strong>
fiji-flo marked this conversation as resolved.
Show resolved Hide resolved
</p>
{sendUsersToSettings && user?.isAuthenticated && !isServer ? (
<p>
Sign up via the{" "}
Unsubscribe now up via the{" "}
<a href={`/${locale}/plus/settings#newsletter`} rel="_blank">
fiji-flo marked this conversation as resolved.
Show resolved Hide resolved
Settings Page.
</a>
</p>
) : (
<form className="mdn-form mdn-form-big" onSubmit={submit}>
<div className="mdn-form-item">
<label htmlFor="newsletter_email">Your email address:</label>

<input
type="email"
name="email"
required={true}
placeholder="[email protected]"
id="newsletter_email"
value={email}
onChange={(e) => setEmail(e.target.value)}
disabled={pending}
/>
</div>

<div className="mdn-form-item">
<label htmlFor="newsletter_privacy">
<input
type="checkbox"
id="newsletter_privacy"
name="privacy"
required={true}
disabled={pending}
/>{" "}
I’m okay with Mozilla handling my info as explained in this{" "}
<a
href="https://www.mozilla.org/en-US/privacy/websites/"
target="_blank"
rel="noreferrer"
>
Privacy Notice
</a>
</label>
</div>

<div className="mdn-form-item">
<Button buttonType="submit" isDisabled={pending || isServer}>
{error ? "Something went wrong, try again" : "Sign Up Now"}
</Button>
</div>
</form>
<></>
)}
</>
);
Expand Down
22 changes: 19 additions & 3 deletions client/src/settings/newsletter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,28 @@ export default function Newsletter() {
<ul>
<li>
<section aria-labelledby="mdn-plus-newsletter">
<h3 id="mdn-plus-newsletter">MDN Plus Newsletter</h3>
<h3 id="mdn-plus-newsletter">
<s>MDN Plus Newsletter</s> (Deprecated)
</h3>
<div className="setting-row">
<span>
Allow us to email you product updates, news, and more.
We're decommissioning our MDN Plus newsletter.
{enabled ? (
<>
{" "}
If you unsubscribe you cannot subscribe again. <br />
fiji-flo marked this conversation as resolved.
Show resolved Hide resolved
<strong>
We will automatically unsubscribe you and purge all
related data in the near future.
fiji-flo marked this conversation as resolved.
Show resolved Hide resolved
</strong>
</>
) : (
<></>
)}
</span>
{loading ? (
<Spinner extraClasses="loading" />
) : (
) : enabled ? (
<Switch
name="mdn_plus_newsletter"
checked={Boolean(enabled)}
Expand All @@ -49,6 +63,8 @@ export default function Newsletter() {
setLoading(false);
}}
></Switch>
) : (
<></>
)}
</div>
</section>
Expand Down
Loading