acsi-core 0.1.95 → 0.1.96

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/dist/index.js CHANGED
@@ -13,10 +13,10 @@ var ReactSelect = require('react-select');
13
13
  var ReactSelect__default = _interopDefault(ReactSelect);
14
14
  var Cookies = _interopDefault(require('js-cookie'));
15
15
  var moment = _interopDefault(require('moment'));
16
+ var msalBrowser = require('@azure/msal-browser');
16
17
  var reactToastify = require('react-toastify');
17
18
  var reactGoogleLogin = require('@leecheuk/react-google-login');
18
19
  var material = require('@mui/material');
19
- require('@azure/msal-browser');
20
20
  var amplitude = require('@amplitude/analytics-browser');
21
21
  var Sentry = require('@sentry/react');
22
22
  var fa = require('react-icons/fa');
@@ -80,25 +80,6 @@ var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
80
80
 
81
81
  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"};
82
82
 
83
- // A type of promise-like that resolves synchronously and supports only one observer
84
-
85
- const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
86
-
87
- const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
88
-
89
- // Asynchronously call a function and send errors to recovery continuation
90
- function _catch(body, recover) {
91
- try {
92
- var result = body();
93
- } catch(e) {
94
- return recover(e);
95
- }
96
- if (result && result.then) {
97
- return result.then(void 0, recover);
98
- }
99
- return result;
100
- }
101
-
102
83
  function _extends() {
103
84
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
104
85
  for (var e = 1; e < arguments.length; e++) {
@@ -118,6 +99,25 @@ function _objectWithoutPropertiesLoose(r, e) {
118
99
  return t;
119
100
  }
120
101
 
102
+ // A type of promise-like that resolves synchronously and supports only one observer
103
+
104
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
105
+
106
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
107
+
108
+ // Asynchronously call a function and send errors to recovery continuation
109
+ function _catch(body, recover) {
110
+ try {
111
+ var result = body();
112
+ } catch(e) {
113
+ return recover(e);
114
+ }
115
+ if (result && result.then) {
116
+ return result.then(void 0, recover);
117
+ }
118
+ return result;
119
+ }
120
+
121
121
  var styles = {"core-button":"_xvNBN","primary":"_U9Qyp","secondary":"_1VzMy","text":"_pZNuj","danger":"_2uYm1","light":"_wxH5S"};
122
122
 
123
123
  var _excluded = ["type", "children", "onClick", "icon", "disabled", "htmlType"];
@@ -1223,6 +1223,55 @@ var TypeLogin;
1223
1223
  TypeLogin[TypeLogin["Microsoft"] = 3] = "Microsoft";
1224
1224
  })(TypeLogin || (TypeLogin = {}));
1225
1225
 
1226
+ var AuthenticationMessage;
1227
+ (function (AuthenticationMessage) {
1228
+ AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
1229
+ AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
1230
+ })(AuthenticationMessage || (AuthenticationMessage = {}));
1231
+ (function (Role) {
1232
+ Role["Student"] = "Student";
1233
+ Role["Teacher"] = "Teacher";
1234
+ Role["Admin"] = "Admin";
1235
+ })(exports.Role || (exports.Role = {}));
1236
+ var msalConfig = function msalConfig(clientId, redirectUri) {
1237
+ return {
1238
+ auth: {
1239
+ clientId: clientId,
1240
+ authority: "https://login.microsoftonline.com/common",
1241
+ redirectUri: redirectUri
1242
+ },
1243
+ cache: {
1244
+ cacheLocation: "sessionStorage",
1245
+ storeAuthStateInCookie: false
1246
+ },
1247
+ system: {
1248
+ loggerOptions: {
1249
+ loggerCallback: function loggerCallback(level, message, containsPii) {
1250
+ if (containsPii) {
1251
+ return;
1252
+ }
1253
+ switch (level) {
1254
+ case msalBrowser.LogLevel.Error:
1255
+ console.error(message);
1256
+ return;
1257
+ case msalBrowser.LogLevel.Info:
1258
+ console.info(message);
1259
+ return;
1260
+ case msalBrowser.LogLevel.Verbose:
1261
+ console.debug(message);
1262
+ return;
1263
+ case msalBrowser.LogLevel.Warning:
1264
+ console.warn(message);
1265
+ return;
1266
+ default:
1267
+ return;
1268
+ }
1269
+ }
1270
+ }
1271
+ }
1272
+ };
1273
+ };
1274
+
1226
1275
  var BlockLogin = function BlockLogin(_ref) {
1227
1276
  var onNavigate = _ref.onNavigate,
1228
1277
  role = _ref.role,
@@ -1357,6 +1406,91 @@ var BlockLogin = function BlockLogin(_ref) {
1357
1406
  return console.log(errorResponse);
1358
1407
  }
1359
1408
  });
1409
+ var fnLoginMicrosoft = function fnLoginMicrosoft() {
1410
+ try {
1411
+ var msalInstance = new msalBrowser.PublicClientApplication(msalConfig(MICROSOFT_CLIENT_ID, MICROSOFT_URL_DIRECT));
1412
+ if (!msalInstance) {
1413
+ console.error("MSAL instance not initialized");
1414
+ return Promise.resolve();
1415
+ }
1416
+ return Promise.resolve(_catch(function () {
1417
+ return Promise.resolve(msalInstance.initialize()).then(function () {
1418
+ var loginRequest = {
1419
+ scopes: ["openid", "profile", "email"]
1420
+ };
1421
+ var silentRequest = _extends({}, loginRequest, {
1422
+ prompt: "select_account"
1423
+ });
1424
+ return Promise.resolve(msalInstance.loginPopup(silentRequest)).then(function (response) {
1425
+ return function () {
1426
+ if (response && response.account) {
1427
+ var account = response.account;
1428
+ var fullName = (account === null || account === void 0 ? void 0 : account.name) || "";
1429
+ var infoLogin = {
1430
+ firstName: fullName.split(' ').slice(0, -1).join(' '),
1431
+ lastName: fullName.split(' ').slice(-1).join(' '),
1432
+ fullName: fullName,
1433
+ imageUrl: "",
1434
+ email: (account === null || account === void 0 ? void 0 : account.username) || "",
1435
+ token: (response === null || response === void 0 ? void 0 : response.accessToken) || "",
1436
+ googleId: (account === null || account === void 0 ? void 0 : account.homeAccountId) || "",
1437
+ role: role,
1438
+ type: TypeLogin.Microsoft
1439
+ };
1440
+ dispatch(setLoading(true));
1441
+ return Promise.resolve(apiLoginGoogle(infoLogin)).then(function (authResult) {
1442
+ var _authResult$data2;
1443
+ if (((_authResult$data2 = authResult.data) === null || _authResult$data2 === void 0 ? void 0 : _authResult$data2.id) == null) {
1444
+ dispatch(setLoading(false));
1445
+ alert("Please contact admin.");
1446
+ return;
1447
+ }
1448
+ localStorage.clear();
1449
+ var tokenJWT = authResult.data.token;
1450
+ trackEvent === null || trackEvent === void 0 ? void 0 : trackEvent({
1451
+ eventName: exports.AmplitudeEvent.LOGIN,
1452
+ eventProperties: {
1453
+ email: email,
1454
+ login_method: 'google',
1455
+ user_role: authResult.data.role,
1456
+ success: true,
1457
+ timestamp: new Date().toISOString()
1458
+ }
1459
+ });
1460
+ if (role === "LandingPage") {
1461
+ CookieService.setAuthCookie({
1462
+ token: tokenJWT,
1463
+ expiresAt: Date.now() + 24 * 60 * 60 * 1000
1464
+ });
1465
+ var getRedirectUrl = function getRedirectUrl(role) {
1466
+ switch (role) {
1467
+ case "Admin":
1468
+ return ADMIN_ORIGIN;
1469
+ case "Teacher":
1470
+ return TEACHER_ORIGIN;
1471
+ default:
1472
+ return role + "." + REQUEST_ORIGIN;
1473
+ }
1474
+ };
1475
+ var redirectUrl = getRedirectUrl(authResult.data.role);
1476
+ window.location.href = redirectUrl + "/dashboard";
1477
+ dispatch(setLoading(false));
1478
+ }
1479
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
1480
+ onNavigate("/dashboard");
1481
+ dispatch(setLoading(false));
1482
+ });
1483
+ }
1484
+ }();
1485
+ });
1486
+ });
1487
+ }, function (error) {
1488
+ console.error("Microsoft login error:", error);
1489
+ }));
1490
+ } catch (e) {
1491
+ return Promise.reject(e);
1492
+ }
1493
+ };
1360
1494
  React__default.useEffect(function () {
1361
1495
  return function () {
1362
1496
  if (resendTimer) {
@@ -1464,7 +1598,18 @@ var BlockLogin = function BlockLogin(_ref) {
1464
1598
  height: 24,
1465
1599
  alt: "Google sign-in",
1466
1600
  src: "/images/icons/Google__G__logo.png"
1467
- }), "Sign in with Google")), React__default.createElement("span", {
1601
+ }), "Sign in with Google")), React__default.createElement("div", {
1602
+ className: "" + styleGlobal["microsoft_button"]
1603
+ }, React__default.createElement("button", {
1604
+ onClick: function onClick() {
1605
+ return fnLoginMicrosoft();
1606
+ }
1607
+ }, React__default.createElement("img", {
1608
+ width: 24,
1609
+ height: 24,
1610
+ alt: "Google sign-in",
1611
+ src: "/images/Single-Sign-On-logo.png"
1612
+ }), "Sign in with Microsoft")), React__default.createElement("span", {
1468
1613
  className: "" + styleGlobal["box-field"]
1469
1614
  }, "OR"), React__default.createElement("div", {
1470
1615
  className: "" + styleGlobal["box-input"]
@@ -2294,17 +2439,6 @@ var CommonDialog = function CommonDialog(_ref) {
2294
2439
  }, title)), children);
2295
2440
  };
2296
2441
 
2297
- var AuthenticationMessage;
2298
- (function (AuthenticationMessage) {
2299
- AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
2300
- AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
2301
- })(AuthenticationMessage || (AuthenticationMessage = {}));
2302
- (function (Role) {
2303
- Role["Student"] = "Student";
2304
- Role["Teacher"] = "Teacher";
2305
- Role["Admin"] = "Admin";
2306
- })(exports.Role || (exports.Role = {}));
2307
-
2308
2442
  var CustomPagination = function CustomPagination(_ref) {
2309
2443
  var currentPage = _ref.currentPage,
2310
2444
  totalPage = _ref.totalPage,