l-min-components 1.0.656 → 1.0.664
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
|
@@ -24,7 +24,11 @@ const AccountDropdown = (props) => {
|
|
|
24
24
|
const navigate = useNavigate();
|
|
25
25
|
const { pathname } = useLocation();
|
|
26
26
|
useEffect(() => {}, [pathname]);
|
|
27
|
-
const {
|
|
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
|
-
{
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,34 +264,47 @@ 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
|
+
|
|
271
|
+
// websocket for all notification account
|
|
272
|
+
const websocket = new WebSocket(
|
|
273
|
+
`wss://${socketUrl}?account=${account_id}&authorization=${token}`
|
|
274
|
+
);
|
|
275
|
+
|
|
252
276
|
useEffect(() => {
|
|
253
|
-
|
|
254
|
-
socket
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
277
|
+
websocket.onopen = () => {
|
|
278
|
+
//check if socket is connected
|
|
279
|
+
console.log("websocket connection established");
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
websocket.onmessage = (event) => {
|
|
283
|
+
const data = JSON.parse(event.data);
|
|
284
|
+
console.log("websocket data", data);
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
const handler = (event) => {
|
|
288
|
+
if (event?.data) {
|
|
289
|
+
const data = JSON.parse(event?.data); //check for incoming message from socket
|
|
290
|
+
if (data.event === "new.notification.result") {
|
|
291
|
+
if (data.data) {
|
|
292
|
+
console.log(data)
|
|
293
|
+
handleGetUnreadNotification();
|
|
294
|
+
handleGeneralNotificationCount();
|
|
295
|
+
}
|
|
266
296
|
}
|
|
267
|
-
|
|
268
|
-
};
|
|
269
297
|
|
|
270
|
-
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
websocket.addEventListener("message", handler, { passive: true });
|
|
271
301
|
|
|
272
302
|
return () => {
|
|
303
|
+
websocket.removeEventListener("message", handler);
|
|
273
304
|
console.log("websocket closed");
|
|
274
305
|
};
|
|
275
|
-
|
|
276
|
-
|
|
306
|
+
}, [websocket]);
|
|
307
|
+
|
|
277
308
|
|
|
278
309
|
return (
|
|
279
310
|
<Navbar>
|