l-min-components 1.0.660 → 1.0.666

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "l-min-components",
3
- "version": "1.0.660",
3
+ "version": "1.0.666",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -111,6 +111,26 @@ const handleGeneralNotificationCount= async () => {
111
111
  }
112
112
  };
113
113
 
114
+ // Mark All Notification as Read Notification
115
+ const [{ ...notificationMarkReadData }, getNotificationMarkRead] = useAxios(
116
+ {
117
+ method: "PUT",
118
+ },
119
+ {
120
+ manual: true,
121
+ }
122
+ );
123
+
124
+ const handleGetNotificationMarkRead = async () => {
125
+ try {
126
+ await getNotificationMarkRead({
127
+ url: `/notify/v1/notifications/mark_all_as_read/`,
128
+ });
129
+ } catch (err) {
130
+ console.log(err);
131
+ }
132
+ };
133
+
114
134
  return {
115
135
  handleGetUserDetails,
116
136
  userDetails,
@@ -123,7 +143,9 @@ const handleGeneralNotificationCount= async () => {
123
143
  unreadNotificationData,
124
144
  handleGetUnreadNotification,
125
145
  generalNotificationCountData,
126
- handleGeneralNotificationCount
146
+ handleGeneralNotificationCount,
147
+ notificationMarkReadData,
148
+ handleGetNotificationMarkRead
127
149
  };
128
150
  };
129
151
  export default useHeader;
@@ -54,6 +54,7 @@ const HeaderComponent = (props) => {
54
54
  handleGetUnreadNotification,
55
55
  generalNotificationCountData,
56
56
  handleGeneralNotificationCount,
57
+ notificationMarkReadData
57
58
  } = useHeader();
58
59
  const { pathname } = useLocation();
59
60
  const { setGeneralData, generalData } = useContext(OutletContext);
@@ -267,61 +268,51 @@ const HeaderComponent = (props) => {
267
268
  const generalSocket = useRef()
268
269
  const token = getCookie("access");
269
270
  const account_id = generalData?.defaultAccount?.id || "";
270
-
271
- useEffect(() => {
272
- if(!socket?.current){
273
- socket.current = new WebSocket(
274
- `wss://${socketUrl}?account=${account_id}&authorization=${token}`
275
- )
276
-
277
- socket.current.onopen = () => {
278
- console.log("websocket connection established");
279
- };
280
- socket.current.onmessage = (event) => {
281
- const response = JSON?.parse(event?.data);
282
- console.log(response)
283
- if(response?.data){
284
- handleGetUnreadNotification();
285
- }
286
-
287
- };
288
271
 
289
- }
272
+ // websocket for all notification account
273
+ const websocket = new WebSocket(
274
+ `wss://${socketUrl}?account=${account_id}&authorization=${token}`
275
+ );
290
276
 
291
- return () => {
292
- console.log("websocket closed");
277
+ useEffect(() => {
278
+ websocket.onopen = () => {
279
+ //check if socket is connected
280
+ console.log("websocket connection established");
293
281
  };
294
-
295
- }, [socket]);
296
282
 
283
+ websocket.onmessage = (event) => {
284
+ const data = JSON.parse(event.data);
285
+ console.log("websocket data", data);
286
+ };
297
287
 
298
- // websocket for all notification account
299
- useEffect(() => {
300
- if(!generalSocket?.current){
301
- generalSocket.current = new WebSocket(
302
- `wss://${socketUrl}?authorization=${token}`
303
- )
304
-
305
- generalSocket.current.onopen = () => {
306
- console.log("General websocket connection established");
307
- };
308
- generalSocket.current.onmessage = (event) => {
309
- const response = JSON?.parse(event?.data);
310
- console.log(response)
311
- if(response?.data){
312
- handleGeneralNotificationCount();
288
+ const handler = (event) => {
289
+ if (event?.data) {
290
+ const data = JSON.parse(event?.data); //check for incoming message from socket
291
+ if (data.event === "new.notification.result") {
292
+ if (data.data) {
293
+ console.log(data)
294
+ handleGetUnreadNotification();
295
+ handleGeneralNotificationCount();
296
+ }
313
297
  }
314
-
315
- };
316
298
 
317
- }
299
+ }
300
+ };
301
+ websocket.addEventListener("message", handler, { passive: true });
318
302
 
319
303
  return () => {
320
- console.log("General websocket closed");
304
+ websocket.removeEventListener("message", handler);
305
+ console.log("websocket closed");
321
306
  };
322
-
323
- }, [generalSocket]);
307
+ }, [websocket]);
308
+
324
309
 
310
+ useEffect(() => {
311
+ if(notificationMarkReadData?.response){
312
+ handleGetUnreadNotification();
313
+ handleGeneralNotificationCount();
314
+ }
315
+ }, [notificationMarkReadData?.response])
325
316
 
326
317
  return (
327
318
  <Navbar>