acsi-core 0.10.0 → 1.1.0

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';
@@ -624,6 +624,7 @@ var setIsRefetchSidebar = createAction("common/setIsRefetchSidebar");
624
624
  var setTenant = createAction("common/setTenant");
625
625
  var setAddTenant = createAction("common/setAddTenant");
626
626
  var setTeam = createAction("common/setTeam");
627
+ var setIsFirstCalendar = createAction("common/setIsFirstCalendar");
627
628
 
628
629
  var REQUEST_ORIGIN = process.env.REACT_APP_REQUEST_ORIGIN || "";
629
630
  var ADMIN_ORIGIN = process.env.REACT_APP_ADMIN_ORIGIN || "";
@@ -640,6 +641,7 @@ var PUSHER_CONFIG = {
640
641
  };
641
642
  var MICROSOFT_CLIENT_ID = process.env.REACT_APP_MICROSOFT_CLIENT_ID || "";
642
643
  var MICROSOFT_URL_DIRECT = process.env.REACT_APP_MICROSOFT_URL_DIRECT || "";
644
+ var MICROSOFT_SSO_ENABLED = process.env.REACT_APP_MICROSOFT_SSO_ENABLED || "false";
643
645
  var OPENSALT_BASE_URL = process.env.REACT_APP_OPENSALT || "";
644
646
  var ACCESS_TOKEN = "ACCESS_TOKEN";
645
647
  var AUTH_COOKIE = "auth";
@@ -671,25 +673,6 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
671
673
 
672
674
  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
675
 
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
676
  function _arrayLikeToArray(r, a) {
694
677
  (null == a || a > r.length) && (a = r.length);
695
678
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
@@ -738,6 +721,25 @@ function _unsupportedIterableToArray(r, a) {
738
721
  }
739
722
  }
740
723
 
724
+ // A type of promise-like that resolves synchronously and supports only one observer
725
+
726
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
727
+
728
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
729
+
730
+ // Asynchronously call a function and send errors to recovery continuation
731
+ function _catch(body, recover) {
732
+ try {
733
+ var result = body();
734
+ } catch(e) {
735
+ return recover(e);
736
+ }
737
+ if (result && result.then) {
738
+ return result.then(void 0, recover);
739
+ }
740
+ return result;
741
+ }
742
+
741
743
  var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
742
744
 
743
745
  var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
@@ -1097,12 +1099,16 @@ var CoreModal = function CoreModal(props) {
1097
1099
  onSubmit = props.onSubmit,
1098
1100
  _props$bodyPadding = props.bodyPadding,
1099
1101
  bodyPadding = _props$bodyPadding === void 0 ? "24px" : _props$bodyPadding,
1100
- className = props.className;
1102
+ className = props.className,
1103
+ _props$disableBackdro = props.disableBackdropClick,
1104
+ disableBackdropClick = _props$disableBackdro === void 0 ? false : _props$disableBackdro;
1101
1105
  return React.createElement(Modal, {
1102
1106
  isOpen: open,
1103
- toggle: onClose,
1107
+ toggle: disableBackdropClick ? undefined : onClose,
1104
1108
  centered: true,
1105
- modalClassName: className
1109
+ modalClassName: className,
1110
+ backdrop: disableBackdropClick ? "static" : true,
1111
+ keyboard: !disableBackdropClick
1106
1112
  }, React.createElement("form", {
1107
1113
  onSubmit: onSubmit ? handleSubmit(onSubmit) : undefined,
1108
1114
  className: "" + styles$6["core-modal-container"]
@@ -1370,7 +1376,7 @@ var CoreSearch = function CoreSearch(props) {
1370
1376
  var styles$a = {"core-select-compact":"_3ql5D","label":"_3fPQC"};
1371
1377
 
1372
1378
  var Option$1 = function Option(props) {
1373
- return React.createElement("div", null, React.createElement(components.Option, Object.assign({}, props), React.createElement(CoreInput$1, {
1379
+ return React.createElement("div", null, React.createElement(components.Option, Object.assign({}, props), props.data.hiddenCheckbox ? React.createElement("span", null, props.label) : React.createElement(CoreInput$1, {
1374
1380
  checked: props.isSelected,
1375
1381
  onChange: function onChange() {
1376
1382
  return null;
@@ -1479,6 +1485,10 @@ var CoreSelectCompact = function CoreSelectCompact(props) {
1479
1485
  backgroundColor: COLORS.lightBlueHover
1480
1486
  }
1481
1487
  });
1488
+ if (state.data.border) {
1489
+ styles.borderTop = "1px solid #E6E6EB";
1490
+ styles.borderRadius = "0px";
1491
+ }
1482
1492
  return styles;
1483
1493
  };
1484
1494
  var multiValueStyles = function multiValueStyles(base) {
@@ -2322,6 +2332,56 @@ var TypeLogin;
2322
2332
  TypeLogin[TypeLogin["Microsoft"] = 3] = "Microsoft";
2323
2333
  })(TypeLogin || (TypeLogin = {}));
2324
2334
 
2335
+ var AuthenticationMessage;
2336
+ (function (AuthenticationMessage) {
2337
+ AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
2338
+ AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
2339
+ })(AuthenticationMessage || (AuthenticationMessage = {}));
2340
+ var Role;
2341
+ (function (Role) {
2342
+ Role["Student"] = "Student";
2343
+ Role["Teacher"] = "Teacher";
2344
+ Role["Admin"] = "Admin";
2345
+ })(Role || (Role = {}));
2346
+ var msalConfig = function msalConfig(clientId, redirectUri) {
2347
+ return {
2348
+ auth: {
2349
+ clientId: clientId,
2350
+ authority: "https://login.microsoftonline.com/common",
2351
+ redirectUri: redirectUri
2352
+ },
2353
+ cache: {
2354
+ cacheLocation: "sessionStorage",
2355
+ storeAuthStateInCookie: false
2356
+ },
2357
+ system: {
2358
+ loggerOptions: {
2359
+ loggerCallback: function loggerCallback(level, message, containsPii) {
2360
+ if (containsPii) {
2361
+ return;
2362
+ }
2363
+ switch (level) {
2364
+ case LogLevel.Error:
2365
+ console.error(message);
2366
+ return;
2367
+ case LogLevel.Info:
2368
+ console.info(message);
2369
+ return;
2370
+ case LogLevel.Verbose:
2371
+ console.debug(message);
2372
+ return;
2373
+ case LogLevel.Warning:
2374
+ console.warn(message);
2375
+ return;
2376
+ default:
2377
+ return;
2378
+ }
2379
+ }
2380
+ }
2381
+ }
2382
+ };
2383
+ };
2384
+
2325
2385
  var BlockLogin = function BlockLogin(_ref) {
2326
2386
  var onNavigate = _ref.onNavigate,
2327
2387
  role = _ref.role,
@@ -2456,6 +2516,91 @@ var BlockLogin = function BlockLogin(_ref) {
2456
2516
  return console.log(errorResponse);
2457
2517
  }
2458
2518
  });
2519
+ var fnLoginMicrosoft = function fnLoginMicrosoft() {
2520
+ try {
2521
+ var msalInstance = new PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
2522
+ if (!msalInstance) {
2523
+ console.error("MSAL instance not initialized");
2524
+ return Promise.resolve();
2525
+ }
2526
+ return Promise.resolve(_catch(function () {
2527
+ return Promise.resolve(msalInstance.initialize()).then(function () {
2528
+ var loginRequest = {
2529
+ scopes: ["openid", "profile", "email"]
2530
+ };
2531
+ var silentRequest = _extends$1({}, loginRequest, {
2532
+ prompt: "select_account"
2533
+ });
2534
+ return Promise.resolve(msalInstance.loginPopup(silentRequest)).then(function (response) {
2535
+ return function () {
2536
+ if (response && response.account) {
2537
+ var account = response.account;
2538
+ var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
2539
+ var infoLogin = {
2540
+ firstName: fullName.split(' ').slice(0, -1).join(' '),
2541
+ lastName: fullName.split(' ').slice(-1).join(' '),
2542
+ fullName: fullName,
2543
+ imageUrl: "",
2544
+ email: (account === null || account === void 0 ? void 0 : account.username) || "",
2545
+ token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
2546
+ googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
2547
+ role: role,
2548
+ type: TypeLogin.Microsoft
2549
+ };
2550
+ dispatch(setLoading(true));
2551
+ return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
2552
+ var _authResult$data2;
2553
+ if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
2554
+ dispatch(setLoading(false));
2555
+ alert("Please contact admin.");
2556
+ return;
2557
+ }
2558
+ localStorage.clear();
2559
+ var tokenJWT = authResult.data.token;
2560
+ trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
2561
+ eventName: AmplitudeEvent.LOGIN,
2562
+ eventProperties: {
2563
+ email: email,
2564
+ login_method: 'microsoft',
2565
+ user_role: authResult.data.role,
2566
+ success: true,
2567
+ timestamp: new Date().toISOString()
2568
+ }
2569
+ });
2570
+ if (role === "LandingPage") {
2571
+ CookieService.setAuthCookie({
2572
+ token: tokenJWT,
2573
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
2574
+ });
2575
+ var getRedirectUrl = function getRedirectUrl(role) {
2576
+ switch (role) {
2577
+ case "Admin":
2578
+ return ADMIN_ORIGIN;
2579
+ case "Teacher":
2580
+ return TEACHER_ORIGIN;
2581
+ default:
2582
+ return role + "." + REQUEST_ORIGIN;
2583
+ }
2584
+ };
2585
+ var redirectUrl = getRedirectUrl(authResult.data.role);
2586
+ window.location.href = redirectUrl + "/dashboard";
2587
+ dispatch(setLoading(false));
2588
+ }
2589
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
2590
+ onNavigate("/dashboard");
2591
+ dispatch(setLoading(false));
2592
+ });
2593
+ }
2594
+ }();
2595
+ });
2596
+ });
2597
+ }, function (error) {
2598
+ console.error("Microsoft login error:", error);
2599
+ }));
2600
+ } catch (e) {
2601
+ return Promise.reject(e);
2602
+ }
2603
+ };
2459
2604
  React.useEffect(function () {
2460
2605
  return function () {
2461
2606
  if (resendTimer) {
@@ -2563,7 +2708,18 @@ var BlockLogin = function BlockLogin(_ref) {
2563
2708
  height: 24,
2564
2709
  alt: "Google sign-in",
2565
2710
  src: "/images/icons/Google__G__logo.png"
2566
- }), "Sign in with Google")), React.createElement("span", {
2711
+ }), "Sign in with Google")), MICROSOFT_SSO_ENABLED === "true" && React.createElement("div", {
2712
+ className: "" + styleGlobal["microsoft_button"]
2713
+ }, React.createElement("button", {
2714
+ onClick: function onClick() {
2715
+ return fnLoginMicrosoft();
2716
+ }
2717
+ }, React.createElement("img", {
2718
+ width: 24,
2719
+ height: 24,
2720
+ alt: "Google sign-in",
2721
+ src: "/images/Single-Sign-On-logo.png"
2722
+ }), "Sign in with Microsoft")), React.createElement("span", {
2567
2723
  className: "" + styleGlobal["box-field"]
2568
2724
  }, "OR"), React.createElement("div", {
2569
2725
  className: "" + styleGlobal["box-input"]
@@ -3164,7 +3320,8 @@ var initialState = {
3164
3320
  user: null,
3165
3321
  academy: null,
3166
3322
  menuCollapse: false,
3167
- isRefetchSidebar: false
3323
+ isRefetchSidebar: false,
3324
+ isFirstCalendar: false
3168
3325
  };
3169
3326
  var commonReducer = createReducer(initialState, function (builder) {
3170
3327
  builder.addCase(setLoading, function (state, action) {
@@ -3189,6 +3346,8 @@ var commonReducer = createReducer(initialState, function (builder) {
3189
3346
  state.user.tenantInfo = action.payload;
3190
3347
  }).addCase(setTeam, function (state, action) {
3191
3348
  state.user.currentTeamId = action.payload;
3349
+ }).addCase(setIsFirstCalendar, function (state) {
3350
+ state.isFirstCalendar = !state.isFirstCalendar;
3192
3351
  });
3193
3352
  });
3194
3353
 
@@ -3394,18 +3553,6 @@ var CommonDialog = function CommonDialog(_ref) {
3394
3553
  }, title)), children);
3395
3554
  };
3396
3555
 
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
3556
  var CustomPagination = function CustomPagination(_ref) {
3410
3557
  var currentPage = _ref.currentPage,
3411
3558
  totalPage = _ref.totalPage,
@@ -3677,15 +3824,13 @@ var useAmplitude = function useAmplitude() {
3677
3824
  };
3678
3825
 
3679
3826
  var initializeAmplitude = function initializeAmplitude(apiKey) {
3680
- if (process.env.NODE_ENV === 'production' || process.env.REACT_APP_ENABLE_AMPLITUDE === 'true') {
3681
- init(apiKey, {
3682
- defaultTracking: {
3683
- pageViews: true,
3684
- sessions: true,
3685
- formInteractions: true
3686
- }
3687
- });
3688
- }
3827
+ init(apiKey, {
3828
+ defaultTracking: {
3829
+ pageViews: true,
3830
+ sessions: true,
3831
+ formInteractions: true
3832
+ }
3833
+ });
3689
3834
  };
3690
3835
 
3691
3836
  function initSentry(dsn, release) {
@@ -3910,7 +4055,17 @@ var utcToLocalTime = (function (time, FORMAT) {
3910
4055
  }
3911
4056
  });
3912
4057
 
4058
+ var timeSpanToLocalMoment = (function (time) {
4059
+ if (!time) return null;
4060
+ var times = time.split(":");
4061
+ if (times.length !== 3) return null;
4062
+ var totalSeconds = +times[0] * 60 * 60 + +times[1] * 60 + +times[2];
4063
+ var startOfDay = moment.utc().startOf("day");
4064
+ var dateTime = startOfDay.add(totalSeconds, "seconds");
4065
+ return dateTime.local();
4066
+ });
4067
+
3913
4068
  var historyCore = createBrowserHistory();
3914
4069
 
3915
- 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 };
4070
+ 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, setIsFirstCalendar, setIsRefetchSidebar, setLoading, setLoadingPage, setMenuCollapse, setTeam, setTenant, setUser, store, timeSpanToLocalMoment, useAmplitude, useGoogleSignOut, utcToLocalTime };
3916
4071
  //# sourceMappingURL=index.modern.js.map