acsi-core 0.1.40 → 0.1.42

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.
@@ -1,7 +1,7 @@
1
1
  import { createBrowserHistory } from 'history';
2
2
  import { createAction, createReducer, configureStore } from '@reduxjs/toolkit';
3
3
  import React, { useState, useCallback, useEffect, Fragment, useRef } from 'react';
4
- import { Row, Col, Form, Modal, ModalHeader, ModalBody, ModalFooter, Button, Pagination, PaginationItem, PaginationLink, FormGroup, Input, Label, Tooltip } from 'reactstrap';
4
+ import { Row, Col, Modal, ModalHeader, ModalBody, ModalFooter, Button, Pagination, PaginationItem, PaginationLink, FormGroup, Input, Label, Tooltip } from 'reactstrap';
5
5
  import axios from 'axios';
6
6
  import moment from 'moment';
7
7
  import { Link } from 'react-router-dom';
@@ -83,7 +83,7 @@ var COLORS = {
83
83
  var ORGANIZATION_TENANT = "ORGANIZATION_TENANT";
84
84
  var ORGANIZATION_TEAM = "ORGANIZATION_TEAM";
85
85
 
86
- var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","box-field":"_2e9xO","box-input":"_3zXRp","box-button-email":"_21FPk","box-signin-container":"_1QERu","box-signin-text":"_2-znH","box-signin-logo":"_1aB2m","box-right":"_3qndF","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r"};
86
+ var styleGlobal = {"signup_wrap":"_1KLz9","box-signin":"_2Jo1o","signin_title":"_3egBO","signup_link":"_1DoIT","google_button":"_34hK_","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","box-right-body":"_JzdCr","box-right-footer":"_19aCA","pr-30":"_2HB5r"};
87
87
 
88
88
  var api = axios.create({
89
89
  baseURL: BASE_URL,
@@ -133,12 +133,28 @@ var apiUpload = axios.create({
133
133
  var apiLoginGoogle = function apiLoginGoogle(body) {
134
134
  return api.post(BASE_URL + "/api/Auth/login", body);
135
135
  };
136
+ var apiSendEmailCode = function apiSendEmailCode(body) {
137
+ return api.post(BASE_URL + "/api/Auth/send-code-email", body);
138
+ };
139
+ var apiCheckEmailCode = function apiCheckEmailCode(params) {
140
+ return api.get(BASE_URL + "/api/Auth/check-code-email", {
141
+ params: params
142
+ });
143
+ };
136
144
 
137
145
  var itemLogin = ['Seamless lesson planning', 'Flexibility and customization', 'Data protection and security', 'Standards alignment', 'AI smart assist'];
138
146
 
139
147
  var BlockLogin = function BlockLogin(_ref) {
140
148
  var onNavigate = _ref.onNavigate,
141
- role = _ref.role;
149
+ role = _ref.role,
150
+ email = _ref.email,
151
+ setEmail = _ref.setEmail,
152
+ loginWithEmail = _ref.loginWithEmail,
153
+ code = _ref.code,
154
+ setCode = _ref.setCode,
155
+ isScreenCode = _ref.isScreenCode,
156
+ formatTime = _ref.formatTime,
157
+ loginWithEmailCode = _ref.loginWithEmailCode;
142
158
  var dispatch = useDispatch();
143
159
  var googleLogin = useGoogleLogin({
144
160
  onSuccess: function (tokenResponse) {
@@ -151,7 +167,7 @@ var BlockLogin = function BlockLogin(_ref) {
151
167
  return function () {
152
168
  if (userInfo && userInfo.data) {
153
169
  var _userInfo$data = userInfo.data,
154
- email = _userInfo$data.email,
170
+ _email = _userInfo$data.email,
155
171
  picture = _userInfo$data.picture,
156
172
  family_name = _userInfo$data.family_name,
157
173
  given_name = _userInfo$data.given_name,
@@ -163,7 +179,7 @@ var BlockLogin = function BlockLogin(_ref) {
163
179
  fullName: name,
164
180
  firstName: family_name,
165
181
  lastName: given_name,
166
- email: email,
182
+ email: _email,
167
183
  token: accessToken,
168
184
  googleId: sub,
169
185
  role: role
@@ -237,13 +253,40 @@ var BlockLogin = function BlockLogin(_ref) {
237
253
  src: "/images/icons/Google__G__logo.png"
238
254
  }), "Sign in with Google")), role != "Admin" && React.createElement(React.Fragment, null, React.createElement("span", {
239
255
  className: "" + styleGlobal["box-field"]
240
- }, "OR"), React.createElement(Form, null, React.createElement("div", {
256
+ }, "OR"), isScreenCode ? React.createElement(React.Fragment, null, React.createElement("div", {
257
+ className: "" + styleGlobal["box-input"]
258
+ }, React.createElement("input", {
259
+ type: "text",
260
+ placeholder: "Code OTP",
261
+ value: code,
262
+ onChange: function onChange(event) {
263
+ setCode(event.target.value);
264
+ }
265
+ }), React.createElement("p", {
266
+ className: styleGlobal["box-text"]
267
+ }, "Your code will expire: ", React.createElement("span", null, formatTime()))), React.createElement("button", {
268
+ onClick: function onClick() {
269
+ return loginWithEmailCode();
270
+ },
271
+ className: "" + styleGlobal["box-button-email"]
272
+ }, React.createElement("img", {
273
+ width: 20,
274
+ height: 20,
275
+ alt: "Email sign-in",
276
+ src: "/images/icons/Login_icon.png"
277
+ }), "Login")) : React.createElement(React.Fragment, null, React.createElement("div", {
241
278
  className: "" + styleGlobal["box-input"]
242
279
  }, React.createElement("input", {
243
280
  type: "email",
244
- placeholder: "Email"
281
+ placeholder: "Email",
282
+ value: email,
283
+ onChange: function onChange(event) {
284
+ setEmail(event.target.value.trim());
285
+ }
245
286
  })), React.createElement("button", {
246
- type: "submit",
287
+ onClick: function onClick() {
288
+ !!email && loginWithEmail();
289
+ },
247
290
  className: "" + styleGlobal["box-button-email"]
248
291
  }, React.createElement("img", {
249
292
  width: 20,
@@ -308,46 +351,179 @@ var BlockLogin = function BlockLogin(_ref) {
308
351
  }))))))));
309
352
  };
310
353
 
354
+ // A type of promise-like that resolves synchronously and supports only one observer
355
+
356
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
357
+
358
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
359
+
360
+ // Asynchronously call a function and send errors to recovery continuation
361
+ function _catch(body, recover) {
362
+ try {
363
+ var result = body();
364
+ } catch(e) {
365
+ return recover(e);
366
+ }
367
+ if (result && result.then) {
368
+ return result.then(void 0, recover);
369
+ }
370
+ return result;
371
+ }
372
+
311
373
  var defaultInfo = {
312
374
  email: "",
313
375
  password: "",
314
376
  captcha: "",
315
377
  rememberMe: false
316
378
  };
317
- var useLogin = function useLogin() {
379
+ var minutes = 15;
380
+ var useLogin = function useLogin(onNavigate) {
318
381
  var _useState = useState(false),
319
382
  openLogin = _useState[0],
320
383
  setOpenLogin = _useState[1];
321
384
  var _useState2 = useState(),
322
385
  infoUser = _useState2[0],
323
386
  setInfoUser = _useState2[1];
387
+ var dispatch = useDispatch();
324
388
  var toggle = useCallback(function () {
325
389
  setOpenLogin(!openLogin);
326
390
  }, [openLogin]);
327
- var _useState3 = useState(false),
328
- isShowPassword = _useState3[0],
329
- setIsShowPassword = _useState3[1];
391
+ var _useState3 = useState(""),
392
+ email = _useState3[0],
393
+ setEmail = _useState3[1];
394
+ var _useState4 = useState(""),
395
+ code = _useState4[0],
396
+ setCode = _useState4[1];
397
+ var _useState5 = useState(false),
398
+ isScreenCode = _useState5[0],
399
+ setIsScreenCode = _useState5[1];
400
+ var _useState6 = useState(minutes * 60),
401
+ timeLeft = _useState6[0],
402
+ setTimeLeft = _useState6[1];
403
+ var loginWithEmail = function loginWithEmail() {
404
+ try {
405
+ var _temp2 = function _temp2() {
406
+ dispatch(setLoading(false));
407
+ };
408
+ dispatch(setLoading(true));
409
+ var _temp = _catch(function () {
410
+ return Promise.resolve(apiSendEmailCode(email)).then(function (res) {
411
+ var data = res.data;
412
+ if (data.status == 1) {
413
+ if (data.data.token != null) {
414
+ var tokenJWT = data.data.token;
415
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
416
+ onNavigate("/dashboard");
417
+ } else {
418
+ setIsScreenCode(true);
419
+ }
420
+ } else {
421
+ dispatch(setLoading(false));
422
+ alert("Please contact admin.");
423
+ }
424
+ });
425
+ }, function (e) {
426
+ console.log(e);
427
+ });
428
+ return Promise.resolve(_temp && _temp.then ? _temp.then(_temp2) : _temp2(_temp));
429
+ } catch (e) {
430
+ return Promise.reject(e);
431
+ }
432
+ };
433
+ var loginWithEmailCode = function loginWithEmailCode() {
434
+ try {
435
+ var _temp4 = function _temp4() {
436
+ dispatch(setLoading(false));
437
+ };
438
+ dispatch(setLoading(true));
439
+ var _temp3 = _catch(function () {
440
+ return Promise.resolve(apiCheckEmailCode({
441
+ email: email,
442
+ code: code
443
+ })).then(function (res) {
444
+ var data = res.data;
445
+ if (data.status == 1) {
446
+ var tokenJWT = data.data.token;
447
+ localStorage.setItem(ACCESS_TOKEN, tokenJWT);
448
+ onNavigate("/dashboard");
449
+ } else {
450
+ dispatch(setLoading(false));
451
+ alert("The code is not accurate. Please check again.");
452
+ }
453
+ });
454
+ }, function (e) {
455
+ console.log(e);
456
+ });
457
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(_temp4) : _temp4(_temp3));
458
+ } catch (e) {
459
+ return Promise.reject(e);
460
+ }
461
+ };
462
+ var formatTime = function formatTime() {
463
+ var m = Math.floor(timeLeft / 60);
464
+ var s = timeLeft % 60;
465
+ return m.toString().padStart(2, '0') + ":" + s.toString().padStart(2, '0');
466
+ };
467
+ useEffect(function () {
468
+ if (isScreenCode) {
469
+ var timer = setInterval(function () {
470
+ setTimeLeft(function (prev) {
471
+ if (prev <= 1) {
472
+ clearInterval(timer);
473
+ return 0;
474
+ }
475
+ return prev - 1;
476
+ });
477
+ }, 1000);
478
+ return function () {
479
+ return clearInterval(timer);
480
+ };
481
+ }
482
+ return;
483
+ }, [isScreenCode]);
330
484
  return {
331
485
  defaultInfo: defaultInfo,
332
486
  openLogin: openLogin,
333
487
  toggle: toggle,
334
- isShowPassword: isShowPassword,
335
- setIsShowPassword: setIsShowPassword,
488
+ email: email,
489
+ setEmail: setEmail,
490
+ loginWithEmail: loginWithEmail,
336
491
  infoUser: infoUser,
337
- setInfoUser: setInfoUser
492
+ setInfoUser: setInfoUser,
493
+ code: code,
494
+ setCode: setCode,
495
+ isScreenCode: isScreenCode,
496
+ formatTime: formatTime,
497
+ loginWithEmailCode: loginWithEmailCode
338
498
  };
339
499
  };
340
500
 
341
501
  var Login = function Login(props) {
342
502
  var onNavigate = props.onNavigate,
343
503
  role = props.role;
344
- var _useLogin = useLogin(),
345
- defaultInfo = _useLogin.defaultInfo;
504
+ var _useLogin = useLogin(onNavigate),
505
+ defaultInfo = _useLogin.defaultInfo,
506
+ email = _useLogin.email,
507
+ setEmail = _useLogin.setEmail,
508
+ loginWithEmail = _useLogin.loginWithEmail,
509
+ code = _useLogin.code,
510
+ setCode = _useLogin.setCode,
511
+ isScreenCode = _useLogin.isScreenCode,
512
+ formatTime = _useLogin.formatTime,
513
+ loginWithEmailCode = _useLogin.loginWithEmailCode;
346
514
  return React.createElement("div", {
347
515
  className: styleGlobal["signup_wrap"] + " container-fluid font-family-lato"
348
516
  }, React.createElement(BlockLogin, {
349
517
  defaultInfo: defaultInfo,
518
+ email: email,
519
+ setEmail: setEmail,
520
+ loginWithEmail: loginWithEmail,
521
+ code: code,
522
+ setCode: setCode,
523
+ formatTime: formatTime,
524
+ isScreenCode: isScreenCode,
350
525
  onNavigate: onNavigate,
526
+ loginWithEmailCode: loginWithEmailCode,
351
527
  role: role
352
528
  }));
353
529
  };
@@ -591,25 +767,6 @@ var getAccessToken$1 = (function () {
591
767
  }
592
768
  });
593
769
 
594
- // A type of promise-like that resolves synchronously and supports only one observer
595
-
596
- const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
597
-
598
- const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
599
-
600
- // Asynchronously call a function and send errors to recovery continuation
601
- function _catch(body, recover) {
602
- try {
603
- var result = body();
604
- } catch(e) {
605
- return recover(e);
606
- }
607
- if (result && result.then) {
608
- return result.then(void 0, recover);
609
- }
610
- return result;
611
- }
612
-
613
770
  var encodeParams$1 = (function (params) {
614
771
  return Object.keys(params).filter(function (key) {
615
772
  return params[key] || params[key] === 0 || params[key] === false;
@@ -1409,7 +1566,7 @@ var Close = function Close(props) {
1409
1566
  fill: "none",
1410
1567
  xmlns: "http://www.w3.org/2000/svg"
1411
1568
  }, React.createElement("g", {
1412
- "clip-path": "url(#clip0_1060_48455)"
1569
+ clipPath: "url(#clip0_1060_48455)"
1413
1570
  }, React.createElement("rect", {
1414
1571
  x: "2.48438",
1415
1572
  y: "3.61597",