l-min-components 1.0.656 → 1.0.660

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.656",
3
+ "version": "1.0.660",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -24,7 +24,11 @@ const AccountDropdown = (props) => {
24
24
  const navigate = useNavigate();
25
25
  const { pathname } = useLocation();
26
26
  useEffect(() => {}, [pathname]);
27
- const { setDefaultAccount, handleSetDefaultAccount } = useHeader();
27
+ const {
28
+ setDefaultAccount,
29
+ handleSetDefaultAccount,
30
+ } = useHeader();
31
+
28
32
  const { envType } = useContext(OutletContext);
29
33
 
30
34
  useEffect(() => {
@@ -145,7 +149,9 @@ const AccountDropdown = (props) => {
145
149
  {developerItem?.metadata?.organization_name ||
146
150
  props.accountName}
147
151
  </h1>
148
- {/* <span>{props.notificationCount} </span> */}
152
+ {developerItem?.notification_count > 0 && (
153
+ <span>{developerItem?.notification_count}</span>
154
+ )}
149
155
  </div>
150
156
  </div>
151
157
  ))}
@@ -186,7 +192,9 @@ const AccountDropdown = (props) => {
186
192
  {" "}
187
193
  {instructorItem?.display_name || props.accountName}
188
194
  </h1>
189
- <span>{props.notificationCount} </span>
195
+ {instructorItem?.notification_count > 0 && (
196
+ <span>{instructorItem?.notification_count} </span>
197
+ )}
190
198
  </div>
191
199
  </div>
192
200
  ))}
@@ -222,7 +230,9 @@ const AccountDropdown = (props) => {
222
230
  {" "}
223
231
  {enterpriseItem?.display_name || props.accountName}
224
232
  </h1>
225
- <span>{props.notificationCount} </span>
233
+ {enterpriseItem?.notification_count > 0 && (
234
+ <span>{enterpriseItem?.notification_count} </span>
235
+ )}
226
236
  </div>
227
237
  </div>
228
238
  ))}
@@ -259,7 +269,9 @@ const AccountDropdown = (props) => {
259
269
  {" "}
260
270
  {personalItem?.display_name || props.accountName}
261
271
  </h1>
262
- <span>{props.notificationCount} </span>
272
+ {personalItem?.notification_count > 0 && (
273
+ <span>{personalItem?.notification_count} </span>
274
+ )}
263
275
  </div>
264
276
  </div>
265
277
  ))}
@@ -90,6 +90,27 @@ const useHeader = () => {
90
90
  }
91
91
  };
92
92
 
93
+
94
+ // general notification count
95
+ const [{ ...generalNotificationCountData }, generalNotificationCount] = useAxios(
96
+ {
97
+ method: "GET",
98
+ },
99
+ {
100
+ manual: true,
101
+ }
102
+ );
103
+
104
+ const handleGeneralNotificationCount= async () => {
105
+ try {
106
+ await generalNotificationCount({
107
+ url: `/notify/v1/notifications/general_notification_count/`,
108
+ });
109
+ } catch (err) {
110
+ console.log(err);
111
+ }
112
+ };
113
+
93
114
  return {
94
115
  handleGetUserDetails,
95
116
  userDetails,
@@ -100,7 +121,9 @@ const useHeader = () => {
100
121
  handleSetDefaultAccount,
101
122
  setDefaultAccount,
102
123
  unreadNotificationData,
103
- handleGetUnreadNotification
124
+ handleGetUnreadNotification,
125
+ generalNotificationCountData,
126
+ handleGeneralNotificationCount
104
127
  };
105
128
  };
106
129
  export default useHeader;
@@ -25,6 +25,7 @@ import { useLocation } from "react-router-dom";
25
25
  import usFlag from "../../assets/images/usFlag.png";
26
26
  import LanguageDropdown from "./languageDropdown";
27
27
  import { getCookie } from "./getCookies";
28
+ import { data } from "../GraphMap/data";
28
29
  /**
29
30
  * @param {{
30
31
  * type: string,
@@ -50,7 +51,9 @@ const HeaderComponent = (props) => {
50
51
  getDefaultAccount,
51
52
  handleGetDefaultAccount,
52
53
  unreadNotificationData,
53
- handleGetUnreadNotification
54
+ handleGetUnreadNotification,
55
+ generalNotificationCountData,
56
+ handleGeneralNotificationCount,
54
57
  } = useHeader();
55
58
  const { pathname } = useLocation();
56
59
  const { setGeneralData, generalData } = useContext(OutletContext);
@@ -63,6 +66,21 @@ const HeaderComponent = (props) => {
63
66
  handleGetDefaultAccount();
64
67
  handleGetUnreadNotification();
65
68
  }, []);
69
+
70
+ // Merge the notification_count into the results data using find
71
+
72
+ const allUserAccountsDetail = userAccountsDetail?.data?.results.map(item => {
73
+ const detail = generalNotificationCountData?.data?.detail?.find(detailItem => detailItem?.account_id === item?.id);
74
+ return {
75
+ ...item,
76
+ notification_count: detail ? detail?.notification_count : 0
77
+ };
78
+ });
79
+
80
+ useEffect(() => {
81
+ handleGeneralNotificationCount();
82
+ }, [])
83
+
66
84
  useEffect(() => {
67
85
  if (userAccountsDetail?.data) {
68
86
  setGeneralData((generalData) => ({
@@ -90,7 +108,7 @@ const HeaderComponent = (props) => {
90
108
  let instructorArray = [];
91
109
  let enterpriseArray = [];
92
110
 
93
- userAccountsDetail?.data?.results?.map((accountItem, idx) => {
111
+ allUserAccountsDetail?.map((accountItem, idx) => {
94
112
  if (
95
113
  accountItem?.type === "PERSONAL" &&
96
114
  !personalAccountData?.includes(accountItem)
@@ -139,7 +157,7 @@ const HeaderComponent = (props) => {
139
157
  setSelectedAccount(enterpriseArray[0]);
140
158
  }
141
159
  }
142
- }, [userAccountsDetail?.data]);
160
+ }, [userAccountsDetail?.data, generalNotificationCountData?.response]);
143
161
 
144
162
  // update general data when selected acct changes
145
163
 
@@ -246,6 +264,7 @@ const HeaderComponent = (props) => {
246
264
  "dev-117782726-api.learngual.com/notify/v1/ws/connect/"
247
265
  );
248
266
  const socket = useRef()
267
+ const generalSocket = useRef()
249
268
  const token = getCookie("access");
250
269
  const account_id = generalData?.defaultAccount?.id || "";
251
270
 
@@ -275,6 +294,35 @@ const HeaderComponent = (props) => {
275
294
 
276
295
  }, [socket]);
277
296
 
297
+
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();
313
+ }
314
+
315
+ };
316
+
317
+ }
318
+
319
+ return () => {
320
+ console.log("General websocket closed");
321
+ };
322
+
323
+ }, [generalSocket]);
324
+
325
+
278
326
  return (
279
327
  <Navbar>
280
328
  <img src={logo} alt="Learngual logo" />