11import React , { useState } from "react" ;
22import { IoMdMailOpen , IoMdMailUnread } from "react-icons/io" ;
33import { useNotifications } from "../../utils/Notifications" ;
4+ import { useNavigate } from "react-router" ;
45
56interface Notification {
67 id : string ;
78 message : string ;
9+ eventType : string ;
10+ eventId : string ;
811 read : boolean ;
912 createdAt : string ;
1013}
1114
15+ interface ModalProps {
16+ title : string ;
17+ children : React . ReactNode ;
18+ onClose : ( ) => void ;
19+ }
20+
1221function ApplicantNotifications ( ) {
1322 const [ activeTab , setActiveTab ] = useState ( "All" ) ;
1423 const [ sortOrder , setSortOrder ] = useState < "new" | "old" > ( "new" ) ;
1524 const [ searchQuery , setSearchQuery ] = useState ( "" ) ;
25+ const navigate = useNavigate ( ) ;
26+
27+
1628
1729 const { notifications, markAsRead, markAsUnread, unreadCount } =
1830 useNotifications ( ) ;
@@ -25,6 +37,19 @@ function ApplicantNotifications() {
2537 const handleSearchChange = ( e : React . ChangeEvent < HTMLInputElement > ) =>
2638 setSearchQuery ( e . target . value ) ;
2739
40+ const handleNotificationClick = async ( notification : Notification , ) => {
41+
42+ if ( ! notification . read ) {
43+ await markAsRead ( notification . id ) ;
44+ }
45+
46+ if ( notification . eventType === "ticket" ) {
47+ navigate ( `/applicant/ticket/${ notification . eventId } ` ) ;
48+ } else if ( notification . eventType === "applicationUpdate" ) {
49+ navigate ( `/applicant/myapplication` ) ;
50+ }
51+ } ;
52+
2853 const filteredNotifications = filterNotifications (
2954 notifications ,
3055 activeTab ,
@@ -49,6 +74,7 @@ function ApplicantNotifications() {
4974 < NotificationList
5075 notifications = { sortedNotifications }
5176 onToggleRead = { handleToggleRead }
77+ onNotificationClick = { handleNotificationClick }
5278 formatDate = { formatDate }
5379 />
5480 </ div >
@@ -150,10 +176,12 @@ const Header = ({
150176const NotificationList = ( {
151177 notifications,
152178 onToggleRead,
179+ onNotificationClick,
153180 formatDate,
154181} : {
155182 notifications : Notification [ ] ;
156- onToggleRead : ( notification : Notification ) => void ;
183+ onToggleRead : ( notification : Notification ) => void ;
184+ onNotificationClick : ( notification : Notification ) => void ;
157185 formatDate : ( dateString : string ) => string ;
158186} ) => (
159187 < div className = "flex-1 p-4 overflow-y-auto" >
@@ -165,7 +193,10 @@ const NotificationList = ({
165193 notification . read
166194 ? "bg-gray-800"
167195 : "bg-gray-800 border border-white text-white"
168- } `}
196+ } `}
197+ style = { { cursor : "pointer" } }
198+ onClick = { ( ) => onNotificationClick ( notification ) }
199+
169200 >
170201 < div className = "flex items-center space-x-4" >
171202 < div className = { notification . read ? "text-gray-400" : "text-white" } >
@@ -177,7 +208,10 @@ const NotificationList = ({
177208 { formatDate ( notification . createdAt ) || "Date not available" }
178209 </ div >
179210 < button
180- onClick = { ( ) => onToggleRead ( notification ) }
211+ onClick = { ( e ) => {
212+ e . stopPropagation ( ) ;
213+ onToggleRead ( notification ) ;
214+ } }
181215 className = "text-blue-500"
182216 >
183217 { notification . read ? (
0 commit comments