-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 토스트 메세지 구현 및 툴팁 CSS 수정 #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hani0903
wants to merge
14
commits into
main
Choose a base branch
from
feat/#55
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
76c9ab9
file: transformChapter 경로 수정
hani0903 39e850e
fix: fetchUnits 함수 수정
hani0903 e85e9ee
add: tanstack query 공통 retry 함수 작성
hani0903 d2af262
feat: 토스트 메세지 구현
hani0903 7d8c13e
chore: framer-motion 설치
hani0903 8aba369
add: 토스트 provider 추가
hani0903 f5ca3a3
fix: 툴팁 css 수정
hani0903 2c3474e
feat: 라우트 경로 보호 및 에러 페이지 추가
hani0903 c616c0e
feat: Auth Handler 함수 추가
hani0903 0e573c4
fix: 로그인 여부 확인 코드 추가
hani0903 f0e039e
chore: pr, issue 템플릿 추가
hani0903 c821179
fix: 에러 페이지 에러 수정
hani0903 565986b
fix: 오타 및 잘못된 코드 수정
hani0903 1262b02
Merge branch 'main' into feat/#55
hani0903 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| # .github/pull_request_template.md | ||
|
|
||
| ## 🔍 작업 유형 | ||
|
|
||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| import { RouterProvider } from 'react-router-dom'; | ||
| import router from './routes/router'; | ||
| import ToastContextProvider from './context/ToastContextProvider'; | ||
|
|
||
| export default function App() { | ||
| return <RouterProvider router={router} />; | ||
| return ( | ||
| <ToastContextProvider> | ||
| <RouterProvider router={router} /> | ||
| </ToastContextProvider> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { useEffect } from 'react'; | ||
| import { useAuthHandler } from '../../../hooks/useAuthHandler'; | ||
|
|
||
| interface ProtectedRouteProps { | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export default function ProtectedRoute({ children }: ProtectedRouteProps) { | ||
| const { checkAuthToken, redirectToLogin } = useAuthHandler(); | ||
|
|
||
| useEffect(() => { | ||
| if (!checkAuthToken()) { | ||
| redirectToLogin(); | ||
| } | ||
| }, [checkAuthToken, redirectToLogin]); | ||
|
|
||
| if (!checkAuthToken()) { | ||
| return null; | ||
| } | ||
|
|
||
| return <>{children}</>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { createContext } from 'react'; | ||
| import type { ToastType } from '../types/@common/toast'; | ||
|
|
||
| type ToastContextType = { | ||
| showToast: (toast: ToastType) => void; | ||
| }; | ||
|
|
||
| const ToastContext = createContext<ToastContextType>({ | ||
| showToast: () => {}, | ||
| }); | ||
|
|
||
| export default ToastContext; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { useCallback, useEffect, useMemo, useRef, useState, type PropsWithChildren } from 'react'; | ||
| import type { ToastType } from '../types/@common/toast'; | ||
| import ToastContext from './ToastContext'; | ||
| import { AnimatePresence, motion } from 'framer-motion'; | ||
|
|
||
| function ToastContextProvider({ children }: PropsWithChildren) { | ||
| const [toast, setToast] = useState<ToastType | null>(null); | ||
| const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
|
|
||
| const showToast = useCallback(({ message, duration = 2 }: ToastType) => { | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| } | ||
|
|
||
| setToast({ message, duration }); | ||
|
|
||
| timeoutRef.current = setTimeout(() => { | ||
| setToast(null); | ||
| timeoutRef.current = null; | ||
| }, duration * 1000); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| if (timeoutRef.current) { | ||
| clearTimeout(timeoutRef.current); | ||
| } | ||
| }; | ||
| }, []); | ||
|
|
||
| const contextValue = useMemo(() => ({ showToast }), [showToast]); | ||
|
|
||
| return ( | ||
| <ToastContext.Provider value={contextValue}> | ||
| {children} | ||
| <AnimatePresence> | ||
| {toast && ( | ||
| <motion.div | ||
| initial={{ opacity: 0, y: -20, scale: 0.9 }} | ||
| animate={{ opacity: 1, y: 0, scale: 1 }} | ||
| exit={{ opacity: 0, y: -20, scale: 0.9 }} | ||
| transition={{ type: 'spring', stiffness: 300, damping: 30 }} | ||
| className="fixed top-1/6 left-1/2 -translate-x-1/2 z-[1000] bg-main-2 text-white rounded-full px-3 py-2" | ||
| > | ||
| {toast.message} | ||
| </motion.div> | ||
| )} | ||
| </AnimatePresence> | ||
| </ToastContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| export default ToastContextProvider; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { useNavigate } from 'react-router-dom'; | ||
| import useToast from './useToast'; | ||
| import { useCallback } from 'react'; | ||
| import { ApiError } from '../types/@common/api'; | ||
|
|
||
| export function useAuthHandler() { | ||
| const navigate = useNavigate(); | ||
| const showToast = useToast(); | ||
|
|
||
| const redirectToLogin = useCallback(() => { | ||
| showToast({ message: '로그인 후 이용할 수 있는 서비스입니다.' }); | ||
| navigate('/', { replace: true }); | ||
| }, [navigate, showToast]); | ||
|
|
||
| const handleApiError = useCallback( | ||
| (error: unknown) => { | ||
| if (error instanceof ApiError) { | ||
| if (['UNAUTHORIZED', 'FORBIDDEN'].includes(error.error)) { | ||
| redirectToLogin(); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
| return false; | ||
| }, | ||
| [redirectToLogin] | ||
| ); | ||
|
|
||
| const checkAuthToken = useCallback(() => { | ||
| return !!localStorage.getItem('accessToken'); | ||
| }, []); | ||
|
|
||
| return { handleApiError, checkAuthToken, redirectToLogin }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { useContext } from 'react'; | ||
| import ToastContext from '../context/ToastContext'; | ||
| import type { ToastType } from '../types/@common/toast'; | ||
|
|
||
| export default function useToast() { | ||
| const { showToast } = useContext(ToastContext); | ||
| return (toast: ToastType) => showToast(toast); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Guard query with enabled; prevent NaN requests and add cache window.
When chapterId is undefined or non-numeric, fetchUnits throws INVALID_ARGUMENT. Gate the query and optionally cache results.
} = useQuery({ queryKey: ['unit-list', { id: chapterId }], queryFn: () => fetchUnits(Number(chapterId)), - retry: shouldRetryApiRequest, + enabled: Number.isFinite(Number(chapterId)), + staleTime: 60_000, + retry: shouldRetryApiRequest, });📝 Committable suggestion
🤖 Prompt for AI Agents