l-min-components 1.7.1294 → 1.7.1296
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
|
@@ -133,8 +133,7 @@ const AppMainLayout = ({ children }) => {
|
|
|
133
133
|
user,
|
|
134
134
|
userDetails,
|
|
135
135
|
} = useHeader({ default: true });
|
|
136
|
-
// get current default account and store in cookie (from api)
|
|
137
|
-
|
|
136
|
+
// get current default account and store in cookie (from api);
|
|
138
137
|
useEffect(() => {
|
|
139
138
|
if (getDefaultAccount?.data) {
|
|
140
139
|
const date = new Date();
|
|
@@ -298,7 +297,7 @@ const AppMainLayout = ({ children }) => {
|
|
|
298
297
|
setIsTranslationsLoading,
|
|
299
298
|
} = useTranslation(wordBank);
|
|
300
299
|
|
|
301
|
-
const messageKit = useMessageKit(
|
|
300
|
+
const messageKit = useMessageKit(); // useMessageKit
|
|
302
301
|
|
|
303
302
|
return (
|
|
304
303
|
<OutletContext.Provider
|
|
@@ -98,7 +98,6 @@ const InstructorAccountSwitcher = ({ generalData, onChange }) => {
|
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
const { accountName, planState } = useContext(OutletContext);
|
|
101
|
-
|
|
102
101
|
// handle if account does not have subscription but is an affiliate
|
|
103
102
|
const prioritizedAffiliateId = useMemo(() => {
|
|
104
103
|
let prioritizedAffiliateId = null;
|
|
@@ -112,6 +111,7 @@ const InstructorAccountSwitcher = ({ generalData, onChange }) => {
|
|
|
112
111
|
) {
|
|
113
112
|
// Priority 2: If no cookie, no subscription, and list exists...
|
|
114
113
|
// Assign the ID of the *first* affiliate directly from the results array
|
|
114
|
+
setCookie(getAllAffiliateData.data.results[0]?.id);
|
|
115
115
|
prioritizedAffiliateId = getAllAffiliateData.data.results[0]?.id; // Optional chaining on 'id'
|
|
116
116
|
}
|
|
117
117
|
return prioritizedAffiliateId;
|
|
@@ -240,7 +240,7 @@ const InstructorAccountSwitcher = ({ generalData, onChange }) => {
|
|
|
240
240
|
</div>
|
|
241
241
|
{
|
|
242
242
|
<div className="btn__wrapper">
|
|
243
|
-
{
|
|
243
|
+
{(planState === "ACTIVE" || planState === "GRACE PERIOD") && (
|
|
244
244
|
<button
|
|
245
245
|
className={switchValue !== "affiliates" ? "active" : ""}
|
|
246
246
|
onClick={() => handleSwitch(1)}>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import useAxios from "axios-hooks";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useState, useRef } from "react";
|
|
3
3
|
import sound from "./new-notification-7-210334.mp3";
|
|
4
|
+
import { cookieGrabber, useCookiePolling } from "../utils/cookiePolling";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Represents the details of the last message in a chat room overview.
|
|
@@ -236,38 +237,29 @@ import sound from "./new-notification-7-210334.mp3";
|
|
|
236
237
|
* @property {any | null} media - The media data (e.g., File object, FormData details). Needs proper handling before API call.
|
|
237
238
|
*/
|
|
238
239
|
|
|
239
|
-
const useMessageKit = (
|
|
240
|
-
const
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
if (!string) return "";
|
|
248
|
-
return string.split("=")[1].trim();
|
|
240
|
+
const useMessageKit = () => {
|
|
241
|
+
const selectedAccountId = useCookiePolling("defaultAccountID");
|
|
242
|
+
const defaultAccountType = useCookiePolling("defaultAccountType");
|
|
243
|
+
const selectedAccount = {
|
|
244
|
+
id: selectedAccountId,
|
|
245
|
+
type: defaultAccountType,
|
|
249
246
|
};
|
|
250
|
-
const
|
|
251
|
-
() => ({
|
|
252
|
-
id: cookieGrabber("defaultAccountID"),
|
|
253
|
-
type: cookieGrabber("defaultAccountType"),
|
|
254
|
-
}),
|
|
255
|
-
[]
|
|
256
|
-
);
|
|
247
|
+
const token = useCookiePolling("access");
|
|
257
248
|
const buildSocketUrl = useCallback(() => {
|
|
258
249
|
const baseUrl =
|
|
259
250
|
window.location.hostname.includes("staging") ||
|
|
260
251
|
window.location.hostname.includes("localhost")
|
|
261
252
|
? "https://dev-117782726-api.learngual.com"
|
|
262
253
|
: "https://api.learngual.com";
|
|
263
|
-
|
|
254
|
+
|
|
264
255
|
return (
|
|
265
256
|
baseUrl.replace("http", "ws") +
|
|
266
257
|
`/notify/v1/ws/connect/?authorization=${token}&_account=${selectedAccount.id}`
|
|
267
258
|
);
|
|
268
259
|
}, []);
|
|
269
260
|
|
|
270
|
-
const affiliateAccount =
|
|
261
|
+
const affiliateAccount = useCookiePolling("affiliateAccount", 1000);
|
|
262
|
+
console.log("changed", affiliateAccount);
|
|
271
263
|
// console.log(affiliateAccount, affiliatesActive, "affiliate");
|
|
272
264
|
// get account type
|
|
273
265
|
const [, request] = useAxios(
|
|
@@ -1441,6 +1433,7 @@ const useMessageKit = ({ affiliateAccount: AffiliateAccount }) => {
|
|
|
1441
1433
|
// Initial data fetch effect
|
|
1442
1434
|
useEffect(() => {
|
|
1443
1435
|
(async () => {
|
|
1436
|
+
if (!selectedAccountId || !defaultAccountType || !token) return;
|
|
1444
1437
|
await getMessageRoomsByCourses();
|
|
1445
1438
|
// reportChat({
|
|
1446
1439
|
// reasons: ["Verbal harassment"],
|
|
@@ -1462,7 +1455,7 @@ const useMessageKit = ({ affiliateAccount: AffiliateAccount }) => {
|
|
|
1462
1455
|
// accountId: "24dbaeede1",
|
|
1463
1456
|
// });
|
|
1464
1457
|
})();
|
|
1465
|
-
}, [
|
|
1458
|
+
}, [affiliateAccount, token, defaultAccountType, selectedAccountId]); // Rerun when selectedAccount changes
|
|
1466
1459
|
// console.log(
|
|
1467
1460
|
// getMessagesForRoom("5be9b48281ac4c2885d3b719654ed59d", "878", "24dbaeede1"),
|
|
1468
1461
|
// "hold versions"
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
|
|
3
|
+
//helper function to get cookie
|
|
4
|
+
export const cookieGrabber = (key = "") => {
|
|
5
|
+
const cookies = document.cookie;
|
|
6
|
+
const string = cookies.split(";").find((cookie) => {
|
|
7
|
+
cookie = cookie.trim();
|
|
8
|
+
if (cookie.startsWith(key.trim() + "=")) return true;
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
if (!string) return "";
|
|
12
|
+
return string.split("=")[1].trim();
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Custom hook to poll a specific cookie and update state on change.
|
|
17
|
+
*
|
|
18
|
+
* @param {string} cookieName The name of the cookie to monitor.
|
|
19
|
+
* @param {number} intervalMs The polling interval in milliseconds (e.g., 1000 for 1 second).
|
|
20
|
+
* @returns {string | null} The current value of the cookie.
|
|
21
|
+
*/
|
|
22
|
+
export function useCookiePolling(cookieName, intervalMs = 500) {
|
|
23
|
+
const [cookieValue, setCookieValue] = useState(() =>
|
|
24
|
+
cookieGrabber(cookieName)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const intervalId = setInterval(() => {
|
|
29
|
+
const currentValue = cookieGrabber(cookieName);
|
|
30
|
+
// Update state only if the value has actually changed
|
|
31
|
+
if (currentValue !== cookieValue) {
|
|
32
|
+
console.log(
|
|
33
|
+
`Cookie '${cookieName}' changed from '${cookieValue}' to '${currentValue}'`
|
|
34
|
+
);
|
|
35
|
+
setCookieValue(currentValue);
|
|
36
|
+
}
|
|
37
|
+
}, intervalMs);
|
|
38
|
+
|
|
39
|
+
// Cleanup: clear the interval when the component unmounts or dependencies change
|
|
40
|
+
return () => clearInterval(intervalId);
|
|
41
|
+
}, [cookieName, intervalMs, cookieValue]); // Re-run effect if cookieName or interval changes, or if cookieValue was updated
|
|
42
|
+
|
|
43
|
+
return cookieValue;
|
|
44
|
+
}
|