@@ -4,6 +4,8 @@ import { useDeleteNotification } from '@/hooks/useDeleteNotification';
44import cn from '@/lib/cn' ;
55import relativeTime from '@/utils/relativeTime' ;
66import IconClose from '@assets/svg/close' ;
7+ import { useRouter } from 'next/navigation' ;
8+ import { toast } from 'sonner' ;
79
810type NotificationStatus = 'confirmed' | 'declined' ;
911
@@ -12,6 +14,7 @@ interface NotificationCardProps {
1214 id : number ;
1315 createdAt : string ;
1416 onDelete : ( id : number ) => void ;
17+ onCardClick ?: ( ) => void ;
1518}
1619
1720const statusColorMap : Record <
@@ -50,14 +53,16 @@ export default function NotificationCard({
5053 createdAt,
5154 id,
5255 onDelete,
56+ onCardClick,
5357} : NotificationCardProps ) {
54- const { mutate : deleteNotification } = useDeleteNotification ( ) ;
58+ const { mutateAsync : deleteNotification } = useDeleteNotification ( ) ;
59+ const router = useRouter ( ) ;
5560
5661 const formattedContent = content . replace ( / ( \( \d { 4 } - \d { 2 } - \d { 2 } ) \s + / , '$1\n' ) ;
5762
58- const handleDelete = ( ) => {
63+ const handleDelete = async ( ) => {
64+ await deleteNotification ( id ) ;
5965 onDelete ( id ) ;
60- deleteNotification ( id ) ;
6166 } ;
6267
6368 const keywordMatch = Object . entries ( statusKeywordMap ) . find ( ( [ k ] ) =>
@@ -66,6 +71,19 @@ export default function NotificationCard({
6671
6772 const status = keywordMatch ?. [ 1 ] ;
6873
74+ const handleCardClick = async ( ) => {
75+ try {
76+ await deleteNotification ( id ) ;
77+ onDelete ( id ) ;
78+ onCardClick ?.( ) ;
79+ router . push ( '/mypage/reservations' ) ;
80+ } catch {
81+ toast . error (
82+ '알림 확인 중 문제가 발생했습니다. 잠시 후 다시 시도해 주세요.' ,
83+ ) ;
84+ }
85+ } ;
86+
6987 return (
7088 < div className = 'w-full rounded-[5px] border border-gray-400 bg-white px-12 py-16' >
7189 < div className = 'flex items-start justify-between' >
@@ -79,8 +97,8 @@ export default function NotificationCard({
7997 ) }
8098 < button
8199 onClick = { ( e ) => {
100+ e . stopPropagation ( ) ;
82101 setTimeout ( ( ) => {
83- e . stopPropagation ( ) ;
84102 handleDelete ( ) ;
85103 } , 0 ) ;
86104 } }
@@ -90,23 +108,25 @@ export default function NotificationCard({
90108 </ button >
91109 </ div >
92110
93- < p className = 'text-md font-regular whitespace-pre-line text-black' >
94- { formattedContent . split ( / ( 승 인 | 거 절 ) / ) . map ( ( text , i ) => {
95- const matchedStatus = statusKeywordMap [ text ] ;
96- return (
97- < span
98- key = { i }
99- className = { cn (
100- matchedStatus && statusColorMap [ matchedStatus ] . text ,
101- ) }
102- >
103- { text }
104- </ span >
105- ) ;
106- } ) }
107- </ p >
111+ < div className = 'cursor-pointer' onClick = { handleCardClick } >
112+ < p className = 'text-md font-regular whitespace-pre-line text-black' >
113+ { formattedContent . split ( / ( 승 인 | 거 절 ) / ) . map ( ( text , i ) => {
114+ const matchedStatus = statusKeywordMap [ text ] ;
115+ return (
116+ < span
117+ key = { i }
118+ className = { cn (
119+ matchedStatus && statusColorMap [ matchedStatus ] . text ,
120+ ) }
121+ >
122+ { text }
123+ </ span >
124+ ) ;
125+ } ) }
126+ </ p >
108127
109- < p className = 'mt-4 text-xs text-gray-600' > { relativeTime ( createdAt ) } </ p >
128+ < p className = 'mt-4 text-xs text-gray-600' > { relativeTime ( createdAt ) } </ p >
129+ </ div >
110130 </ div >
111131 ) ;
112132}
0 commit comments