Skip to content

Commit

Permalink
[FEAT] 404 not found page & 500 server error page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny-jinn committed Nov 12, 2024
1 parent dfbdc1c commit 54e4db2
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { checkToken, getUserInfo } from './api/auth.ts'
import userStore from './store/User.ts'
import Home from './pages/Home'
import Admin from './pages/Admin.tsx'
import { NotFound } from './pages/error/NotFound.tsx'

function App() {
const [location] = useLocation()
Expand Down Expand Up @@ -46,6 +47,7 @@ function App() {
<Route path='/post/:post_id' component={PostDetail} />
<Route path='/profile' component={Profile} />
<Route path='/admin' component={Admin} />
<Route path='*' component={NotFound} />
</Switch>
)
}
Expand Down
3 changes: 2 additions & 1 deletion src/pages/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { TUser } from '../types'
import { Color } from '../palette'
import icon_search from '../assets/icon_search.svg'
import { Pagination } from '../components/Pagination'
import { ServerError } from './error/ServerError'

const Style = {
wrapper: css`
Expand Down Expand Up @@ -142,7 +143,7 @@ const Admin: React.FC = () => {
))
}

if (studentRequestError || studentListError) return <div>Error</div>
if (studentRequestError || studentListError) return <ServerError />

if (!isAuthorized) {
return <div>관리자만 접근 가능한 페이지입니다.</div>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import icon_default_profile from '../assets/icon_default_profile.svg'
import userStore from '../store/User'
import { mutate } from 'swr'
import { ServerError } from './error/ServerError'

const PostStyle = {
wrapper: css`
Expand Down Expand Up @@ -202,8 +203,8 @@ const Post: React.FC = () => {
mutate: commentMutate,
} = useGetComments(post_id!)

if (isLoading || isCommentsLoading) return <>Loading..</>
if (error || commentsError) return <>Error occured!</>
if (isLoading || isCommentsLoading) return <></>
if (error || commentsError) return <ServerError />

const comments: TComment[] = commentsData.content

Expand Down
5 changes: 3 additions & 2 deletions src/pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CustomPlusButton } from '../components/CustomPlusButton'
import { useLocation } from 'wouter'

import { CustomInput } from '../components/CustomInput'
import { ServerError } from './error/ServerError'

const Style = {
wrapper: css`
Expand Down Expand Up @@ -248,8 +249,8 @@ const Profile: React.FC = () => {
}
}, [data])

if (error || postsError) return <div>로그인 후 이용해주세요!</div>
if (isLoading || postLoading || !profileData) return <div>Loading...</div>
if (isLoading || postLoading || !profileData) return <div></div>
if (error || postsError) return <ServerError />

const profiles: TUser = profileData

Expand Down
7 changes: 4 additions & 3 deletions src/pages/Project.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ProjectCard } from '../components/ProjectCard'
import { TProject } from '../types'
import userStore from '../store/User'
import { Pagination } from '../components/Pagination'
import { ServerError } from './error/ServerError'

const containerStyle = css`
display: flex;
Expand Down Expand Up @@ -102,16 +103,16 @@ const Project: FC = () => {
size: '7',
}).toString()

const { data, error } = useSWR(`project?${params}`, fetcher)
const { data, error, isLoading } = useSWR(`project?${params}`, fetcher)

useEffect(() => {
if (data) {
setTotalPages(Math.ceil(data.data.totalElements / 7))
}
}, [data])

if (error) return <div>Failed to load profile</div>
if (!data) return <div>Loading...</div>
if (isLoading) return <div></div>
if (error) return <ServerError />

const projectList: TProject[] = data.data.content

Expand Down
4 changes: 3 additions & 1 deletion src/pages/ProjectDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'swiper/css/effect-fade'
import { SwiperBullets } from '../components/SwiperBullets'
import { Swiper as SwiperClass } from 'swiper/types' // Swiper 인스턴스 타입
import { Header } from '../common/Header'
import { ServerError } from './error/ServerError'

const Style = {
wrapper: css`
Expand Down Expand Up @@ -197,7 +198,8 @@ const ProjectDetail: React.FC = () => {
const [, navigate] = useLocation()

const { data, isLoading, error } = useSWR(`project/${project_id!}`, fetcher)
if (isLoading || error) return <div>Error</div>
if (isLoading) return <div></div>
if (error) return <ServerError />

const projectInfo: TProject = data.data

Expand Down
5 changes: 3 additions & 2 deletions src/pages/TechBlog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Header } from '../common/Header'
import { TPost } from '../types'
import { useGetPostList } from '../hooks/query/post.api'
import { Pagination } from '../components/Pagination'
import { ServerError } from './error/ServerError'

const TechBlog: React.FC = () => {
const [currentPage, setCurrentPage] = useState<number>(0)
Expand All @@ -31,8 +32,8 @@ const TechBlog: React.FC = () => {
}
}, [data])

if (isLoading) return <div>Failed to load profiles</div>
if (error) return <div>Error!</div>
if (isLoading) return <div></div>
if (error) return <ServerError />

const postList: TPost[] = data.content

Expand Down
43 changes: 43 additions & 0 deletions src/pages/error/NotFound.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { css } from '@emotion/react'
import main_image from '../../assets/main_image.svg'
import { Link } from 'wouter'
import { Color } from '../../palette'

export const NotFound = () => {
return (
<div css={Wrapper}>
<img src={main_image} alt='404' />
<div css={TextContainer}>
<h1>404</h1>
<p>페이지를 찾을 수 없습니다.</p>
<Link to='/'>홈으로 돌아가기</Link>
</div>
</div>
)
}

const Wrapper = css`
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`

const TextContainer = css`
display: flex;
flex-direction: column;
align-items: center;
font-size: 1.5rem;
a {
font-weight: 600;
color: ${Color.Primary};
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
`
43 changes: 43 additions & 0 deletions src/pages/error/ServerError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { css } from '@emotion/react'
import main_image from '../../assets/main_image.svg'
import { Link } from 'wouter'
import { Color } from '../../palette'

export const ServerError = () => {
return (
<div css={Wrapper}>
<img src={main_image} alt='404' />
<div css={TextContainer}>
<h1>500</h1>
<p>에러가 발생했습니다.</p>
<Link to='/'>홈으로 돌아가기</Link>
</div>
</div>
)
}

const Wrapper = css`
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
`

const TextContainer = css`
display: flex;
flex-direction: column;
align-items: center;
font-size: 1.5rem;
a {
font-weight: 600;
color: ${Color.Primary};
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
`

0 comments on commit 54e4db2

Please sign in to comment.