Skip to content

Commit 40ddd61

Browse files
authored
fix(notification): refactors and fixes user notifications feature (#446)
1 parent 0d8badc commit 40ddd61

9 files changed

+319
-138
lines changed

package-lock.json

+6-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Mutations/notificationMutation.tsx

+23-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const getAllNotification = gql`
88
receiver
99
createdAt
1010
read
11+
type
1112
sender {
1213
profile {
1314
firstName
@@ -38,6 +39,27 @@ export const NotificationSubscription = gql`
3839
createdAt
3940
message
4041
read
42+
type
43+
receiver
44+
id
45+
}
46+
}
47+
`;
48+
export const PUSH_NOTIFICATION_SUB = gql`
49+
subscription PushNotificationSub($receiverId: String!) {
50+
pushNotification(receiverId: $receiverId) {
51+
sender {
52+
profile {
53+
firstName
54+
lastName
55+
name
56+
avatar
57+
}
58+
}
59+
createdAt
60+
message
61+
read
62+
type
4163
receiver
4264
id
4365
}
@@ -82,4 +104,4 @@ export const updatedPushNotifications = gql`
82104
query Query($getUpdatedPushNotificationsId: ID!) {
83105
getUpdatedPushNotifications(id: $getUpdatedPushNotificationsId)
84106
}
85-
`;
107+
`;

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 = () =>

0 commit comments

Comments
 (0)