-
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
feat: toast 컴포넌트를 구현합니다 #221
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4927ceb
feat: toast component 개발
Jungjjeong d826587
feat: toast 사용하기 위한 상태 관리 추가
Jungjjeong 2048e89
feat: toast 렌더링 영역 추가
Jungjjeong f55f679
fix: toast 오픈 위치 수정
Jungjjeong ebe1a1f
chore: use toast 주석 추가
Jungjjeong 3ff45dc
feat: 칭찬 가능 여부 api 추가 및 적용
Jungjjeong 3c8e118
fix: 불필요 fragment 삭제
Jungjjeong a41e8a6
fix: toast position, z index 수정
Jungjjeong 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { fetchData } from '@/apis/fetch-data'; | ||
|
||
export async function GET( | ||
request: NextRequest, | ||
{ params }: { params: { memoryId: number } }, | ||
) { | ||
const data = await fetchData<{ data: { eligibility: boolean } }>( | ||
`/memory/${Number(params.memoryId)}/reaction/eligibility`, | ||
'GET', | ||
); | ||
|
||
return NextResponse.json(data); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export const Error = (props?: React.SVGProps<SVGSVGElement>) => { | ||
return ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<g clipPath="url(#clip0_18199_7240)"> | ||
<circle cx="12" cy="12" r="8" fill="white" /> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M2.1001 12.0001C2.1001 6.53248 6.53247 2.1001 12.0001 2.1001C17.4677 2.1001 21.9001 6.53248 21.9001 12.0001C21.9001 17.4677 17.4677 21.9001 12.0001 21.9001C6.53247 21.9001 2.1001 17.4677 2.1001 12.0001ZM13.0001 16.2501C13.0001 16.8024 12.5524 17.2501 12.0001 17.2501C11.4478 17.2501 11.0001 16.8024 11.0001 16.2501C11.0001 15.6978 11.4478 15.2501 12.0001 15.2501C12.5524 15.2501 13.0001 15.6978 13.0001 16.2501ZM11.1001 6.75012V13.7501H12.9001V6.75012H11.1001Z" | ||
fill="#FF4242" | ||
/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_18199_7240"> | ||
<rect width="24" height="24" fill="white" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
); | ||
}; |
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,3 @@ | ||
export * from './error'; | ||
export * from './success'; | ||
export * from './warning'; |
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,27 @@ | ||
export const Success = (props?: React.SVGProps<SVGSVGElement>) => { | ||
return ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<g clipPath="url(#clip0_18199_7226)"> | ||
<circle cx="12" cy="12" r="8" fill="white" /> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M17.1459 9.62682L10.6766 16.2922L6.85426 12.3541L8.14591 11.1004L10.6766 13.7078L15.8543 8.37317L17.1459 9.62682ZM2.1001 12C2.1001 6.53236 6.53248 2.09998 12.0001 2.09998C17.4677 2.09998 21.9001 6.53236 21.9001 12C21.9001 17.4676 17.4677 21.9 12.0001 21.9C6.53248 21.9 2.1001 17.4676 2.1001 12Z" | ||
fill="#00BF40" | ||
/> | ||
</g> | ||
<defs> | ||
<clipPath id="clip0_18199_7226"> | ||
<rect width="24" height="24" fill="white" /> | ||
</clipPath> | ||
</defs> | ||
</svg> | ||
); | ||
}; |
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,19 @@ | ||
export const Warning = (props?: React.SVGProps<SVGSVGElement>) => { | ||
return ( | ||
<svg | ||
width="24" | ||
height="24" | ||
viewBox="0 0 24 24" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
{...props} | ||
> | ||
<path | ||
fillRule="evenodd" | ||
clipRule="evenodd" | ||
d="M2.1001 12.0001C2.1001 6.53248 6.53247 2.1001 12.0001 2.1001C17.4677 2.1001 21.9001 6.53248 21.9001 12.0001C21.9001 17.4677 17.4677 21.9001 12.0001 21.9001C6.53247 21.9001 2.1001 17.4677 2.1001 12.0001ZM13.0001 16.2501C13.0001 16.8024 12.5524 17.2501 12.0001 17.2501C11.4478 17.2501 11.0001 16.8024 11.0001 16.2501C11.0001 15.6978 11.4478 15.2501 12.0001 15.2501C12.5524 15.2501 13.0001 15.6978 13.0001 16.2501ZM11.1001 6.75012V13.7501H12.9001V6.75012H11.1001Z" | ||
fill="#FFCF58" | ||
/> | ||
</svg> | ||
); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './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,88 @@ | ||
'use client'; | ||
|
||
import { useAtomValue } from 'jotai'; | ||
import { PropsWithChildren, ReactNode } from 'react'; | ||
|
||
import { toastAtom } from '@/store'; | ||
import { css } from '@/styled-system/css'; | ||
import { flex } from '@/styled-system/patterns'; | ||
|
||
import { Error, Success, Warning } from '../icons'; | ||
|
||
export type ToastType = 'success' | 'error' | 'warning'; | ||
export type ToastProps = { | ||
content: ReactNode; | ||
type: ToastType; | ||
}; | ||
|
||
export const ToastDialog = () => { | ||
const toastState = useAtomValue(toastAtom); | ||
const isOpen = toastState.size > 0; | ||
|
||
return ( | ||
<dialog | ||
className={containerStyle} | ||
open={isOpen} | ||
ref={(el) => { | ||
if (el && !el.open) el.show(); | ||
}} | ||
> | ||
<div className={toastWrapperStyle}> | ||
{Array.from(toastState.entries()).map(([id, { content, type }]) => ( | ||
<Toast type={type} key={id}> | ||
{content} | ||
</Toast> | ||
))} | ||
</div> | ||
</dialog> | ||
); | ||
}; | ||
|
||
const Toast = ({ | ||
type, | ||
children, | ||
}: PropsWithChildren<{ | ||
type: ToastType; | ||
}>) => { | ||
return ( | ||
<div className={toastStyle}> | ||
{ | ||
{ | ||
success: <Success />, | ||
error: <Error />, | ||
warning: <Warning />, | ||
}[type] | ||
} | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
const containerStyle = css({ | ||
position: 'fixed', | ||
backgroundColor: 'transparent', | ||
zIndex: 900, | ||
}); | ||
|
||
const toastWrapperStyle = flex({ | ||
direction: 'column', | ||
gap: '4px', | ||
position: 'fixed', | ||
bottom: 0, | ||
left: '50%', | ||
transform: 'translateX(-50%)', | ||
marginBottom: 'calc(35px + env(safe-area-inset-bottom))', | ||
}); | ||
|
||
const toastStyle = flex({ | ||
textWrap: 'nowrap', | ||
alignItems: 'center', | ||
gap: '10px', | ||
textStyle: 'body2.normal', | ||
fontWeight: 'medium', | ||
color: 'white', | ||
p: '12px 16px', | ||
backgroundColor: 'fill.highlight', | ||
rounded: '16px', | ||
animation: 'fadeUp 0.3s', | ||
}); |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './use-cheer'; | ||
export * from './use-cheer-eligibility'; | ||
export * from './use-cheer-list'; | ||
export * from './use-cheer-preview-list'; | ||
export * from './use-cheer-remove'; |
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,27 @@ | ||
'use client'; | ||
|
||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const fetchCheerEligibility = async (memoryId: number) => { | ||
const res = await fetch(`/api/memory/${memoryId}/reaction/eligibility`, { | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
|
||
return res.json(); | ||
}; | ||
|
||
export const useCheerEligibility = (memoryId: number, isMyMemory?: boolean) => { | ||
const query = useQuery<{ data: { isRegistrable: boolean } }>({ | ||
queryKey: ['useCheerEligibility', memoryId], | ||
queryFn: () => fetchCheerEligibility(memoryId), | ||
retry: 3, | ||
enabled: !!memoryId && !isMyMemory, | ||
}); | ||
|
||
return { | ||
...query, | ||
data: query.data?.data, | ||
}; | ||
}; |
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
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.
dialog 태그의 속성으로 인해 스크롤이 존재하는 페이지에서 toast가 띄워질 시,
사라질 때 스크롤이 페이지 바닥으로 이동하는 현상이 존재하는 것 같아요!
dialog 태그 스타일을 수정, 혹은 스크롤을 현재 위치로 고정해주는 로직이 추가되어야 자연스러운 동작이 될 것 같습니다~
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.
오 맞아요 방금 그 부분 수정했습니다!
layout shifting이 발생하여 dialog component의 스타일 속성을 변경했습니다.