Skip to content
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 18 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
--emerald4: rgb(101, 206, 156);
--emerald3: rgb(138, 227, 185);
--emerald1: rgb(216, 248, 230);
--emerald05: rgb(239, 252, 245);
--red9: rgb(118, 39, 32);
--red7: rgb(172, 49, 35);
--red6: rgb(205, 62, 46);
Expand Down Expand Up @@ -63,6 +64,7 @@
--emerald4: rgb(62, 146, 107);
--emerald3: rgb(48, 117, 88);
--emerald1: rgb(30, 76, 60);
--emerald05: rgb(20, 42, 46);
--red9: rgb(250, 227, 226);
--red7: rgb(242, 170, 166);
--red6: rgb(234, 123, 116);
Expand Down
102 changes: 102 additions & 0 deletions src/components/common/Notification/Notification.tsx
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

알림을 눌렀을 때 읽음 처리와 페이지 이동을 해줘야 하는데 이 부분이 빠진 것 같습니다! 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다! 😀

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
10 changes: 10 additions & 0 deletions src/components/common/Notification/constants/index.ts
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 src/components/common/Notification/hooks/useNotification.ts
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
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export { default as Dropdown } from './common/Dropdown/Dropdown'
export { default as SpaceMemberList } from './common/SpaceMemberList/SpaceMemberList'
export { default as Sidebar } from './common/Sidebar/Sidebar'
export { default as Comment } from './Comment/Comment'
export { default as Notification } from './common/Notification/Notification'
39 changes: 39 additions & 0 deletions src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,42 @@ export const mock_spaceData = {
scrap: 40,
comment: true,
}

export const mock_notificationData: {
id: number
type: 'comment' | 'follow' | 'space'
userId: number
userName: string
spaceId?: number
spaceName?: string
isRead: boolean
isAccept?: boolean
}[] = [
{
id: 1,
type: 'follow',
userId: 1,
userName: '프롱이',
isRead: false,
},
{
id: 2,
type: 'comment',
userId: 1,
userName: '프롱이',
spaceId: 123,
spaceName: '개발 모음',
isRead: false,
isAccept: false,
},
{
id: 3,
type: 'space',
userId: 1,
userName: '프롱이',
spaceId: 123,
spaceName: '개발 모음',
isRead: false,
isAccept: false,
},
]
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const config: Config = {
emerald4: 'var(--emerald4)',
emerald3: 'var(--emerald3)',
emerald1: 'var(--emerald1)',
emerald05: 'var(--emerald05)',
red9: 'var(--red9)',
red7: 'var(--red7)',
red6: 'var(--red6)',
Expand Down