-
Notifications
You must be signed in to change notification settings - Fork 0
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
알림 컴포넌트 구현 #51
Merged
Merged
알림 컴포넌트 구현 #51
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4702827
chore: #50 - 커스텀 스타일 추가
dudwns 7105c3d
feat: #50 - 알림 컴포넌트 구현
dudwns 65887d4
feat: #50 - 알림 컴포넌트에서 사용되는 텍스트를 상수로 저장
dudwns 9703a24
style: #50 - 알림 컴포넌트 정렬 수정
dudwns 94a2f1b
feat: #50 - 페이지 이동 및 읽음 처리 추가
dudwns 97d5222
style: #50 - 레이아웃 수정
dudwns 72470e7
feat: #50 - NotificationUser 컴포넌트 구현
dudwns bb2c128
feat: #50 - NotificationComment 컴포넌트 구현
dudwns 094810a
feat: #50 - NotificationSpace 컴포넌트 구현
dudwns 5df506b
feat: #50 - 상수 수정
dudwns 8cffe47
feat: #50 - handleClickSpaceProps 타입 수정
dudwns c8eaf93
refactor: #50 - 컴포넌트 중복 제거
dudwns b91449c
refactor: #50 - 코드 순서 변경
dudwns f06af43
refactor: #50 - onClick 콜백 함수를 prop으로 전달하는 로직으로 변경
dudwns 7228844
refactor: #50 - 타입명 수정 및 적용
dudwns 115bdd3
refactor: #50 - Notification 관련 컴포넌트 제거
dudwns ada2c8a
feat: #50 - 알림 컴포넌트 조건부 렌더링 수정
dudwns 6fcaf59
Merge branch 'develop' into feature/#50/component-notification
dudwns 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use client' | ||
|
||
import { cls } from '@/utils' | ||
import { XMarkIcon } from '@heroicons/react/24/solid' | ||
import Button from '../Button/Button' | ||
import { NOTIFICATION_MSG } from './constants' | ||
import useNotification from './hooks/useNotification' | ||
|
||
export interface NotificationProps { | ||
notificationId: number | ||
type: 'follow' | 'comment' | 'space' | ||
userId: number | ||
userName: string | ||
spaceId?: number | ||
spaceName?: string | ||
isRead?: boolean | ||
isAccept?: boolean | ||
onAccept?: (e?: React.MouseEvent<HTMLButtonElement>) => void | ||
onClose?: (e?: React.MouseEvent<HTMLButtonElement>) => void | ||
} | ||
|
||
const Notification = ({ | ||
notificationId, | ||
type, | ||
userId, | ||
userName, | ||
spaceId, | ||
spaceName, | ||
isRead = false, | ||
isAccept = false, | ||
onAccept, | ||
onClose, | ||
}: NotificationProps) => { | ||
const { handleClickUser, handleClickSpace, handleClickComment } = | ||
useNotification() | ||
|
||
return ( | ||
<div | ||
className={cls( | ||
'flex flex-col gap-6 rounded-md border border-slate3 p-3', | ||
isRead ? 'bg-bgColor' : 'bg-emerald05', | ||
)}> | ||
<div className="flex w-full items-start justify-between text-sm font-medium text-gray9"> | ||
<div> | ||
<span | ||
onClick={() => handleClickUser({ notificationId, userId, isRead })} | ||
className="cursor-pointer font-bold"> | ||
{userName} | ||
</span> | ||
{NOTIFICATION_MSG.USER} | ||
{type === 'follow' ? ( | ||
NOTIFICATION_MSG.FOLLOW | ||
) : ( | ||
<> | ||
<span | ||
onClick={() => | ||
handleClickSpace({ notificationId, spaceId, isRead }) | ||
} | ||
className="cursor-pointer font-bold"> | ||
{spaceName} | ||
</span> | ||
{NOTIFICATION_MSG.SPACE} | ||
<span | ||
onClick={() => | ||
handleClickComment({ | ||
notificationId, | ||
spaceId, | ||
isRead, | ||
}) | ||
} | ||
className="cursor-pointer font-bold"> | ||
{NOTIFICATION_MSG.COMMENT} | ||
</span> | ||
{NOTIFICATION_MSG.COMMENT_LEAVE} | ||
{type === 'space' && NOTIFICATION_MSG.SPACE_INVITE} | ||
</> | ||
)} | ||
</div> | ||
<Button onClick={onClose}> | ||
<XMarkIcon className="h-5 w-5 p-0.5 text-slate6" /> | ||
</Button> | ||
</div> | ||
{type === 'space' && ( | ||
<div className="flex justify-end"> | ||
{isAccept ? ( | ||
<div className="text-sm font-semibold text-slate6"> | ||
{NOTIFICATION_MSG.APPROVE} | ||
</div> | ||
) : ( | ||
<Button | ||
onClick={onAccept} | ||
className="button button-emerald px-2.5 py-1.5"> | ||
{NOTIFICATION_MSG.APPROVE_BUTTON} | ||
</Button> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default Notification |
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,10 @@ | ||
export const NOTIFICATION_MSG = { | ||
APPROVE_BUTTON: '수락', | ||
APPROVE: '수락 완료', | ||
USER: ' 님이 ', | ||
FOLLOW: '팔로우했습니다.', | ||
COMMENT: '댓글', | ||
COMMENT_LEAVE: '을 남겼습니다.', | ||
SPACE: ' 스페이스에 ', | ||
SPACE_INVITE: '초대했습니다.', | ||
} |
74 changes: 74 additions & 0 deletions
74
src/components/common/Notification/hooks/useNotification.ts
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,74 @@ | ||
import { useRouter } from 'next/navigation' | ||
|
||
export interface HandleClickUserProps { | ||
notificationId: number | ||
userId: number | ||
isRead: boolean | ||
} | ||
|
||
export interface HandleClickSpaceProps { | ||
notificationId: number | ||
spaceId?: number | ||
isRead: boolean | ||
} | ||
|
||
export interface HandleClickCommentProps extends HandleClickSpaceProps {} | ||
|
||
export interface UseNotificationReturn { | ||
handleClickUser: ({ | ||
notificationId, | ||
userId, | ||
isRead, | ||
}: HandleClickUserProps) => void | ||
handleClickSpace: ({ | ||
notificationId, | ||
spaceId, | ||
isRead, | ||
}: HandleClickSpaceProps) => void | ||
handleClickComment: ({ | ||
notificationId, | ||
spaceId, | ||
isRead, | ||
}: HandleClickCommentProps) => void | ||
} | ||
|
||
const useNotification = (): UseNotificationReturn => { | ||
const router = useRouter() | ||
|
||
const handleClickUser = ({ | ||
notificationId, | ||
userId, | ||
isRead, | ||
}: HandleClickUserProps) => { | ||
router.push(`/user/${userId}`) | ||
if (!isRead) { | ||
console.log(`${notificationId} 읽음 처리 추가`) | ||
} | ||
} | ||
|
||
const handleClickSpace = ({ | ||
notificationId, | ||
spaceId, | ||
isRead, | ||
}: HandleClickSpaceProps) => { | ||
router.push(`/space/${spaceId}`) | ||
if (!isRead) { | ||
console.log(`${notificationId} 읽음 처리 추가`) | ||
} | ||
} | ||
|
||
const handleClickComment = ({ | ||
notificationId, | ||
spaceId, | ||
isRead, | ||
}: HandleClickCommentProps) => { | ||
router.push(`/space/${spaceId}/comment`) | ||
if (!isRead) { | ||
console.log(`${notificationId} 읽음 처리 로직 추가`) | ||
} | ||
} | ||
|
||
return { handleClickUser, handleClickSpace, handleClickComment } | ||
} | ||
|
||
export default useNotification |
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
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.
알림을 눌렀을 때 읽음 처리와 페이지 이동을 해줘야 하는데 이 부분이 빠진 것 같습니다! 👀
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.
반영했습니다! 😀