l-min-components 1.0.650 → 1.0.655

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.650",
3
+ "version": "1.0.655",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -30,3 +30,33 @@ export const NotificationIcon = ({ width, height, fill }) => (
30
30
  <circle cx="17.1797" cy="5" r="4.5" fill="#F39B33" stroke="white" />
31
31
  </svg>
32
32
  );
33
+ export const NotificationEmptyIcon = ({ width, height, fill }) => (
34
+ <svg
35
+ width={width || "23"}
36
+ height={height || "23"}
37
+ viewBox="0 0 23 23"
38
+ fill="none"
39
+ xmlns="http://www.w3.org/2000/svg">
40
+ <path
41
+ d="M10.891 3.59375C7.94042 3.59375 5.54254 5.99163 5.54254 8.94218V11.5183C5.54254 12.0621 5.31077 12.8911 5.03444 13.3546L4.00932 15.0572C3.37642 16.1091 3.81321 17.2768 4.97204 17.669C8.814 18.9527 12.959 18.9527 16.801 17.669C17.8796 17.3125 18.352 16.0378 17.7637 15.0572L16.7386 13.3546C16.4712 12.8911 16.2394 12.0621 16.2394 11.5183V8.94218C16.2394 6.00055 13.8326 3.59375 10.891 3.59375Z"
42
+ stroke="#4A4D4D"
43
+ strokeWidth="1.5"
44
+ strokeMiterlimit="10"
45
+ strokeLinecap="round"
46
+ />
47
+ <path
48
+ d="M12.5404 3.85266C12.2641 3.77244 11.9788 3.71004 11.6846 3.67438C10.8289 3.56741 10.0088 3.62981 9.24219 3.85266C9.5007 3.19302 10.1425 2.72949 10.8913 2.72949C11.6401 2.72949 12.2819 3.19302 12.5404 3.85266Z"
49
+ stroke="#4A4D4D"
50
+ strokeWidth="1.5"
51
+ strokeMiterlimit="10"
52
+ strokeLinecap="round"
53
+ strokeLinejoin="round"
54
+ />
55
+ <path
56
+ d="M13.5672 17.9902C13.5672 19.4611 12.3638 20.6645 10.893 20.6645C10.162 20.6645 9.48455 20.3614 9.00319 19.88C8.52183 19.3987 8.21875 18.7212 8.21875 17.9902"
57
+ stroke="#4A4D4D"
58
+ strokeWidth="1.5"
59
+ strokeMiterlimit="10"
60
+ />
61
+ </svg>
62
+ );
@@ -0,0 +1,19 @@
1
+ export function getCookie(name) {
2
+ // Split cookie string and get all individual name=value pairs in an array
3
+ var cookieArr = document.cookie.split(";");
4
+
5
+ // Loop through the array elements
6
+ for (var i = 0; i < cookieArr.length; i++) {
7
+ var cookiePair = cookieArr[i].split("=");
8
+
9
+ /* Removing whitespace at the beginning of the cookie name
10
+ and compare it with the given string */
11
+ if (name == cookiePair[0].trim()) {
12
+ // Decode the cookie value and return
13
+ return decodeURIComponent(cookiePair[1]);
14
+ }
15
+ }
16
+
17
+ // Return null if not found
18
+ return null;
19
+ }
@@ -68,6 +68,27 @@ const useHeader = () => {
68
68
  console.log(err);
69
69
  }
70
70
  };
71
+ const [{ ...unreadNotificationData }, getUnreadNotification] = useAxios(
72
+ {
73
+ method: "GET",
74
+ },
75
+ {
76
+ manual: true,
77
+ }
78
+ );
79
+
80
+ const handleGetUnreadNotification = async (read = false) => {
81
+ try {
82
+ await getUnreadNotification({
83
+ url: `/notify/v1/notifications/`,
84
+ params: {
85
+ read: read,
86
+ },
87
+ });
88
+ } catch (err) {
89
+ console.log(err);
90
+ }
91
+ };
71
92
 
72
93
  return {
73
94
  handleGetUserDetails,
@@ -78,6 +99,8 @@ const useHeader = () => {
78
99
  getDefaultAccount,
79
100
  handleSetDefaultAccount,
80
101
  setDefaultAccount,
102
+ unreadNotificationData,
103
+ handleGetUnreadNotification
81
104
  };
82
105
  };
83
106
  export default useHeader;
@@ -6,7 +6,7 @@ import { PeopleIcon } from "./assets/svg/people";
6
6
  import { MessageIcon } from "./assets/svg/message";
7
7
  import { SettingIcon } from "./assets/svg/setting";
8
8
  import { SearchIcon } from "./assets/svg/search";
9
- import { NotificationIcon } from "./assets/svg/notification";
9
+ import { NotificationEmptyIcon, NotificationIcon } from "./assets/svg/notification";
10
10
  import { ArrowDownIcon } from "./assets/svg/arrow-down";
11
11
  import AccountDropdown from "./account-dropdown";
12
12
  import avatar from "./assets/images/avatar.png";
@@ -24,6 +24,7 @@ import { OutletContext } from "..";
24
24
  import { useLocation } from "react-router-dom";
25
25
  import usFlag from "../../assets/images/usFlag.png";
26
26
  import LanguageDropdown from "./languageDropdown";
27
+ import { getCookie } from "./getCookies";
27
28
  /**
28
29
  * @param {{
29
30
  * type: string,
@@ -48,6 +49,8 @@ const HeaderComponent = (props) => {
48
49
  userDetails,
49
50
  getDefaultAccount,
50
51
  handleGetDefaultAccount,
52
+ unreadNotificationData,
53
+ handleGetUnreadNotification
51
54
  } = useHeader();
52
55
  const { pathname } = useLocation();
53
56
  const { setGeneralData, generalData } = useContext(OutletContext);
@@ -58,6 +61,7 @@ const HeaderComponent = (props) => {
58
61
  handleGetUserAccountsDetail();
59
62
  handleGetUserDetails();
60
63
  handleGetDefaultAccount();
64
+ handleGetUnreadNotification();
61
65
  }, []);
62
66
  useEffect(() => {
63
67
  if (userAccountsDetail?.data) {
@@ -237,6 +241,40 @@ const HeaderComponent = (props) => {
237
241
  return "Learning";
238
242
  };
239
243
 
244
+ // websocket for notifications initialization
245
+ const [socketUrl, setSocketUrl] = useState(
246
+ "dev-117782726-api.learngual.com/notify/v1/ws/connect/"
247
+ );
248
+ const socket = useRef()
249
+ const token = getCookie("access");
250
+ const account_id = generalData?.defaultAccount?.id || "";
251
+
252
+ useEffect(() => {
253
+ if(!socket?.current){
254
+ socket.current = new WebSocket(
255
+ `wss://${socketUrl}?account=${account_id}&authorization=${token}`
256
+ )
257
+
258
+ socket.current.onopen = () => {
259
+ console.log("websocket connection established");
260
+ };
261
+ socket.current.onmessage = (event) => {
262
+ const response = JSON?.parse(event?.data);
263
+ console.log(response)
264
+ if(response?.data){
265
+ handleGetUnreadNotification();
266
+ }
267
+
268
+ };
269
+
270
+ }
271
+
272
+ return () => {
273
+ console.log("websocket closed");
274
+ };
275
+
276
+ }, [socket]);
277
+
240
278
  return (
241
279
  <Navbar>
242
280
  <img src={logo} alt="Learngual logo" />
@@ -273,11 +311,22 @@ const HeaderComponent = (props) => {
273
311
  <SettingIcon /> Settings
274
312
  </a>
275
313
  </li>
276
- {/* <li>
277
- <a href="#">
278
- <NotificationIcon /> Notifications
314
+ <li>
315
+ <a
316
+ href="https://developer-staging-01.learngual.com/notifications/"
317
+ className={
318
+ window.location.pathname.includes("notifications") ? "active" : ""
319
+ }
320
+ style={{ cursor: "pointer" }}
321
+ >
322
+ {unreadNotificationData?.data?.count > 0 ? (
323
+ <NotificationIcon />
324
+ ) : (
325
+ <NotificationEmptyIcon />
326
+ )}
327
+ Notifications
279
328
  </a>
280
- </li> */}
329
+ </li>
281
330
  </Nav>
282
331
 
283
332
  <NavGroup