l-min-components 1.0.652 → 1.0.656

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.652",
3
+ "version": "1.0.656",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src/assets",
@@ -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
+ }
@@ -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,
@@ -240,6 +241,40 @@ const HeaderComponent = (props) => {
240
241
  return "Learning";
241
242
  };
242
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
+
243
278
  return (
244
279
  <Navbar>
245
280
  <img src={logo} alt="Learngual logo" />
@@ -74,13 +74,17 @@ const SideBar = ({ routes }) => {
74
74
  onClick={() => {
75
75
  deleteCookies("access");
76
76
  deleteCookies("refresh");
77
+ deleteCookies("activeDeveloperAccount");
78
+ deleteCookies("defaultAccountID");
79
+ deleteCookies("defaultAccountType");
80
+ deleteCookies("rememberMe");
77
81
  setTimeout(() => {
78
82
  if (
79
83
  window.location.hostname.includes("localhost") ||
80
84
  window.location.hostname.includes("staging")
81
85
  ) {
82
86
  window.location.href =
83
- "https://demo-test-01.learngual.com/login/developer";
87
+ "https://559staging.learngual.com/auth/sign-in/";
84
88
  } else {
85
89
  window.location.href =
86
90
  "https://demo.learngual.com/login/developer";