Skip to content

Commit 4769acf

Browse files
committed
fix(notification): refactors and fixes user notifications feature
1 parent 64af47e commit 4769acf

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

src/Mutations/notificationMutation.tsx

+18
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@ export const NotificationSubscription = gql`
4343
}
4444
}
4545
`;
46+
export const PUSH_NOTIFICATION_SUB = gql`
47+
subscription PushNotificationSub($receiverId: String!) {
48+
pushNotification(receiverId: $receiverId) {
49+
sender {
50+
profile {
51+
firstName
52+
lastName
53+
avatar
54+
}
55+
}
56+
createdAt
57+
message
58+
read
59+
receiver
60+
id
61+
}
62+
}
63+
`;
4664
export const deleteNotification = gql`
4765
mutation Mutation($deleteNotificationsId: ID!) {
4866
deleteNotifications(id: $deleteNotificationsId)

src/components/DashHeader.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { UserContext } from '../hook/useAuth';
1212
import {
1313
getAllNotification,
1414
NotificationSubscription,
15+
PUSH_NOTIFICATION_SUB,
1516
} from '../Mutations/notificationMutation';
1617
import { MenuContext } from '../hook/menuProvider';
1718
import ToggleThemeButton from './TogglethemeIcon';
@@ -74,6 +75,14 @@ function DashHeader() {
7475
receiver: user?.userId,
7576
},
7677
});
78+
useSubscription(PUSH_NOTIFICATION_SUB, {
79+
onData: (data) => {
80+
setNotificationData([data.data.data.pushNotification, ...notifications]);
81+
},
82+
variables: {
83+
receiverId: user?.userId,
84+
},
85+
});
7786

7887
/* istanbul ignore next */
7988
const handleShowProfileDropdown = () =>

src/components/Notification.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ function Notification({
7777
notifications?.map((notification: any) => {
7878
// eslint-disable-next-line no-nested-ternary
7979
/* istanbul ignore next */
80-
if (notification.read !== true) {
80+
if (!notification.read) {
8181
// eslint-disable-next-line no-nested-ternary
8282
/* istanbul ignore next */
8383
return { ...notification, read: true };
@@ -123,7 +123,7 @@ function Notification({
123123
>
124124
<div
125125
className={`flex flex-row justify-between align-center gap-x-[10px] ${
126-
notification.read === 'false'
126+
!notification.read
127127
? 'bg-[#E5EAFF] font-bold dark:bg-dark-tertiary'
128128
: 'border-border-dark dark:border-white dark:bg-dark-tertiary opacity-30 hover:bg-[#E5EAFF] hover:opacity-100 dark:hover:bg-dark-tertiary'
129129
}`}
@@ -186,14 +186,14 @@ function Notification({
186186
{notification.message}
187187
</p>
188188
<p className="text-[12px] dark:text-white">
189-
{format(new Date(notification.createdAt), 'MMMM dd, p')}
189+
{format(new Date(Number(notification.createdAt)), 'MMMM dd, p')}
190190
</p>
191191
</div>
192192

193193
<div className="flex flex-col items-center transition-all">
194194
<div
195195
className={`h-[15px] w-[15px] rounded-full ${
196-
notification.read === 'false'
196+
notification.read
197197
? 'bg-[#148FB6]'
198198
: 'border-border-dark dark:border-white border-[1px]'
199199
} mt-[7px] mb-[10px]`}

src/pages/AdminTraineeDashboard.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ function AdminTraineeDashboard() {
403403
},
404404
fetchPolicy: 'network-only',
405405
onError: (error) => {
406+
console.log(error.message);
406407
toast.error(error.message);
407408
},
408409
});

0 commit comments

Comments
 (0)