From 5dca8192f6e49ee90eb035e84319a5f53d706ea1 Mon Sep 17 00:00:00 2001 From: Mario Souto <13791385+omariosouto@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:16:24 -0300 Subject: [PATCH 1/2] feat: add 404 page --- pages/404.tsx | 91 ++++++++++++++++++++ pages/pt-BR/path/[slug]/[activeCardSlug].tsx | 8 ++ pages/pt-BR/path/[slug]/index.tsx | 6 ++ 3 files changed, 105 insertions(+) create mode 100644 pages/404.tsx diff --git a/pages/404.tsx b/pages/404.tsx new file mode 100644 index 000000000..4444f5acc --- /dev/null +++ b/pages/404.tsx @@ -0,0 +1,91 @@ +import React from "react"; +import { Box, Link, Text } from "@src/components"; +import { SiteLocale } from "@src/gql_types"; +import { I18nProvider, useI18n } from "@src/infra/i18n"; + +const copyByLocale = { + [SiteLocale.PtBr]: { + "404.TITLE": "404", + "404.DESCRIPTION": "Página não encontrada", + }, + [SiteLocale.EnUs]: { + "404.TITLE": "404", + "404.DESCRIPTION": "Page not found", + }, + [SiteLocale.Es]: { + "404.TITLE": "404", + "404.DESCRIPTION": "Página no encontrada", + }, +}; + +export default function NotFoundScreen() { + const currentURL = globalThis?.location?.pathname || "/pt-BR"; + let locale; + + if (currentURL.includes("/en-US")) { + locale = SiteLocale.EnUs; + } + if (currentURL.includes("/es")) { + locale = SiteLocale.Es; + } + if (currentURL.includes("/pt-BR")) { + locale = SiteLocale.PtBr; + } + + return ( + + + + ); +} + +function Screen({ locale }: { locale: SiteLocale }) { + const i18n = useI18n(); + + return ( + + + + {i18n.content("404.TITLE")} + + + {i18n.content("404.DESCRIPTION")} + + + + ); +} diff --git a/pages/pt-BR/path/[slug]/[activeCardSlug].tsx b/pages/pt-BR/path/[slug]/[activeCardSlug].tsx index 7209904c6..13720f64b 100644 --- a/pages/pt-BR/path/[slug]/[activeCardSlug].tsx +++ b/pages/pt-BR/path/[slug]/[activeCardSlug].tsx @@ -6,6 +6,13 @@ export { default } from "./index"; export const getStaticProps = async (ctx) => { const staticProps = await getStaticPropsBase(ctx); + + if (!staticProps.props.guide) { + return { + notFound: true, + }; + } + const cards = [ ...staticProps.props.guide.collaborations[0].cards, ...staticProps.props.guide.collaborations[1].cards, @@ -20,6 +27,7 @@ export const getStaticProps = async (ctx) => { const title = card?.item?.name || "Error"; const categoryTitle = staticProps.props.guide.name; + return { ...staticProps, props: { diff --git a/pages/pt-BR/path/[slug]/index.tsx b/pages/pt-BR/path/[slug]/index.tsx index bdcbe2d1e..998bfb60e 100644 --- a/pages/pt-BR/path/[slug]/index.tsx +++ b/pages/pt-BR/path/[slug]/index.tsx @@ -23,6 +23,12 @@ export const getStaticProps = async ({ params, ...ctx }: any) => { }, }); + if (!data.guide) { + return { + notFound: true, + }; + } + return withLocaleContent( { props: { From a9ee01b75651b61837db304bac1fcb23abe39c87 Mon Sep 17 00:00:00 2001 From: Mario Souto <13791385+omariosouto@users.noreply.github.com> Date: Thu, 20 Jun 2024 22:22:19 -0300 Subject: [PATCH 2/2] update --- pages/pt-BR/path/[slug]/[activeCardSlug].tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/pt-BR/path/[slug]/[activeCardSlug].tsx b/pages/pt-BR/path/[slug]/[activeCardSlug].tsx index 13720f64b..f8780769d 100644 --- a/pages/pt-BR/path/[slug]/[activeCardSlug].tsx +++ b/pages/pt-BR/path/[slug]/[activeCardSlug].tsx @@ -5,9 +5,9 @@ import { AllPathsForActiveCardDocument, SiteLocale } from "@src/gql_types"; export { default } from "./index"; export const getStaticProps = async (ctx) => { - const staticProps = await getStaticPropsBase(ctx); + const staticProps = (await getStaticPropsBase(ctx)) as any; - if (!staticProps.props.guide) { + if (staticProps.notFound) { return { notFound: true, };