-
Notifications
You must be signed in to change notification settings - Fork 1
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
[Feature] 토스트 컴포넌트 구현 및 에러핸들링 로직 수정 #108
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5b724bf
feat: 토스트 컴포넌트 구현
hamo-o a9b0134
feat: 토스트 스토리 작성
hamo-o 689b50e
fix: 사용하지 않는 import 삭제
hamo-o b4a5f14
fix: id 필수 prop으로 변환, export 추가
hamo-o a8cd450
feat: toast atoms 추가
hamo-o 624128d
feat: useToast hook
hamo-o e8c6433
feat: ToastProvider
hamo-o 3769a50
feat: admin Toast 컴포넌트 구현
hamo-o a86c4ab
feat: 에러메시지를 받기 위한 fetcher 로직 수정
hamo-o c6fdb91
feat: 어드민 ToastProvider 적용
hamo-o cff5067
feat: default 에러메시지
hamo-o 98c4326
feat: 과제 휴강처리 toast 적용
hamo-o ae07105
feat: 스터디 생성 실패 toast 적용
hamo-o efea019
feat: 공지 생성 실패 toast 적용
hamo-o c0c42b3
feat: toast 타입 적용
hamo-o dbfc658
feat: toast default message 삭제 및 type 개별적용
hamo-o ac66a27
feat: 과제 개설 toast 적용
hamo-o 5a3e242
fix: 스터디 상세정보 작성 try catch구문 적용
hamo-o a9e9ed1
feat: 클라이언트 Toast 세팅
hamo-o b56960e
fix: 누락된 type 추가
hamo-o ecca381
fix: 잘못된 import 수정
hamo-o 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 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -12,20 +12,19 @@ const useSubmitStudyDetailInfo = ( | |
const router = useRouter(); | ||
|
||
const handleSubmitDetailInfo = async () => { | ||
const data = await createStudyApi.postStudyDetailInfo( | ||
studyDetailData, | ||
studyId | ||
); | ||
if (data.success) { | ||
try { | ||
await createStudyApi.postStudyDetailInfo(studyDetailData, studyId); | ||
setIsSuccess(true); | ||
const timerId = setTimeout(() => { | ||
router.push(`${routerPath.root.href}/${studyId}`); | ||
}, 500); | ||
return () => clearTimeout(timerId); | ||
} else { | ||
setIsSuccess(false); | ||
window.alert("스터디 상세 정보 저장에 실패했어요."); | ||
router.push(`${routerPath.root.href}`); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
setIsSuccess(false); | ||
window.alert(error.message); | ||
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3; |
||
router.push(`${routerPath.root.href}`); | ||
} | ||
} | ||
}; | ||
|
||
|
This file contains 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,46 @@ | ||
"use client"; | ||
import type { ToastProps } from "@wow-class/ui"; | ||
import { Toast as ToastUI } from "@wow-class/ui"; | ||
import { toastStatusMap } from "constants/status/toastStatusMap"; | ||
import { useSetAtom } from "jotai"; | ||
import { useEffect, useState } from "react"; | ||
import { removeToastAtom } from "store"; | ||
|
||
const TOAST_DURATION = 2000; | ||
const ANIMATION_DURATION = 200; | ||
|
||
const Toast = ({ id, type, text, ...rest }: ToastProps) => { | ||
const [opacity, setOpacity] = useState<number>(0.2); | ||
const removeToastItem = useSetAtom(removeToastAtom); | ||
|
||
useEffect(() => { | ||
setOpacity(1); | ||
const timeoutForRemove = setTimeout(() => { | ||
removeToastItem(id); | ||
}, TOAST_DURATION); | ||
|
||
const timeoutForVisible = setTimeout(() => { | ||
setOpacity(0); | ||
}, TOAST_DURATION - ANIMATION_DURATION); | ||
|
||
return () => { | ||
clearTimeout(timeoutForRemove); | ||
clearTimeout(timeoutForVisible); | ||
}; | ||
}, [id, removeToastItem]); | ||
|
||
return ( | ||
<ToastUI | ||
id={id} | ||
style={{ opacity }} | ||
text={text || toastStatusMap[type]} | ||
transition="opacity" | ||
transitionDelay="0.5" | ||
transitionTimingFunction="ease-in-out" | ||
type={type} | ||
{...rest} | ||
/> | ||
); | ||
}; | ||
|
||
export default Toast; |
This file contains 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,33 @@ | ||
"use client"; | ||
|
||
import { Flex } from "@styled-system/jsx"; | ||
import type { ToastProps } from "@wow-class/ui"; | ||
import { useAtomValue } from "jotai"; | ||
import type { ReactNode } from "react"; | ||
import { toastsAtom } from "store"; | ||
|
||
import Toast from "./Toast"; | ||
|
||
const ToastProvider = ({ children }: { children: ReactNode }) => { | ||
const toasts = useAtomValue(toastsAtom); | ||
|
||
return ( | ||
<> | ||
<Flex | ||
direction="column" | ||
gap="sm" | ||
left="50%" | ||
position="absolute" | ||
top={24} | ||
translate="-50%" | ||
> | ||
{toasts?.map((toast: ToastProps) => ( | ||
<Toast key={toast.id} {...toast} /> | ||
))} | ||
</Flex> | ||
{children} | ||
</> | ||
); | ||
}; | ||
|
||
export default ToastProvider; |
This file contains 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 @@ | ||
export const DEFAULT_ERROR_MESSAGE = "에러가 발생했어요."; |
File renamed without changes.
This file contains 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,6 @@ | ||
import { DEFAULT_ERROR_MESSAGE } from "constants/messages/error"; | ||
|
||
export const toastStatusMap: Record<"error" | "success", string> = { | ||
error: DEFAULT_ERROR_MESSAGE, | ||
success: "", | ||
}; |
This file contains 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 { useSetAtom } from "jotai"; | ||
import { toastAtom } from "store"; | ||
|
||
const useToast = () => { | ||
const addToast = useSetAtom(toastAtom); | ||
|
||
return { | ||
toast: addToast(), | ||
}; | ||
}; | ||
|
||
export default useToast; |
This file contains 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 @@ | ||
export * from "./toastAtoms"; |
This file contains 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,26 @@ | ||
import type { ToastProps } from "@wow-class/ui"; | ||
import { atom } from "jotai"; | ||
|
||
import { toastsAtom } from "../atoms/toastAtoms"; | ||
|
||
export const toastAtom = atom( | ||
null, | ||
(get, set) => | ||
(props: Omit<ToastProps, "id"> & Partial<Pick<ToastProps, "id">>) => { | ||
const prevAtom = get(toastsAtom); | ||
const newToast = { | ||
...props, | ||
id: props.id || Date.now().toString(), | ||
}; | ||
|
||
set(toastsAtom, [...prevAtom, newToast]); | ||
} | ||
); | ||
Comment on lines
+6
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. p3; |
||
|
||
export const removeToastAtom = atom(null, (get, set, id: string) => { | ||
const prev = get(toastsAtom); | ||
set( | ||
toastsAtom, | ||
prev.filter((toast) => toast.id !== id) | ||
); | ||
}); |
This file contains 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 @@ | ||
export * from "./toastAtoms"; |
This file contains 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,4 @@ | ||
import type { ToastProps } from "@wow-class/ui"; | ||
import { atom } from "jotai"; | ||
|
||
export const toastsAtom = atom<ToastProps[]>([]); |
This file contains 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,2 @@ | ||
export * from "./actions"; | ||
export * from "./atoms"; |
This file contains 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.
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.
p3;
해당 api는 fetcher 클래스를 사용하는 것 같은데 response interceptor를 사용해보면 공통으로 에러 메시지 같은 부분을 관리할 수 있을 거 같아요!
불가피하게 fetch를 쓰는 경우에만 위 경우처럼 처리해주면 될 거 같은데 fetcher를 안 쓰고 fetch를 쓰는 경우가 있나요?