Skip to content

Commit d048945

Browse files
authored
fix notifications (#281)
1 parent 8833480 commit d048945

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

src/components/sidebar/navHeader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function NavBar() {
9999
const handleShowNotification = () => {
100100
const notificationPath = roleName === "superAdmin" || roleName === "admin" ? "/admin/notifications" : "/applicant/notifications";
101101
navigate(notificationPath);
102-
window.location.reload();
102+
// window.location.reload();
103103
};
104104
const handleShowProfileDropdown = () =>
105105
setShowProfileDropdown(!showProfileDropdown);

src/hooks/useAdminNotifications.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { useEffect, useState } from "react";
22
import { initializeAdminPusher, unsubscribeAdminPusher } from "../utils/adminNotifications/pusher";
3+
import { toastOptions } from "../utils/toast";
4+
import { toast } from "react-toastify";
35

46
interface Notification {
57
_id: string;
@@ -9,10 +11,11 @@ interface Notification {
911
}
1012
export const useAdminNotifications = () => {
1113
const [notifications, setNotifications] = useState<Notification[]>([]);
12-
14+
1315
useEffect(() => {
1416
const handleNewNotification = (notification: Notification) => {
1517
setNotifications((prev) => [...prev, notification]);
18+
toast.info(`New notification: ${notification.message}`, toastOptions);
1619
};
1720

1821
const channel = initializeAdminPusher(handleNewNotification);

src/pages/ApplicantNotifications/AppNotification.tsx

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
11
import React, { useState } from "react";
22
import { IoMdMailOpen, IoMdMailUnread } from "react-icons/io";
33
import { useNotifications } from "../../utils/Notifications";
4+
import { useNavigate } from "react-router";
45

56
interface 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+
1221
function 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 = ({
150176
const 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 ? (

src/pages/tickets/createTicketModal.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React, { useState} from "react";
22
import { toast, ToastContainer } from "react-toastify";
33
import * as icons from "react-icons/ai";
4+
import { AiOutlineLoading3Quarters } from "react-icons/ai";
45

56
const CreateTicketModal = ({ isOpen, onClose, onSubmit }) => {
67
const [ticket, setTicket] = useState({
@@ -18,7 +19,7 @@ const CreateTicketModal = ({ isOpen, onClose, onSubmit }) => {
1819
try {
1920
setIsSubmitting(true);
2021
await onSubmit(ticket);
21-
// toast.success("Ticket submitted successfully");
22+
toast.success("Ticket submitted successfully");
2223
handleClose();
2324
} catch (error: any) {
2425
const errorMessage =
@@ -93,7 +94,11 @@ const CreateTicketModal = ({ isOpen, onClose, onSubmit }) => {
9394
className="flex bg-primary dark:bg-[#56C870] rounded-md py-2 px-4 text-white font-medium cursor-pointer"
9495
disabled={isSubmitting}
9596
>
96-
Submit
97+
{isSubmitting ? (
98+
<AiOutlineLoading3Quarters className="animate-spin text-xl" />
99+
) : (
100+
"Submit"
101+
)}
97102
</button>
98103
<button
99104
type="button"
@@ -112,4 +117,4 @@ const CreateTicketModal = ({ isOpen, onClose, onSubmit }) => {
112117
);
113118
};
114119

115-
export default CreateTicketModal;
120+
export default CreateTicketModal;

src/utils/applicantNotifications/NotificationService.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export const fetchNotifications = async (
1515
message
1616
read
1717
createdAt
18+
eventType
19+
eventId
1820
}
1921
}`,
2022
variables: { userId },

src/utils/applicantNotifications/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export interface Notification {
22
id: string;
3+
eventType: string;
4+
eventId: string;
35
message: string;
46
read: boolean;
57
createdAt: string;

0 commit comments

Comments
 (0)