Skip to content

Commit

Permalink
error refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dlopezalvas committed Nov 15, 2023
1 parent be5661b commit 3e7fc97
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 52 deletions.
6 changes: 0 additions & 6 deletions locales/en-us/pageNotFound.json

This file was deleted.

8 changes: 8 additions & 0 deletions locales/en-us/pbError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"home": "Go to home page",
"errorOcurred": "An error occurred (✖╭╮✖)",
"pageNotFound": {
"title": "Page not found",
"text": "The page you are trying to access does not exist."
}
}
6 changes: 0 additions & 6 deletions locales/es-ar/pageNotFound.json

This file was deleted.

8 changes: 8 additions & 0 deletions locales/es-ar/pbError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"home": "Ir al inicio",
"errorOcurred": "Ocurrió un error (✖╭╮✖)",
"pageNotFound": {
"title": "Página no encontrada",
"text": "La página a la que intentás acceder no existe."
}
}
6 changes: 0 additions & 6 deletions locales/pt-br/pageNotFound.json

This file was deleted.

8 changes: 8 additions & 0 deletions locales/pt-br/pbError.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"home": "Vá para iniciar",
"errorOcurred": "Um erro ocorreu (✖╭╮✖)",
"pageNotFound": {
"title": "Página não encontrada",
"text": "A página que você está tentando acessar não existe."
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useEffect } from 'react';
import './App.css';
import { createHashRouter, RouterProvider, Outlet } from "react-router-dom";
import { Home } from './components/home/Home';
import { PBError } from './components/PBError';
import { PBError } from './components/pageNotFound/PBError';
import { ChallengeById, ChallengeByName } from './components/ChallengeView';
import { BookView } from './components/book/BookView';
import { ImportedChallengeView } from './components/ImportedChallengeView';
Expand Down
11 changes: 0 additions & 11 deletions src/components/PBError.tsx

This file was deleted.

28 changes: 28 additions & 0 deletions src/components/pageNotFound/PBError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Typography, Button, Stack } from "@mui/material"
import { Link, useRouteError } from "react-router-dom";
import { useTranslation } from "react-i18next";
import styles from "./PBError.module.css"
import { Header } from "../header/Header";

type PbErrorProps = {
title?: string,
error?: string,
}

export const PBError = (props: PbErrorProps) =>{
const {t} = useTranslation("pbError")

const error = useRouteError() as any

return <>
<Header/>
<Stack direction='column' alignItems='center'>
<Typography className={styles.title} variant="h4">{props.title ? props.title : t("errorOcurred")}</Typography>
<img alt="capy" className={styles.image} src='imagenes/capy_error.png' />
<Typography className={styles.text} variant="h6">{props.error ? props.error : error.message}</Typography>
<Link to="/">
<Button variant="contained" color="success" >{t("home")}</Button>
</Link>
</Stack>
</>
}
26 changes: 4 additions & 22 deletions src/components/pageNotFound/PageNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,8 @@
import { Typography, Button, Stack } from "@mui/material"
import { Link } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Header } from "../header/Header"
import styles from "./pageNotFound.module.css"
import { PBError } from "./PBError";

type PageNotFoundProps = {
title?: string,
error?: string,
}
export const PageNotFound = () =>{
const {t} = useTranslation("pbError")

export const PageNotFound = (props: PageNotFoundProps) =>{
const {t} = useTranslation("pageNotFound")

return <>
<Header/>
<Stack direction='column' alignItems='center'>
<Typography className={styles.title} variant="h4">{props.title ? props.title : t("title")}</Typography>
<img alt="capy" className={styles.image} src='imagenes/capy_error.png' />
<Typography className={styles.text} variant="h6">{props.error ? props.error : t("text")}</Typography>
<Link to="/">
<Button variant="contained" color="success" >{t("home")}</Button>
</Link>
</Stack>
</>
return <PBError title={t("pageNotFound.title")!} error={t("pageNotFound.text")!}/>
}

0 comments on commit 3e7fc97

Please sign in to comment.