diff --git a/frontend/src/app/[locale]/subscribe/SubscribeForm.tsx b/frontend/src/app/[locale]/subscribe/SubscribeForm.tsx deleted file mode 100644 index f66102763..000000000 --- a/frontend/src/app/[locale]/subscribe/SubscribeForm.tsx +++ /dev/null @@ -1,217 +0,0 @@ -"use client"; -import { SUBSCRIBE_CONFIRMATION } from "src/constants/breadcrumbs"; -import { ExternalRoutes } from "src/constants/routes"; - -import { useRouter } from "next/navigation"; -import { useState } from "react"; -import { - Alert, - Button, - ErrorMessage, - FormGroup, - Label, - TextInput, -} from "@trussworks/react-uswds"; - -import { Data } from "src/pages/api/subscribe"; -import { useTranslations } from "next-intl"; - -export default function SubscribeForm() { - const t = useTranslations("Subscribe"); - - const router = useRouter(); - const email = ExternalRoutes.EMAIL_SIMPLERGRANTSGOV; - - const [formSubmitted, setFormSubmitted] = useState(false); - - const [formData, setFormData] = useState({ - name: "", - LastName: "", - email: "", - hp: "", - }); - - const [sendyError, setSendyError] = useState(""); - const [erroredEmail, setErroredEmail] = useState(""); - - const validateField = (fieldName: string) => { - // returns the string "valid" or the i18n key for the error message - const emailRegex = - /^(\D)+(\w)*((\.(\w)+)?)+@(\D)+(\w)*((\.(\D)+(\w)*)+)?(\.)[a-z]{2,}$/g; - if (fieldName === "name" && formData.name === "") - return t("errors.missing_name"); - if (fieldName === "email" && formData.email === "") - return t("errors.missing_email"); - if (fieldName === "email" && !emailRegex.test(formData.email)) - return t("errors.invalid_email"); - return "valid"; - }; - - const showError = (fieldName: string): boolean => - formSubmitted && validateField(fieldName) !== "valid"; - - const handleInput = (e: React.ChangeEvent) => { - const fieldName = e.target.name; - const fieldValue = e.target.value; - - setFormData((prevState) => ({ - ...prevState, - [fieldName]: fieldValue, - })); - }; - - const submitForm = async () => { - const formURL = "api/subscribe"; - if (validateField("email") !== "valid" || validateField("name") !== "valid") - return; - - const res = await fetch(formURL, { - method: "POST", - body: JSON.stringify(formData), - headers: { - Accept: "application/json", - }, - }); - - if (res.ok) { - const { message } = (await res.json()) as Data; - router.push(`${SUBSCRIBE_CONFIRMATION.path}?sendy=${message as string}`); - return setSendyError(""); - } else { - const { error } = (await res.json()) as Data; - console.error("client error", error); - setErroredEmail(formData.email); - return setSendyError(error || ""); - } - }; - - const handleSubmit = (e: React.FormEvent) => { - e.preventDefault(); - setFormSubmitted(true); - submitForm().catch((err) => { - console.error("catch block", err); - }); - }; - - return ( -
- {sendyError ? ( - - {t.rich( - sendyError === "Already subscribed." - ? "errors.already_subscribed" - : "errors.sendy", - { - email: (chunks) => ( - - {chunks} - - ), - sendy_error: (chunks) => ( - - {chunks} - - ), - email_address: (chunks) => ( - - {chunks} - - ), - }, - )} - - ) : ( - <> - )} - - - {showError("name") ? ( - - {validateField("name")} - - ) : ( - <> - )} - - - - - - - {showError("email") ? ( - - {validateField("email")} - - ) : ( - <> - )} - - -
- - -
- - - ); -} diff --git a/frontend/src/app/[locale]/subscribe/confirmation/page.tsx b/frontend/src/app/[locale]/subscribe/confirmation/page.tsx deleted file mode 100644 index 9a91a3e21..000000000 --- a/frontend/src/app/[locale]/subscribe/confirmation/page.tsx +++ /dev/null @@ -1,66 +0,0 @@ -import { SUBSCRIBE_CONFIRMATION_CRUMBS } from "src/constants/breadcrumbs"; - -import Link from "next/link"; -import { Grid, GridContainer } from "@trussworks/react-uswds"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "src/components/BetaAlert"; -import { useTranslations } from "next-intl"; -import { Metadata } from "next"; -import { getTranslations } from "next-intl/server"; - -export async function generateMetadata() { - const t = await getTranslations({ locale: "en" }); - const meta: Metadata = { - title: t("Subscribe.page_title"), - description: t("Index.meta_description"), - }; - - return meta; -} - -export default function SubscribeConfirmation() { - const t = useTranslations("Subscribe_confirmation"); - - return ( - <> - - - - - -

- {t("title")} -

-

- {t("intro")} -

- - -

{t("paragraph_1")}

-
- -

- {t("heading")} -

-

- {t.rich("paragraph_2", { - strong: (chunks) => {chunks}, - "process-link": (chunks) => ( - {chunks} - ), - "research-link": (chunks) => ( - {chunks} - ), - })} -

-
-
-
- -

{t("disclaimer")}

-
- - ); -} diff --git a/frontend/src/app/[locale]/subscribe/page.tsx b/frontend/src/app/[locale]/subscribe/page.tsx deleted file mode 100644 index 080aaed5a..000000000 --- a/frontend/src/app/[locale]/subscribe/page.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { NEWSLETTER_CRUMBS } from "src/constants/breadcrumbs"; - -import { Grid, GridContainer } from "@trussworks/react-uswds"; -import pick from "lodash/pick"; -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "src/components/BetaAlert"; -import NewsletterForm from "src/app/[locale]/newsletter/NewsletterForm"; -import { Metadata } from "next"; -import { getTranslations } from "next-intl/server"; -import { - useTranslations, - useMessages, - NextIntlClientProvider, -} from "next-intl"; - -export async function generateMetadata() { - const t = await getTranslations({ locale: "en" }); - const meta: Metadata = { - title: t("Newsletter.page_title"), - description: t("Index.meta_description"), - }; - - return meta; -} - -export default function Newsletter() { - const t = useTranslations("Newsletter"); - const messages = useMessages(); - - return ( - <> - - - - - -

- {t("title")} -

-

- {t("intro")} -

- - -

{t("paragraph_1")}

- {t.rich("list", { - ul: (chunks) => ( -
    - {chunks} -
- ), - li: (chunks) =>
  • {chunks}
  • , - })} -
    - - - - - -
    -
    - -

    {t("disclaimer")}

    -
    - - ); -} diff --git a/frontend/src/app/[locale]/subscribe/unsubscribe/page.tsx b/frontend/src/app/[locale]/subscribe/unsubscribe/page.tsx deleted file mode 100644 index 9a095211a..000000000 --- a/frontend/src/app/[locale]/subscribe/unsubscribe/page.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import { NEWSLETTER_UNSUBSCRIBE_CRUMBS } from "src/constants/breadcrumbs"; - -import Link from "next/link"; -import { Grid, GridContainer } from "@trussworks/react-uswds"; - -import Breadcrumbs from "src/components/Breadcrumbs"; -import PageSEO from "src/components/PageSEO"; -import BetaAlert from "src/components/BetaAlert"; -import { useTranslations } from "next-intl"; -import { Metadata } from "next"; -import { getTranslations } from "next-intl/server"; - -export async function generateMetadata() { - const t = await getTranslations({ locale: "en" }); - const meta: Metadata = { - title: t("Newsletter.page_title"), - description: t("Index.meta_description"), - }; - - return meta; -} - -export default function NewsletterUnsubscribe() { - const t = useTranslations("Newsletter_unsubscribe"); - - return ( - <> - - - - - -

    - {t("title")} -

    -

    - {t("intro")} -

    - - -

    {t("paragraph_1")}

    - - {t("button_resub")} - -
    - -

    - {t("heading")} -

    -

    - {t.rich("paragraph_2", { - strong: (chunks) => {chunks}, - "process-link": (chunks) => ( - {chunks} - ), - "research-link": (chunks) => ( - {chunks} - ), - })} -

    -
    -
    -
    - -

    {t("disclaimer")}

    -
    - - ); -}