Skip to content

Commit b49b137

Browse files
committed
Improve not found page
1 parent c58b0ac commit b49b137

4 files changed

Lines changed: 84 additions & 26 deletions

File tree

frontend/src/components/Pages/FlotillaSite.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../NavigationMenu/NavigationMenuPages'
1414
import { InfoPage } from './InfoPage'
1515
import { PageRouter } from './PageRouter'
16+
import { PageNotFound } from './NotFoundPage'
1617

1718
export const FlotillaSite = () => {
1819
const frontPageTabOptions = Object.values(TabNames)
@@ -51,6 +52,7 @@ export const FlotillaSite = () => {
5152
<Route path={`${config.FRONTEND_BASE_ROUTE}/auto-schedule`} element={<AutoSchedulePage />} />
5253
<Route path={`${config.FRONTEND_BASE_ROUTE}/robots`} element={<RobotStatusPage />} />
5354
<Route path={`${config.FRONTEND_BASE_ROUTE}/info`} element={<InfoPage />} />
55+
<Route path="*" element={<PageNotFound />} />
5456
</Routes>
5557
</BrowserRouter>
5658
</APIUpdater>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { useNavigate } from 'react-router-dom'
2+
import { Button, Typography } from '@equinor/eds-core-react'
3+
import styled from 'styled-components'
4+
import notfound from 'mediaAssets/404notfound.png'
5+
import { config } from 'config'
6+
import { StyledPage } from 'components/Styles/StyledComponents'
7+
import { Header } from 'components/Header/Header'
8+
9+
const StyledPageContent = styled.div`
10+
position: absolute;
11+
top: 50%;
12+
left: 50%;
13+
transform: translate(-50%, -50%);
14+
display: flex;
15+
flex-direction: row;
16+
align-items: center;
17+
18+
@media (max-width: 600px) {
19+
flex-direction: column;
20+
}
21+
`
22+
const StyledTypography = styled(Typography)`
23+
text-align: center;
24+
gap: 10px;
25+
`
26+
const StyledImage = styled.img`
27+
height: 500px;
28+
padding: 0px 10px;
29+
30+
@media (max-width: 600px) {
31+
max-width: 50vw;
32+
height: auto;
33+
padding: 5px;
34+
}
35+
`
36+
const StyledActions = styled.div`
37+
display: flex;
38+
flex-direction: column;
39+
align-items: center;
40+
padding: 0px 10px;
41+
gap: 20px;
42+
`
43+
const StyledButton = styled(Button)`
44+
width: 200px;
45+
justify-content: center;
46+
`
47+
48+
export const PageNotFound = () => {
49+
const navigate = useNavigate()
50+
return (
51+
<>
52+
<Header page={'404'} />
53+
<StyledPage>
54+
<StyledPageContent>
55+
<StyledImage src={notfound} />
56+
<StyledActions>
57+
<StyledTypography variant="h3">
58+
{"We couldn't find the page you're looking for."}
59+
</StyledTypography>
60+
<StyledButton
61+
color="secondary"
62+
onClick={() => {
63+
navigate(`${config.FRONTEND_BASE_ROUTE}/front-page`)
64+
}}
65+
>
66+
{"Let's go back"}
67+
</StyledButton>
68+
</StyledActions>
69+
</StyledPageContent>
70+
</StyledPage>
71+
</>
72+
)
73+
}

frontend/src/components/Pages/PageRouter.tsx

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,20 @@ import { RobotPage } from './RobotPage/RobotPage'
44
import { MissionDefinitionPage } from './MissionDefinitionPage/MissionDefinitionPage'
55
import { Typography } from '@equinor/eds-core-react'
66
import styled from 'styled-components'
7+
import { PageNotFound } from './NotFoundPage'
78

8-
const StyledTypography = styled.div`
9-
position: absolute;
10-
top: 30%;
11-
left: 50%;
12-
transform: translate(-70%, -50%);
13-
display: flex;
14-
flex-direction: column;
15-
align-items: center;
16-
justify-content: center;
9+
const StyledTypography = styled(Typography)`
10+
text-align: center;
1711
gap: 10px;
1812
`
13+
1914
export const PageRouter = () => {
2015
const { page } = useParams()
2116
if (!page) return InvalidRoute()
2217

2318
const [pageName, id] = page.split(/-(.+)/)
2419

25-
if (ValidateUUID(id)) return PageNotFound()
20+
if (!ValidateUUID(id)) return PageNotFound()
2621

2722
switch (pageName) {
2823
case 'mission':
@@ -35,24 +30,12 @@ export const PageRouter = () => {
3530
return PageNotFound()
3631
}
3732
}
38-
const ValidateUUID = (id: string) => {
39-
return (id.match(/-/g) || []).length > 4
40-
}
4133

42-
const PageNotFound = () => {
43-
return (
44-
<StyledTypography>
45-
<Typography variant="h1"> {'404'} </Typography>
46-
<Typography variant="h2">{'Page Not Found'}</Typography>
47-
<Typography variant="body_short">{"We could't find the page you're looking for."} </Typography>
48-
</StyledTypography>
49-
)
34+
const ValidateUUID = (id: string) => {
35+
const regex = /^[\da-f]{8}-([\da-f]{4}-){3}[\da-f]{12}$/i
36+
return regex.test(id)
5037
}
5138

5239
const InvalidRoute = () => {
53-
return (
54-
<StyledTypography>
55-
<Typography variant="body_short">Invalid route</Typography>
56-
</StyledTypography>
57-
)
40+
return <StyledTypography variant="body_short">Invalid route</StyledTypography>
5841
}
1.01 MB
Loading

0 commit comments

Comments
 (0)