Skip to content

Commit

Permalink
feat(page): add global error and not-found pages
Browse files Browse the repository at this point in the history
  • Loading branch information
jwinr committed Sep 22, 2024
1 parent 0791c9a commit b12ad06
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 11 deletions.
24 changes: 13 additions & 11 deletions next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/** @type {import('next').NextConfig} */

export function webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})

return config
}
export const compiler = {
styledComponents: true,
const nextConfig = {
webpack(config) {
config.module.rules.push({
test: /\.svg$/,
use: ['@svgr/webpack'],
})
return config
},
compiler: {
styledComponents: true,
},
}

export default nextConfig
1 change: 1 addition & 0 deletions public/images/spool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use client'

import { useEffect } from 'react'

export default function Error({
error,
reset,
}: {
error: Error & { digest?: string }
reset: () => void
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error)
}, [error])

return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
)
}
103 changes: 103 additions & 0 deletions src/app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use client'

import styled from 'styled-components'
import Link from 'next/link'
import Spool from '@/public/images/spool.svg'

const Container = styled.main`
display: flex;
flex-direction: column;
padding: 80px;
height: 100%;
max-width: 1200px;
margin: 0 auto;
position: relative;
&::before,
&::after {
content: '';
position: absolute;
top: 0;
bottom: 0;
width: 1px;
background: repeating-linear-gradient(
to bottom,
transparent 0,
transparent 4px,
var(--sc-color-divider) 4px,
var(--sc-color-divider) 8px
);
opacity: 0.75;
}
&::before {
left: 0px;
}
&::after {
right: 0px;
}
@media (max-width: 768px) {
padding: 40px;
max-width: 100%;
padding: 30px;
}
`

const Title = styled.h2`
font-size: 3rem;
font-weight: 600;
color: var(--sc-color-title);
margin-bottom: 16px;
`

const Message = styled.p`
font-size: 1.5rem;
margin-bottom: 24px;
font-weight: 500;
`

const SubMessage = styled.p`
font-size: 1.2rem;
`

const HomeLink = styled(Link)`
font-size: 1.2rem;
`

const Icon = styled(Spool)`
position: absolute;
right: 0;
bottom: 0;
height: 50%;
fill: var(--sc-color-carnation);
opacity: 0.4;
@media (max-width: 1024px) {
height: 35%;
}
@media (max-width: 768px) {
height: 35%;
bottom: 10%;
}
`

export default function NotFound() {
return (
<Container>
<section aria-labelledby="page-title">
<Title id="page-title">Page not found!</Title>
<Message>
Sorry, but the page you were looking for could not be found.
</Message>
<SubMessage>
You can <HomeLink href="/">return to our front page</HomeLink>, or
contact us if you can't find what you're looking for.
</SubMessage>
</section>
<Icon />
</Container>
)
}

0 comments on commit b12ad06

Please sign in to comment.