Skip to content

Commit

Permalink
fix up new pages with translations and meta
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-s-nava committed Jan 9, 2025
1 parent d8bc746 commit 8e20429
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 26 deletions.
14 changes: 0 additions & 14 deletions frontend/src/app/[locale]/error.tsx

This file was deleted.

25 changes: 20 additions & 5 deletions frontend/src/app/[locale]/error/page.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
"use client";
import { Metadata } from "next";

import { useTranslations } from "next-intl";
import { getTranslations } from "next-intl/server";
import { GridContainer } from "@trussworks/react-uswds";

const Unauthorized = () => {
import ServerErrorAlert from "src/components/ServerErrorAlert";

export async function generateMetadata() {
const t = await getTranslations();
const meta: Metadata = {
title: t("ErrorPages.generic_error.page_title"),
description: t("Index.meta_description"),
};
return meta;
}

// not a NextJS error page - this is here to be redirected to manually in cases
// where Next's error handling situation doesn't quite do what we need.
const TopLevelError = () => {
const t = useTranslations("Errors");
return (
<GridContainer>
<h3>Error</h3>
<div>Oops, something went wrong. Please try again.</div>
<ServerErrorAlert callToAction={t("try_again")} />
</GridContainer>
);
};

export default Unauthorized;
export default TopLevelError;
2 changes: 1 addition & 1 deletion frontend/src/app/[locale]/not-found.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import BetaAlert from "src/components/BetaAlert";
export async function generateMetadata() {
const t = await getTranslations();
const meta: Metadata = {
title: t("ErrorPages.page_not_found.title"),
title: t("ErrorPages.page_not_found.page_title"),
description: t("Index.meta_description"),
};
return meta;
Expand Down
21 changes: 17 additions & 4 deletions frontend/src/app/[locale]/unauthorized/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
"use client";
import { Metadata } from "next";

import { GridContainer } from "@trussworks/react-uswds";
import { useTranslations } from "next-intl";
import { getTranslations } from "next-intl/server";
import { Alert, GridContainer } from "@trussworks/react-uswds";

export async function generateMetadata() {
const t = await getTranslations();
const meta: Metadata = {
title: t("ErrorPages.unauthorized.page_title"),
description: t("Index.meta_description"),
};
return meta;
}

const Unauthorized = () => {
const t = useTranslations("Errors");
return (
<GridContainer>
<h3>Unauthorized</h3>
<div>Unable to log in</div>
<Alert type="error" heading={t("unauthorized")} headingLevel="h4">
{t("authorization_fail")}
</Alert>
</GridContainer>
);
};
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/i18n/messages/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,14 @@ export const messages = {
"The Simpler.Grants.gov email subscriptions are powered by the Sendy data service. Personal information is not stored within Simpler.Grants.gov.",
},
ErrorPages: {
page_title: "Page Not Found | Simpler.Grants.gov",
generic_error: {
page_title: "Error | Simpler.Grants.gov",
},
unauthorized: {
page_title: "Unauthorized | Simpler.Grants.gov",
},
page_not_found: {
page_title: "Page Not Found | Simpler.Grants.gov",
title: "Oops! Page Not Found",
message_content_1:
"The page you have requested cannot be displayed because it does not exist, has been moved, or the server has been instructed not to let you view it. There is nothing to see here.",
Expand Down Expand Up @@ -521,6 +527,9 @@ export const messages = {
Errors: {
heading: "We're sorry.",
generic_message: "There seems to have been an error.",
try_again: "Please try again.",
unauthorized: "Unauthorized",
authorization_fail: "Login or user authorization failed. Please try again.",
},
Search: {
title: "Search Funding Opportunities | Simpler.Grants.gov",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function middleware(request: NextRequest): NextResponse {
request,
i18nMiddleware(request),
);
// in Next 15 there is an experimantal `unauthorized` function that will send a 401
// in Next 15 there is an experimental `unauthorized` function that will send a 401
// code to the client and display an unauthorized page
// see https://nextjs.org/docs/app/api-reference/functions/unauthorized
// For now we can set status codes on auth redirect errors here
Expand Down

0 comments on commit 8e20429

Please sign in to comment.