acsi-core 0.9.18 → 0.9.20

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.
@@ -17,11 +17,11 @@ import 'katex/dist/katex.min.css';
17
17
  import Cookies from 'js-cookie';
18
18
  export { default as Cookies } from 'js-cookie';
19
19
  import moment from 'moment';
20
+ import { LogLevel, PublicClientApplication } from '@azure/msal-browser';
20
21
  import { toast } from 'react-toastify';
21
22
  export { ToastContainer, toast } from 'react-toastify';
22
23
  import { useGoogleLogout } from '@leecheuk/react-google-login';
23
24
  import { Box, Typography } from '@mui/material';
24
- import '@azure/msal-browser';
25
25
  import { Identify, identify, track, setUserId, reset as reset$1, init } from '@amplitude/analytics-browser';
26
26
  import { init as init$1, replayIntegration } from '@sentry/react';
27
27
  import { FaCaretDown } from 'react-icons/fa';
@@ -671,25 +671,6 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
671
671
 
672
672
  var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","microsoft_button":"_19ESb","box-field":"_2e9xO","box-input":"_3zXRp","box-text":"_8NJga","box-button-email":"_21FPk","box-signin-container":"_1QERu","box-signin-text":"_2-znH","box-signin-logo":"_1aB2m","box-right":"_3qndF","image-slideshow":"_1aM7m","active":"_Vx1zf","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r","width-400":"_4ehXP"};
673
673
 
674
- // A type of promise-like that resolves synchronously and supports only one observer
675
-
676
- const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
677
-
678
- const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
679
-
680
- // Asynchronously call a function and send errors to recovery continuation
681
- function _catch(body, recover) {
682
- try {
683
- var result = body();
684
- } catch(e) {
685
- return recover(e);
686
- }
687
- if (result && result.then) {
688
- return result.then(void 0, recover);
689
- }
690
- return result;
691
- }
692
-
693
674
  function _arrayLikeToArray(r, a) {
694
675
  (null == a || a > r.length) && (a = r.length);
695
676
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -738,6 +719,25 @@ function _unsupportedIterableToArray(r, a) {
738
719
  }
739
720
  }
740
721
 
722
+ // A type of promise-like that resolves synchronously and supports only one observer
723
+
724
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
725
+
726
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
727
+
728
+ // Asynchronously call a function and send errors to recovery continuation
729
+ function _catch(body, recover) {
730
+ try {
731
+ var result = body();
732
+ } catch(e) {
733
+ return recover(e);
734
+ }
735
+ if (result && result.then) {
736
+ return result.then(void 0, recover);
737
+ }
738
+ return result;
739
+ }
740
+
741
741
  var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
742
742
 
743
743
  var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
@@ -2322,6 +2322,56 @@ var TypeLogin;
2322
2322
  TypeLogin[TypeLogin["Microsoft"] = 3] = "Microsoft";
2323
2323
  })(TypeLogin || (TypeLogin = {}));
2324
2324
 
2325
+ var AuthenticationMessage;
2326
+ (function (AuthenticationMessage) {
2327
+ AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
2328
+ AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
2329
+ })(AuthenticationMessage || (AuthenticationMessage = {}));
2330
+ var Role;
2331
+ (function (Role) {
2332
+ Role["Student"] = "Student";
2333
+ Role["Teacher"] = "Teacher";
2334
+ Role["Admin"] = "Admin";
2335
+ })(Role || (Role = {}));
2336
+ var msalConfig = function msalConfig(clientId, redirectUri) {
2337
+ return {
2338
+ auth: {
2339
+ clientId: clientId,
2340
+ authority: "https://login.microsoftonline.com/common",
2341
+ redirectUri: redirectUri
2342
+ },
2343
+ cache: {
2344
+ cacheLocation: "sessionStorage",
2345
+ storeAuthStateInCookie: false
2346
+ },
2347
+ system: {
2348
+ loggerOptions: {
2349
+ loggerCallback: function loggerCallback(level, message, containsPii) {
2350
+ if (containsPii) {
2351
+ return;
2352
+ }
2353
+ switch (level) {
2354
+ case LogLevel.Error:
2355
+ console.error(message);
2356
+ return;
2357
+ case LogLevel.Info:
2358
+ console.info(message);
2359
+ return;
2360
+ case LogLevel.Verbose:
2361
+ console.debug(message);
2362
+ return;
2363
+ case LogLevel.Warning:
2364
+ console.warn(message);
2365
+ return;
2366
+ default:
2367
+ return;
2368
+ }
2369
+ }
2370
+ }
2371
+ }
2372
+ };
2373
+ };
2374
+
2325
2375
  var BlockLogin = function BlockLogin(_ref) {
2326
2376
  var onNavigate = _ref.onNavigate,
2327
2377
  role = _ref.role,
@@ -2456,6 +2506,91 @@ var BlockLogin = function BlockLogin(_ref) {
2456
2506
  return console.log(errorResponse);
2457
2507
  }
2458
2508
  });
2509
+ var fnLoginMicrosoft = function fnLoginMicrosoft() {
2510
+ try {
2511
+ var msalInstance = new PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
2512
+ if (!msalInstance) {
2513
+ console.error("MSAL instance not initialized");
2514
+ return Promise.resolve();
2515
+ }
2516
+ return Promise.resolve(_catch(function () {
2517
+ return Promise.resolve(msalInstance.initialize()).then(function () {
2518
+ var loginRequest = {
2519
+ scopes: ["openid", "profile", "email"]
2520
+ };
2521
+ var silentRequest = _extends$1({}, loginRequest, {
2522
+ prompt: "select_account"
2523
+ });
2524
+ return Promise.resolve(msalInstance.loginPopup(silentRequest)).then(function (response) {
2525
+ return function () {
2526
+ if (response && response.account) {
2527
+ var account = response.account;
2528
+ var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
2529
+ var infoLogin = {
2530
+ firstName: fullName.split(' ').slice(0, -1).join(' '),
2531
+ lastName: fullName.split(' ').slice(-1).join(' '),
2532
+ fullName: fullName,
2533
+ imageUrl: "",
2534
+ email: (account === null || account === void 0 ? void 0 : account.username) || "",
2535
+ token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
2536
+ googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
2537
+ role: role,
2538
+ type: TypeLogin.Microsoft
2539
+ };
2540
+ dispatch(setLoading(true));
2541
+ return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2542
+ var _authResult$data2;
2543
+ if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
2544
+ dispatch(setLoading(false));
2545
+ alert("Please contact admin.");
2546
+ return;
2547
+ }
2548
+ localStorage.clear();
2549
+ var tokenJWT = authResult.data.token;
2550
+ trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
2551
+ eventName: AmplitudeEvent.LOGIN,
2552
+ eventProperties: {
2553
+ email: email,
2554
+ login_method: 'google',
2555
+ user_role: authResult.data.role,
2556
+ success: true,
2557
+ timestamp: new Date().toISOString()
2558
+ }
2559
+ });
2560
+ if (role === "LandingPage") {
2561
+ CookieService.setAuthCookie({
2562
+ token: tokenJWT,
2563
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
2564
+ });
2565
+ var getRedirectUrl = function getRedirectUrl(role) {
2566
+ switch (role) {
2567
+ case "Admin":
2568
+ return ADMIN_ORIGIN;
2569
+ case "Teacher":
2570
+ return TEACHER_ORIGIN;
2571
+ default:
2572
+ return role + "." + REQUEST_ORIGIN;
2573
+ }
2574
+ };
2575
+ var redirectUrl = getRedirectUrl(authResult.data.role);
2576
+ window.location.href = redirectUrl + "/dashboard";
2577
+ dispatch(setLoading(false));
2578
+ }
2579
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2580
+ onNavigate("/dashboard");
2581
+ dispatch(setLoading(false));
2582
+ });
2583
+ }
2584
+ }();
2585
+ });
2586
+ });
2587
+ }, function (error) {
2588
+ console.error("Microsoft login error:", error);
2589
+ }));
2590
+ } catch (e) {
2591
+ return Promise.reject(e);
2592
+ }
2593
+ };
2459
2594
  React.useEffect(function () {
2460
2595
  return function () {
2461
2596
  if (resendTimer) {
@@ -2563,7 +2698,18 @@ var BlockLogin = function BlockLogin(_ref) {
2563
2698
  height: 24,
2564
2699
  alt: "Google sign-in",
2565
2700
  src: "/images/icons/Google__G__logo.png"
2566
- }), "Sign in with Google")), React.createElement("span", {
2701
+ }), "Sign in with Google")), React.createElement("div", {
2702
+ className: "" + styleGlobal["microsoft_button"]
2703
+ }, React.createElement("button", {
2704
+ onClick: function onClick() {
2705
+ return fnLoginMicrosoft();
2706
+ }
2707
+ }, React.createElement("img", {
2708
+ width: 24,
2709
+ height: 24,
2710
+ alt: "Google sign-in",
2711
+ src: "/images/Single-Sign-On-logo.png"
2712
+ }), "Sign in with Microsoft")), React.createElement("span", {
2567
2713
  className: "" + styleGlobal["box-field"]
2568
2714
  }, "OR"), React.createElement("div", {
2569
2715
  className: "" + styleGlobal["box-input"]
@@ -3394,18 +3540,6 @@ var CommonDialog = function CommonDialog(_ref) {
3394
3540
  }, title)), children);
3395
3541
  };
3396
3542
 
3397
- var AuthenticationMessage;
3398
- (function (AuthenticationMessage) {
3399
- AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
3400
- AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
3401
- })(AuthenticationMessage || (AuthenticationMessage = {}));
3402
- var Role;
3403
- (function (Role) {
3404
- Role["Student"] = "Student";
3405
- Role["Teacher"] = "Teacher";
3406
- Role["Admin"] = "Admin";
3407
- })(Role || (Role = {}));
3408
-
3409
3543
  var CustomPagination = function CustomPagination(_ref) {
3410
3544
  var currentPage = _ref.currentPage,
3411
3545
  totalPage = _ref.totalPage,
@@ -3908,17 +4042,7 @@ var utcToLocalTime = (function (time, FORMAT) {
3908
4042
  }
3909
4043
  });
3910
4044
 
3911
- var timeSpanToLocalMoment = (function (time) {
3912
- if (!time) return null;
3913
- var times = time.split(":");
3914
- if (times.length !== 3) return null;
3915
- var totalSeconds = +times[0] * 60 * 60 + +times[1] * 60 + +times[2];
3916
- var startOfDay = moment.utc().startOf("day");
3917
- var dateTime = startOfDay.add(totalSeconds, "seconds");
3918
- return dateTime.local();
3919
- });
3920
-
3921
4045
  var historyCore = createBrowserHistory();
3922
4046
 
3923
- export { ACCESS_TOKEN, AmplitudeEvent, BASE_URL, CommonDialog, ConfirmDialog, CoreButton, CoreInput$1 as CoreCheckbox, CoreError, CoreInput, CoreInputCompact, CoreModal, CoreRadio, CoreRange, CoreSearch, CoreSelect, CoreSelectCompact, CoreTextArea, CoreTitleInput, CoreTooltip, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, CustomSelectOption, DATE_TIME_MIN_VALUE, LayoutContext, Loading, Login, MarkdownRenderer as MarkdownLatexRender, NotFound, OPENSALT_BASE_URL, ORGANIZATION_TEAM, ORGANIZATION_TENANT, Role, api, apiUpload, firstCheckToken, getAccessToken, getErrorMessage, getImageUrl, historyCore, initSentry, initializeAmplitude, setAddTenant, setAlert, setIsRefetchSidebar, setLoading, setLoadingPage, setMenuCollapse, setTeam, setTenant, setUser, store, timeSpanToLocalMoment, useAmplitude, useGoogleSignOut, utcToLocalTime };
4047
+ export { ACCESS_TOKEN, AmplitudeEvent, BASE_URL, CommonDialog, ConfirmDialog, CoreButton, CoreInput$1 as CoreCheckbox, CoreError, CoreInput, CoreInputCompact, CoreModal, CoreRadio, CoreRange, CoreSearch, CoreSelect, CoreSelectCompact, CoreTextArea, CoreTitleInput, CoreTooltip, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, CustomSelectOption, DATE_TIME_MIN_VALUE, LayoutContext, Loading, Login, MarkdownRenderer as MarkdownLatexRender, NotFound, OPENSALT_BASE_URL, ORGANIZATION_TEAM, ORGANIZATION_TENANT, Role, api, apiUpload, firstCheckToken, getAccessToken, getErrorMessage, getImageUrl, historyCore, initSentry, initializeAmplitude, setAddTenant, setAlert, setIsRefetchSidebar, setLoading, setLoadingPage, setMenuCollapse, setTeam, setTenant, setUser, store, useAmplitude, useGoogleSignOut, utcToLocalTime };
3924
4048
  //# sourceMappingURL=index.modern.js.map