Skip to content

Commit fe697db

Browse files
authored
Merge pull request #10 from treetips/feature/add_error_page
Add error page
2 parents 116ae46 + 84c9945 commit fe697db

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

constants/Page.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Color } from "@material-ui/core"
2-
import { blue, orange, pink } from "@material-ui/core/colors"
2+
import { blue, orange, pink, red } from "@material-ui/core/colors"
33
import { SvgIconProps } from "@material-ui/core/SvgIcon"
44
import HomeIcon from "@material-ui/icons/Home"
55
import InfoIcon from "@material-ui/icons/Info"
@@ -46,6 +46,16 @@ export class Page implements IEnum<Page> {
4646
InfoIcon,
4747
orange
4848
)
49+
public static readonly ERROR = new Page(
50+
99,
51+
"Error",
52+
"Error",
53+
"Error | sample",
54+
"Error.",
55+
"/error",
56+
InfoIcon,
57+
red
58+
)
4959

5060
/**
5161
* constructor

pages/_error.tsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Typography } from "@material-ui/core"
2+
import { createStyles, makeStyles, Theme } from "@material-ui/core/styles"
3+
import React from "react"
4+
import { AppContext } from "../components/AppContext"
5+
import { SpacingPaper } from "../components/atoms"
6+
import { HeaderArticleContainer } from "../components/organisms"
7+
import { Layout } from "../components/templates"
8+
import { Page } from "../constants"
9+
import { IPagePayload, PageActions } from "../store/page"
10+
11+
const useStyles = makeStyles((theme: Theme) =>
12+
createStyles({
13+
root: {},
14+
})
15+
)
16+
17+
interface IProps {
18+
httpStatusCode: number
19+
}
20+
21+
function Error(props: IProps) {
22+
const { httpStatusCode } = props
23+
const classes = useStyles(props)
24+
return (
25+
<Layout>
26+
<HeaderArticleContainer>
27+
<SpacingPaper>
28+
<Typography variant="h5">
29+
Http status code {httpStatusCode} error !
30+
</Typography>
31+
</SpacingPaper>
32+
</HeaderArticleContainer>
33+
</Layout>
34+
)
35+
}
36+
37+
/**
38+
* Server side rendering
39+
*/
40+
Error.getInitialProps = async (ctx: AppContext): Promise<IProps> => {
41+
const pagePayload: IPagePayload = {
42+
selectedPage: Page.ERROR,
43+
}
44+
ctx.store.dispatch({
45+
type: PageActions.changePage.toString(),
46+
payload: pagePayload,
47+
})
48+
return {
49+
httpStatusCode: ctx.res.statusCode,
50+
}
51+
}
52+
53+
export default Error

0 commit comments

Comments
 (0)