Skip to content

Commit

Permalink
♻️ Refactor(create-board): error-boundary 로직 수정
Browse files Browse the repository at this point in the history
related to: #169
  • Loading branch information
ppochaco committed Aug 16, 2024
1 parent 7c447d1 commit 4e482d4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client'

import { useEffect } from 'react'

import { usePathname, useRouter } from 'next/navigation'

import { Button } from '@/components/ui/button'
Expand All @@ -15,13 +17,16 @@ const ActivityErrorFallback = ({
const pathName = usePathname()
const router = useRouter()

if (error?.message === DATA_ERROR_MESSAGES.ACTIVITY_NOT_FOUND) {
const semesterName = getSemesterNameFromPath(pathName)
const currentSemester = useCurrentSemester(semesterName)
const {} = useGetActivities(Number(currentSemester.semesterId))
const semesterName = getSemesterNameFromPath(pathName)
const currentSemester = useCurrentSemester(semesterName)

useGetActivities(Number(currentSemester.semesterId))

resetErrorBoundary()
}
useEffect(() => {
if (error?.message === DATA_ERROR_MESSAGES.ACTIVITY_NOT_FOUND) {
resetErrorBoundary()
}
}, [error])

return (
<div className="flex flex-col items-center gap-6 pt-40">
Expand All @@ -30,7 +35,7 @@ const ActivityErrorFallback = ({
<Button variant="secondary" onClick={() => router.back()}>
뒤로가기
</Button>
<Button onClick={() => router.push('/auth/login')}> 로그인 </Button>
<Button onClick={() => router.push('/auth/login')}>로그인</Button>
</div>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const ActivitySection = ({
semesterId,
activityId,
}: ActivitySectionProps) => {
const { data: activities, status } = useGetActivities(semesterId)
const { data: activities } = useGetActivities(semesterId)
const currentActivity = useCurrentActivity(semesterId, activityId)

if (!activities?.length) return <div>활동이 없습니다.</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useEffect, useState } from 'react'

import { usePathname, useRouter } from 'next/navigation'

import { Button } from '@/components/ui/button'
Expand All @@ -6,14 +8,20 @@ import { useMyInfoStore } from '@/store/myInfo'
export const CreateBoardButton = () => {
const pathName = usePathname()
const router = useRouter()

const { role } = useMyInfoStore((state) => state.getMyInfo())
const [disabled, setDisabled] = useState(true)

useEffect(() => {
setDisabled(!(role === '해구르르' || role === '팀장'))
}, [])

return (
<div className="mb-20 flex w-full justify-end">
<Button
className="max-w-fit"
onClick={() => router.push(`${pathName}/create-board`)}
disabled={!(role === '해구르르' || role === '팀장')}
disabled={disabled}
>
게시판 생성하기
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const ActivityLayout = ({ children }: { children: ReactNode }) => {
return (
<ErrorHandlingWrapper
fallbackComponent={ActivityErrorFallback}
suspenseFallback={<div>loading...</div>}
suspenseFallback={
<div className="flex w-full justify-center pt-20">loading...</div>
}
>
{children}
</ErrorHandlingWrapper>
Expand Down
4 changes: 3 additions & 1 deletion src/service/components/ReactQueryClientProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
export const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: 0,
retry: 1,
staleTime: 1000 * 60 * 3,
refetchOnMount: false,
refetchOnWindowFocus: false,
},
},
})
Expand Down
4 changes: 3 additions & 1 deletion src/service/data/activity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { queryOptions, useQuery, useSuspenseQuery } from '@tanstack/react-query'
'use client'

import { queryOptions, useSuspenseQuery } from '@tanstack/react-query'

import { DATA_ERROR_MESSAGES } from '@/constant/errorMessage'
import { queryClient } from '@/service/components/ReactQueryClientProvider'
Expand Down

0 comments on commit 4e482d4

Please sign in to comment.