touchstudy-core 0.1.10 → 0.1.12

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,8 +1,9 @@
1
1
  import { createBrowserHistory } from 'history';
2
2
  import { createAction, createReducer, configureStore } from '@reduxjs/toolkit';
3
3
  import moment from 'moment';
4
+ export { default as moment } from 'moment';
4
5
  import React, { useState, useCallback, useEffect, Fragment, useRef, useMemo } from 'react';
5
- import { Row, Col, Form, Modal, ModalHeader, ModalBody, ModalFooter, Button, Alert, Pagination, PaginationItem, PaginationLink, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, Collapse, InputGroup, Input, Spinner } from 'reactstrap';
6
+ import { Row, Col, Form, Modal, ModalHeader, ModalBody, Input, ModalFooter, Button, Alert, Pagination, PaginationItem, PaginationLink, Dropdown, DropdownToggle, DropdownMenu, DropdownItem, Collapse, InputGroup, Spinner, FormGroup, Label } from 'reactstrap';
6
7
  import { Formik } from 'formik';
7
8
  import { object, string, boolean } from 'yup';
8
9
  import GoogleLogin, { useGoogleLogout } from '@leecheuk/react-google-login';
@@ -13,11 +14,18 @@ import i18n from 'i18next';
13
14
  import { initReactI18next, useTranslation } from 'react-i18next';
14
15
  export { I18nextProvider, useTranslation } from 'react-i18next';
15
16
  import { IoChevronDown } from 'react-icons/io5';
16
- import Select from 'react-select';
17
+ import 'moment/locale/ko.js';
18
+ import 'moment/locale/en-au.js';
19
+ import Select, { components } from 'react-select';
20
+ import { FaCaretDown, FaPlusCircle } from 'react-icons/fa';
17
21
  import { Link } from 'react-router-dom';
18
22
  import { IoIosCloseCircle, IoMdSend } from 'react-icons/io';
19
- import { ToastContainer, toast } from 'react-toastify';
20
23
  import Pusher from 'pusher-js';
24
+ import { toast } from 'react-toastify';
25
+ export { ToastContainer, toast } from 'react-toastify';
26
+ import CreatableSelect from 'react-select/creatable';
27
+ import { PiDotsNineLight } from 'react-icons/pi';
28
+ import _ from 'lodash';
21
29
 
22
30
  var setLoading = createAction("common/setLoading");
23
31
  var setAlert = createAction("common/setAlert");
@@ -30,6 +38,7 @@ var isLocalHost = Boolean(window.location.hostname === "localhost" || window.loc
30
38
  var GOOGLE_CLIENT_ID = "64118819726-0qlur4qjrs9jbuu6rnoa0u91g680lmpg.apps.googleusercontent.com";
31
39
  var ACCESS_TOKEN = "ACCESS_TOKEN";
32
40
  var DATE_MIN_VALUE = "0001-01-01T00:00:00+00:00";
41
+ var DATE_TIME_MIN_VALUE = "0001-01-01T00:00:00";
33
42
  var BASE_URL = function () {
34
43
  return isLocalHost ? "https://localhost:7045" : "https://api.studypeak.io";
35
44
  }();
@@ -60,7 +69,7 @@ var encodeParams = function encodeParams(params) {
60
69
  };
61
70
 
62
71
  var utcToLocalTime = (function (time, FORMAT) {
63
- if (time === DATE_MIN_VALUE) return "";
72
+ if (time === DATE_MIN_VALUE || time === DATE_TIME_MIN_VALUE) return "";
64
73
  try {
65
74
  return moment.utc(time).local().format(FORMAT || "yyyy-MM-DD");
66
75
  } catch (_unused) {
@@ -147,6 +156,12 @@ var AuthenticationMessage;
147
156
  AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
148
157
  AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
149
158
  })(AuthenticationMessage || (AuthenticationMessage = {}));
159
+ var Role;
160
+ (function (Role) {
161
+ Role["Student"] = "Student";
162
+ Role["Teacher"] = "Teacher";
163
+ Role["Admin"] = "Admin";
164
+ })(Role || (Role = {}));
150
165
 
151
166
  var useGoogleSignOut = function useGoogleSignOut(props) {
152
167
  var dispatch = useDispatch();
@@ -193,7 +208,8 @@ var schema = object({
193
208
  var BlockLogin = function BlockLogin(_ref) {
194
209
  var defaultInfo = _ref.defaultInfo,
195
210
  onNavigate = _ref.onNavigate,
196
- isTeacher = _ref.isTeacher;
211
+ _ref$role = _ref.role,
212
+ role = _ref$role === void 0 ? Role.Student : _ref$role;
197
213
  var dispatch = useDispatch();
198
214
  var _useGoogleSignOut = useGoogleSignOut({
199
215
  onNavigate: onNavigate
@@ -219,7 +235,6 @@ var BlockLogin = function BlockLogin(_ref) {
219
235
  token: accessToken,
220
236
  googleId: googleId
221
237
  };
222
- var role = isTeacher ? "Teacher" : "Student";
223
238
  dispatch(setLoading(true));
224
239
  var _temp = _catch(function () {
225
240
  return Promise.resolve(apiLoginGoogle(infoLogin, role)).then(function (res1) {
@@ -227,7 +242,7 @@ var BlockLogin = function BlockLogin(_ref) {
227
242
  var tokenJWT = res1.data.token;
228
243
  localStorage.setItem("USER_INFORMATION", JSON.stringify(infoLogin));
229
244
  localStorage.setItem(ACCESS_TOKEN, tokenJWT);
230
- if (!isTeacher && isFirstLogin) {
245
+ if (role === Role.Student && isFirstLogin) {
231
246
  onNavigate("/register/info");
232
247
  } else {
233
248
  onNavigate("/");
@@ -346,7 +361,7 @@ var useLogin = function useLogin(onNavigate) {
346
361
 
347
362
  var Login = function Login(_ref) {
348
363
  var onNavigate = _ref.onNavigate,
349
- isTeacher = _ref.isTeacher;
364
+ role = _ref.role;
350
365
  var _useLogin = useLogin(onNavigate),
351
366
  defaultInfo = _useLogin.defaultInfo;
352
367
  return React.createElement("div", {
@@ -361,7 +376,7 @@ var Login = function Login(_ref) {
361
376
  }, React.createElement(BlockLogin, {
362
377
  defaultInfo: defaultInfo,
363
378
  onNavigate: onNavigate,
364
- isTeacher: isTeacher
379
+ role: role
365
380
  }))));
366
381
  };
367
382
 
@@ -602,11 +617,11 @@ var NotFound = function NotFound() {
602
617
  document.title = TITLE;
603
618
  });
604
619
  return React.createElement("div", {
605
- className: "not-found"
620
+ className: "not-found d-flex justify-content-center"
606
621
  }, React.createElement("div", {
607
- className: "clearfix"
622
+ className: "clearfix pt-5"
608
623
  }, React.createElement("h1", {
609
- className: "float-left display-3 mr-4"
624
+ className: "float-left display-3 fw-bold mr-4 text-center"
610
625
  }, "404"), React.createElement("div", {
611
626
  className: "float-left"
612
627
  }, React.createElement("h4", {
@@ -661,16 +676,13 @@ var LayoutContext = function LayoutContext(_ref) {
661
676
  var _state$common;
662
677
  return state === null || state === void 0 ? void 0 : (_state$common = state.common) === null || _state$common === void 0 ? void 0 : _state$common.user;
663
678
  });
679
+ var roles = (user === null || user === void 0 ? void 0 : user.roles) || [];
664
680
  var resetAuth = function resetAuth() {
665
681
  handleSignOut();
666
682
  };
667
683
  var checkRoleUser = useCallback(function () {
668
- var _user$roles, _user$roles2;
669
684
  if (!user) return;
670
- var isAdmin = (_user$roles = user.roles) === null || _user$roles === void 0 ? void 0 : _user$roles.includes("Admin");
671
- if (isAdmin && role !== "Teacher") alert(user.email + " not allow to register " + role);
672
- if (isAdmin) return;
673
- if (!((_user$roles2 = user.roles) !== null && _user$roles2 !== void 0 && _user$roles2.includes(role))) {
685
+ if (!roles.includes(role)) {
674
686
  alert(user.email + " not allow to register " + role);
675
687
  resetAuth();
676
688
  }
@@ -723,19 +735,47 @@ var ConfirmDialog = function ConfirmDialog(_ref) {
723
735
  _ref$title = _ref.title,
724
736
  title = _ref$title === void 0 ? "Confirmation" : _ref$title,
725
737
  toggle = _ref.toggle,
726
- onConfirm = _ref.onConfirm;
738
+ onConfirm = _ref.onConfirm,
739
+ confirmText = _ref.confirmText;
740
+ var _useState = useState(),
741
+ confirmTextValue = _useState[0],
742
+ setConfirmTextValue = _useState[1];
743
+ var handleConfirm = function handleConfirm() {
744
+ onConfirm();
745
+ };
746
+ var handleChangeConfirmText = function handleChangeConfirmText(e) {
747
+ setConfirmTextValue(e.target.value);
748
+ };
749
+ var handlePaste = function handlePaste(e) {
750
+ e.preventDefault();
751
+ };
752
+ useEffect(function () {
753
+ !open && setConfirmTextValue(undefined);
754
+ }, [open]);
755
+ var isValid = !!confirmText && !!confirmTextValue && confirmTextValue.trim() === confirmText.trim();
727
756
  return React.createElement(Modal, {
728
757
  isOpen: open,
729
758
  toggle: toggle,
730
- centered: true
759
+ centered: true,
760
+ zIndex: 1102
731
761
  }, React.createElement(ModalHeader, {
732
762
  toggle: toggle
733
- }, title), React.createElement(ModalBody, null, text), React.createElement(ModalFooter, null, React.createElement(Button, {
763
+ }, title), React.createElement(ModalBody, null, React.createElement("p", null, React.createElement("strong", null, text)), !!confirmText && React.createElement("div", null, React.createElement("p", null, "Enter \"", React.createElement("strong", null, confirmText), "\" to confirm delete"), React.createElement(Input, {
764
+ value: confirmTextValue,
765
+ onChange: handleChangeConfirmText,
766
+ placeholder: "Please enter...",
767
+ onPaste: handlePaste,
768
+ invalid: !isValid && confirmTextValue !== undefined,
769
+ valid: isValid
770
+ }))), React.createElement(ModalFooter, null, React.createElement(Button, {
734
771
  color: "secondary",
772
+ className: "px-3",
735
773
  onClick: toggle
736
774
  }, cancelText), React.createElement(Button, {
737
775
  color: isDelete ? "danger" : "primary",
738
- onClick: onConfirm
776
+ className: "px-3",
777
+ disabled: !!confirmText && (confirmTextValue === null || confirmTextValue === void 0 ? void 0 : confirmTextValue.trim()) !== confirmText.trim(),
778
+ onClick: handleConfirm
739
779
  }, okText)));
740
780
  };
741
781
 
@@ -753,7 +793,8 @@ var CommonDialog = function CommonDialog(_ref) {
753
793
  isOpen: open,
754
794
  toggle: onClose,
755
795
  centered: centered,
756
- size: size
796
+ size: size,
797
+ zIndex: 1102
757
798
  }, React.createElement(ModalHeader, {
758
799
  toggle: onClose
759
800
  }, title), children);
@@ -970,6 +1011,50 @@ var problem = "문제";
970
1011
  var problem_solving_time = "문제풀이 시간";
971
1012
  var minutes = "분";
972
1013
  var correct_rate = "정확한 비율";
1014
+ var title = "시험명";
1015
+ var duration = "시험 시간";
1016
+ var answer_count = "답변 수";
1017
+ var question_count = "문제 갯수";
1018
+ var category = "문항 카테고리";
1019
+ var save_and_exit = "저장 및 종료";
1020
+ var update_exam = "시험 업데이트";
1021
+ var create_exam = "새 시험 만들기";
1022
+ var enter_title = "시험 제목을 입력하세요";
1023
+ var select_placeholder = "선택하다...";
1024
+ var view_exam = "시험 보기";
1025
+ var back = "뒤쪽에";
1026
+ var date_format = "YYYY년 MM월 DD일";
1027
+ var date_time_format = "YYYY-MM-DD HH:mm";
1028
+ var date_time_format_12h = "YYYY-MM-DD HH:mm A";
1029
+ var full_date_time_format = "YYYY년 MMMM Do HH:mm:ss";
1030
+ var total_questions = "총 질문수";
1031
+ var code = "암호";
1032
+ var type = "유형";
1033
+ var description = "설명";
1034
+ var actions = "행위";
1035
+ var start_time = "시작 시간";
1036
+ var end_time = "종료 시간";
1037
+ var start_date = "시작일";
1038
+ var end_date = "종료일";
1039
+ var weekly_day = "주간";
1040
+ var weekly_days = "주간";
1041
+ var enter_class_name = "수업 이름을 입력하세요";
1042
+ var name = "이름";
1043
+ var total_teachers = "총 교사 수";
1044
+ var full_name = "이름";
1045
+ var email = "이메일";
1046
+ var payments = "지불";
1047
+ var view_payments = "결제 보기";
1048
+ var sunday = "일요일";
1049
+ var monday = "월요일";
1050
+ var tuesday = "화요일";
1051
+ var wednesday = "수요일";
1052
+ var thursday = "목요일";
1053
+ var friday = "금요일";
1054
+ var saturday = "토요일";
1055
+ var total_lessons = "총 수업";
1056
+ var weekly_days_required = "평일 필수";
1057
+ var main_teacher = "주 교사";
973
1058
  var lang_ko = {
974
1059
  problem_solving: problem_solving,
975
1060
  my_story: my_story,
@@ -1027,7 +1112,51 @@ var lang_ko = {
1027
1112
  problem: problem,
1028
1113
  problem_solving_time: problem_solving_time,
1029
1114
  minutes: minutes,
1030
- correct_rate: correct_rate
1115
+ correct_rate: correct_rate,
1116
+ title: title,
1117
+ duration: duration,
1118
+ answer_count: answer_count,
1119
+ question_count: question_count,
1120
+ category: category,
1121
+ save_and_exit: save_and_exit,
1122
+ update_exam: update_exam,
1123
+ create_exam: create_exam,
1124
+ enter_title: enter_title,
1125
+ select_placeholder: select_placeholder,
1126
+ view_exam: view_exam,
1127
+ back: back,
1128
+ date_format: date_format,
1129
+ date_time_format: date_time_format,
1130
+ date_time_format_12h: date_time_format_12h,
1131
+ full_date_time_format: full_date_time_format,
1132
+ total_questions: total_questions,
1133
+ code: code,
1134
+ type: type,
1135
+ description: description,
1136
+ actions: actions,
1137
+ start_time: start_time,
1138
+ end_time: end_time,
1139
+ start_date: start_date,
1140
+ end_date: end_date,
1141
+ weekly_day: weekly_day,
1142
+ weekly_days: weekly_days,
1143
+ enter_class_name: enter_class_name,
1144
+ name: name,
1145
+ total_teachers: total_teachers,
1146
+ full_name: full_name,
1147
+ email: email,
1148
+ payments: payments,
1149
+ view_payments: view_payments,
1150
+ sunday: sunday,
1151
+ monday: monday,
1152
+ tuesday: tuesday,
1153
+ wednesday: wednesday,
1154
+ thursday: thursday,
1155
+ friday: friday,
1156
+ saturday: saturday,
1157
+ total_lessons: total_lessons,
1158
+ weekly_days_required: weekly_days_required,
1159
+ main_teacher: main_teacher
1031
1160
  };
1032
1161
 
1033
1162
  var problem_solving$1 = "Problem Solving";
@@ -1087,6 +1216,86 @@ var problem$1 = "Problem ";
1087
1216
  var problem_solving_time$1 = "Problem solving time";
1088
1217
  var minutes$1 = "m";
1089
1218
  var correct_rate$1 = "Correct rate";
1219
+ var difficult_level = "Difficult level";
1220
+ var difficulty_explain = "(The Difficulty Level provides an indication of the difficulty level of each test question)";
1221
+ var explain_your_answer = "Explain your answer";
1222
+ var hint = "Hint";
1223
+ var save_and_add_next_question = "Save and add next question";
1224
+ var save_and_exit$1 = "Save and exit";
1225
+ var question_text = "Question text";
1226
+ var title$1 = "Title";
1227
+ var create_question = "Create question";
1228
+ var parent_question = "Parent question";
1229
+ var edit_question = "Edit question";
1230
+ var easy = "Easy";
1231
+ var intermediate = "Intermediate";
1232
+ var difficult = "Difficult";
1233
+ var article = "Article";
1234
+ var correct_answer = "Correct answer";
1235
+ var mark = "Mark";
1236
+ var answer = "Answer";
1237
+ var add_new_row = "Add new row";
1238
+ var question_text_required = "Question text is required";
1239
+ var create_question_success = "Question is created successfully";
1240
+ var update_question_success = "Question is updated successfully";
1241
+ var number_of_answers = "Number of answers";
1242
+ var correct_answers = "Correct answers";
1243
+ var category$1 = "Category";
1244
+ var score = "Score";
1245
+ var enter_title$1 = "Enter title";
1246
+ var enter_score = "Enter score";
1247
+ var exam_title_required = "Exam title is required";
1248
+ var question_category_required = "Question category is required";
1249
+ var start_time$1 = "Start time";
1250
+ var end_time$1 = "End time";
1251
+ var start_date$1 = "Start date";
1252
+ var end_date$1 = "End date";
1253
+ var weekly_day$1 = "Weekly day";
1254
+ var weekly_days$1 = "Weekly days";
1255
+ var enter_class_name$1 = "Enter class name";
1256
+ var class_required = "Class name is required";
1257
+ var total_teachers$1 = "Total teachers";
1258
+ var start_date_required = "Start date is required";
1259
+ var end_date_required = "End date is required";
1260
+ var full_name$1 = "Full name";
1261
+ var email$1 = "Email";
1262
+ var is_paid = "Is paid";
1263
+ var payment_time = "Payment time";
1264
+ var create_and_continue = "Create and continue";
1265
+ var payments$1 = "Payments";
1266
+ var duration$1 = "Duration";
1267
+ var answer_count$1 = "Answer count";
1268
+ var question_count$1 = "Question count";
1269
+ var multi_choice = "Is multiple";
1270
+ var select_placeholder$1 = "Select...";
1271
+ var view_exam$1 = "View exam";
1272
+ var update_exam$1 = "Update exam";
1273
+ var create_exam$1 = "Create exam";
1274
+ var back$1 = "Back";
1275
+ var date_format$1 = "MM-DD-YYYY";
1276
+ var date_time_format$1 = "MM-DD-YYYY HH:mm";
1277
+ var date_time_format_12h$1 = "MM-DD-YYYY HH:mm A";
1278
+ var full_date_time_format$1 = "MMM Do YYYY HH:mm:ss";
1279
+ var total_questions$1 = "Total questions";
1280
+ var code$1 = "Code";
1281
+ var type$1 = "Type";
1282
+ var description$1 = "Description";
1283
+ var actions$1 = "Actions";
1284
+ var name$1 = "Name";
1285
+ var sunday$1 = "Sunday";
1286
+ var monday$1 = "Monday";
1287
+ var tuesday$1 = "Tuesday";
1288
+ var wednesday$1 = "Wednesday";
1289
+ var thursday$1 = "Thursday";
1290
+ var friday$1 = "Friday";
1291
+ var saturday$1 = "Saturday";
1292
+ var total_lessons$1 = "Total lessons";
1293
+ var is_cancelled = "Is cancelled";
1294
+ var date = "Date";
1295
+ var weekly_days_required$1 = "Weekly days are required";
1296
+ var main_teacher$1 = "Main teacher";
1297
+ var main_teacher_required = "Main teacher is required";
1298
+ var teacher = "Teacher";
1090
1299
  var lang_en = {
1091
1300
  problem_solving: problem_solving$1,
1092
1301
  my_story: my_story$1,
@@ -1144,7 +1353,87 @@ var lang_en = {
1144
1353
  problem: problem$1,
1145
1354
  problem_solving_time: problem_solving_time$1,
1146
1355
  minutes: minutes$1,
1147
- correct_rate: correct_rate$1
1356
+ correct_rate: correct_rate$1,
1357
+ difficult_level: difficult_level,
1358
+ difficulty_explain: difficulty_explain,
1359
+ explain_your_answer: explain_your_answer,
1360
+ hint: hint,
1361
+ save_and_add_next_question: save_and_add_next_question,
1362
+ save_and_exit: save_and_exit$1,
1363
+ question_text: question_text,
1364
+ title: title$1,
1365
+ create_question: create_question,
1366
+ parent_question: parent_question,
1367
+ edit_question: edit_question,
1368
+ easy: easy,
1369
+ intermediate: intermediate,
1370
+ difficult: difficult,
1371
+ article: article,
1372
+ correct_answer: correct_answer,
1373
+ mark: mark,
1374
+ answer: answer,
1375
+ add_new_row: add_new_row,
1376
+ question_text_required: question_text_required,
1377
+ create_question_success: create_question_success,
1378
+ update_question_success: update_question_success,
1379
+ number_of_answers: number_of_answers,
1380
+ correct_answers: correct_answers,
1381
+ category: category$1,
1382
+ score: score,
1383
+ enter_title: enter_title$1,
1384
+ enter_score: enter_score,
1385
+ exam_title_required: exam_title_required,
1386
+ question_category_required: question_category_required,
1387
+ start_time: start_time$1,
1388
+ end_time: end_time$1,
1389
+ start_date: start_date$1,
1390
+ end_date: end_date$1,
1391
+ weekly_day: weekly_day$1,
1392
+ weekly_days: weekly_days$1,
1393
+ enter_class_name: enter_class_name$1,
1394
+ class_required: class_required,
1395
+ total_teachers: total_teachers$1,
1396
+ start_date_required: start_date_required,
1397
+ end_date_required: end_date_required,
1398
+ full_name: full_name$1,
1399
+ email: email$1,
1400
+ is_paid: is_paid,
1401
+ payment_time: payment_time,
1402
+ create_and_continue: create_and_continue,
1403
+ payments: payments$1,
1404
+ duration: duration$1,
1405
+ answer_count: answer_count$1,
1406
+ question_count: question_count$1,
1407
+ multi_choice: multi_choice,
1408
+ select_placeholder: select_placeholder$1,
1409
+ view_exam: view_exam$1,
1410
+ update_exam: update_exam$1,
1411
+ create_exam: create_exam$1,
1412
+ back: back$1,
1413
+ date_format: date_format$1,
1414
+ date_time_format: date_time_format$1,
1415
+ date_time_format_12h: date_time_format_12h$1,
1416
+ full_date_time_format: full_date_time_format$1,
1417
+ total_questions: total_questions$1,
1418
+ code: code$1,
1419
+ type: type$1,
1420
+ description: description$1,
1421
+ actions: actions$1,
1422
+ name: name$1,
1423
+ sunday: sunday$1,
1424
+ monday: monday$1,
1425
+ tuesday: tuesday$1,
1426
+ wednesday: wednesday$1,
1427
+ thursday: thursday$1,
1428
+ friday: friday$1,
1429
+ saturday: saturday$1,
1430
+ total_lessons: total_lessons$1,
1431
+ is_cancelled: is_cancelled,
1432
+ date: date,
1433
+ weekly_days_required: weekly_days_required$1,
1434
+ main_teacher: main_teacher$1,
1435
+ main_teacher_required: main_teacher_required,
1436
+ teacher: teacher
1148
1437
  };
1149
1438
 
1150
1439
  i18n.use(initReactI18next).init({
@@ -1163,28 +1452,27 @@ i18n.use(initReactI18next).init({
1163
1452
  }
1164
1453
  });
1165
1454
 
1166
- var DEFAULT_LANGUAGE_CODE = "ko";
1455
+ var DEFAULT_LANGUAGE_INDEX = 0;
1167
1456
  var LANGUAGES = [{
1168
1457
  code: "ko",
1169
1458
  fullName: "Korean",
1170
1459
  shortName: "Korean",
1171
1460
  nativeName: "Korean",
1172
1461
  name: "Korean",
1173
- image: "/images/korea.png"
1462
+ image: "/images/korea.png",
1463
+ momentLangCode: "ko"
1174
1464
  }, {
1175
1465
  code: "en",
1176
1466
  fullName: "English",
1177
1467
  shortName: "English",
1178
1468
  nativeName: "English",
1179
1469
  name: "English",
1180
- image: "/images/usa.png"
1470
+ image: "/images/usa.png",
1471
+ momentLangCode: "en-au"
1181
1472
  }];
1182
- var SUPPORTED_LANGUAGES_CODE = LANGUAGES.map(function (i) {
1183
- return i.code;
1184
- });
1185
1473
 
1186
- var TheLanguageDropdown = function TheLanguageDropdown() {
1187
- var defaultLanguage = !!localStorage.getItem("language") ? localStorage.getItem("language") : navigator.language || DEFAULT_LANGUAGE_CODE;
1474
+ var useLanguage = function useLanguage() {
1475
+ var defaultLanguage = !!localStorage.getItem("language") ? localStorage.getItem("language") : navigator.language || LANGUAGES[DEFAULT_LANGUAGE_INDEX].code;
1188
1476
  var dispatch = useDispatch();
1189
1477
  var _useTranslation = useTranslation(),
1190
1478
  i18n = _useTranslation.i18n;
@@ -1200,25 +1488,42 @@ var TheLanguageDropdown = function TheLanguageDropdown() {
1200
1488
  });
1201
1489
  };
1202
1490
  var changeLanguageApp = function changeLanguageApp(lang) {
1203
- if (!SUPPORTED_LANGUAGES_CODE.includes(lang)) lang = DEFAULT_LANGUAGE_CODE;
1204
- i18n.changeLanguage(lang);
1205
- localStorage.setItem("language", lang);
1206
- setItemLanguage(lang);
1207
- dispatch(setLanguage(lang));
1491
+ var language = LANGUAGES.find(function (i) {
1492
+ return i.code === lang;
1493
+ });
1494
+ if (!language) language = LANGUAGES[DEFAULT_LANGUAGE_INDEX];
1495
+ i18n.changeLanguage(language.code);
1496
+ moment.locale(language.momentLangCode);
1497
+ localStorage.setItem("language", language.code);
1498
+ setItemLanguage(language.code);
1499
+ dispatch(setLanguage(language.code));
1208
1500
  };
1501
+ useEffect(function () {
1502
+ changeLanguageApp(language);
1503
+ }, [language]);
1209
1504
  var currentLanguage = useMemo(function () {
1210
1505
  var currentLang = LANGUAGES.find(function (i) {
1211
1506
  return i.code === language;
1212
1507
  });
1213
1508
  if (!currentLang) return null;
1214
- return React.createElement(React.Fragment, null, React.createElement("img", {
1215
- className: "mr-2 " + styles['dropdown-menu-flag'],
1216
- src: currentLang.image
1217
- }), " ", currentLang.shortName);
1218
- }, [language]);
1219
- useEffect(function () {
1220
- changeLanguageApp(language);
1509
+ return currentLang;
1221
1510
  }, [language]);
1511
+ return {
1512
+ language: language,
1513
+ dropdownOpen: dropdownOpen,
1514
+ currentLanguage: currentLanguage,
1515
+ toggle: toggle,
1516
+ setItemLanguage: setItemLanguage
1517
+ };
1518
+ };
1519
+
1520
+ var TheLanguageDropdown = function TheLanguageDropdown() {
1521
+ var _useLanguage = useLanguage(),
1522
+ currentLanguage = _useLanguage.currentLanguage,
1523
+ language = _useLanguage.language,
1524
+ dropdownOpen = _useLanguage.dropdownOpen,
1525
+ toggle = _useLanguage.toggle,
1526
+ setItemLanguage = _useLanguage.setItemLanguage;
1222
1527
  return React.createElement(Dropdown, {
1223
1528
  isOpen: dropdownOpen,
1224
1529
  toggle: toggle,
@@ -1232,7 +1537,10 @@ var TheLanguageDropdown = function TheLanguageDropdown() {
1232
1537
  display: 'flex',
1233
1538
  alignItems: 'center'
1234
1539
  }
1235
- }, currentLanguage, React.createElement(IoChevronDown, {
1540
+ }, !!currentLanguage && React.createElement("img", {
1541
+ className: "mr-2 " + styles['dropdown-menu-flag'],
1542
+ src: currentLanguage.image
1543
+ }), !!currentLanguage && currentLanguage.shortName, React.createElement(IoChevronDown, {
1236
1544
  className: "ml-2",
1237
1545
  style: {
1238
1546
  fontSize: '15px',
@@ -1316,14 +1624,54 @@ function _objectWithoutPropertiesLoose(source, excluded) {
1316
1624
  return target;
1317
1625
  }
1318
1626
 
1319
- var _excluded = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
1627
+ var _excluded = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
1628
+ var DropdownIndicator = function DropdownIndicator(props) {
1629
+ return React.createElement(components.DropdownIndicator, Object.assign({}, props), React.createElement(FaCaretDown, {
1630
+ color: "#5458D5"
1631
+ }));
1632
+ };
1633
+ var CustomOption = function CustomOption(props) {
1634
+ return React.createElement(components.Option, Object.assign({}, props), React.createElement("div", {
1635
+ style: {
1636
+ fontSize: "14px",
1637
+ fontWeight: 500
1638
+ }
1639
+ }, props.data.label));
1640
+ };
1641
+ var customStyles = {
1642
+ control: function control(baseStyles, state) {
1643
+ return _extends({}, baseStyles, {
1644
+ fontSize: "14px",
1645
+ fontWeight: 700,
1646
+ color: "#5458D5",
1647
+ borderColor: state.isFocused ? '#5458D5' : '#C3C5FE'
1648
+ });
1649
+ },
1650
+ input: function input(baseStyles, _) {
1651
+ return _extends({}, baseStyles, {
1652
+ fontSize: "14px",
1653
+ fontWeight: 700,
1654
+ color: "#5458D5"
1655
+ });
1656
+ },
1657
+ singleValue: function singleValue(baseStyles) {
1658
+ return _extends({}, baseStyles, {
1659
+ fontSize: "14px",
1660
+ fontWeight: 700,
1661
+ color: "#5458D5"
1662
+ });
1663
+ }
1664
+ };
1320
1665
  var CustomSelect = function CustomSelect(_ref) {
1321
- var options = _ref.options,
1666
+ var isDefault = _ref.isDefault,
1667
+ options = _ref.options,
1322
1668
  isDisabled = _ref.isDisabled,
1323
1669
  scrollBottom = _ref.scrollBottom,
1324
1670
  value = _ref.value,
1325
1671
  isMulti = _ref.isMulti,
1326
1672
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
1673
+ var _useTranslation = useTranslation(),
1674
+ t = _useTranslation.t;
1327
1675
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
1328
1676
  return value.includes(i.value);
1329
1677
  }) : isMulti ? options.filter(function (i) {
@@ -1334,9 +1682,19 @@ var CustomSelect = function CustomSelect(_ref) {
1334
1682
  return React.createElement(Select, Object.assign({
1335
1683
  isDisabled: isDisabled,
1336
1684
  options: options,
1337
- value: initialValues,
1685
+ value: !isDefault ? initialValues != null ? initialValues : null : undefined,
1686
+ defaultValue: isDefault ? initialValues : undefined,
1338
1687
  menuPlacement: scrollBottom ? "top" : "auto",
1339
- isMulti: isMulti
1688
+ isMulti: isMulti,
1689
+ components: {
1690
+ IndicatorSeparator: function IndicatorSeparator() {
1691
+ return null;
1692
+ },
1693
+ DropdownIndicator: DropdownIndicator,
1694
+ Option: CustomOption
1695
+ },
1696
+ styles: customStyles,
1697
+ placeholder: t("select_placeholder")
1340
1698
  }, rest));
1341
1699
  };
1342
1700
 
@@ -1408,6 +1766,8 @@ var ChatRightItem = function ChatRightItem(_ref) {
1408
1766
  var _useState2 = useState(false),
1409
1767
  isShowInfo = _useState2[0],
1410
1768
  setShowInfo = _useState2[1];
1769
+ var _useTranslation = useTranslation(),
1770
+ t = _useTranslation.t;
1411
1771
  var handleShowInfo = function handleShowInfo() {
1412
1772
  setShowInfo(!isShowInfo);
1413
1773
  !isFirst && !isSystemLog && setShowTime(!isShowInfo);
@@ -1440,12 +1800,12 @@ var ChatRightItem = function ChatRightItem(_ref) {
1440
1800
  }
1441
1801
  }, "Add message to exam")), isSystemLog || !!isFirst ? React.createElement("p", {
1442
1802
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
1443
- }, utcToLocalTime(createdAt, "HH:mm DD MMM YYYY")) : React.createElement(Collapse, {
1803
+ }, utcToLocalTime(createdAt, t("date_time_format"))) : React.createElement(Collapse, {
1444
1804
  className: "w-100",
1445
1805
  isOpen: isShowTime
1446
1806
  }, React.createElement("p", {
1447
1807
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
1448
- }, utcToLocalTime(createdAt, "HH:mm DD MMM YYYY"))), isSystemLog ? React.createElement("div", {
1808
+ }, utcToLocalTime(createdAt, t("date_time_format")))), isSystemLog ? React.createElement("div", {
1449
1809
  className: "text-center w-100"
1450
1810
  }, React.createElement(Link, {
1451
1811
  to: "" + (actionLink || "/"),
@@ -1502,6 +1862,8 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
1502
1862
  var _useState2 = useState(false),
1503
1863
  isShowInfo = _useState2[0],
1504
1864
  setShowInfo = _useState2[1];
1865
+ var _useTranslation = useTranslation(),
1866
+ t = _useTranslation.t;
1505
1867
  var handleShowInfo = function handleShowInfo() {
1506
1868
  if (!id) return;
1507
1869
  setShowInfo(!isShowInfo);
@@ -1530,12 +1892,12 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
1530
1892
  }
1531
1893
  }, "Add message to exam")), isSystemLog || !!isFirst ? React.createElement("p", {
1532
1894
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
1533
- }, utcToLocalTime(createdAt, "HH:mm DD MMM YYYY")) : React.createElement(Collapse, {
1895
+ }, utcToLocalTime(createdAt, t("date_time_format"))) : React.createElement(Collapse, {
1534
1896
  className: "w-100",
1535
1897
  isOpen: isShowTime
1536
1898
  }, React.createElement("p", {
1537
1899
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
1538
- }, utcToLocalTime(createdAt, "HH:mm DD MMM YYYY"))), isSystemLog ? React.createElement("div", {
1900
+ }, utcToLocalTime(createdAt, t("date_time_format")))), isSystemLog ? React.createElement("div", {
1539
1901
  className: "text-center w-100"
1540
1902
  }, React.createElement(Link, {
1541
1903
  to: "" + (actionLink || "/"),
@@ -1688,9 +2050,16 @@ var ChatHeader = function ChatHeader(_ref) {
1688
2050
  var name = _ref.name,
1689
2051
  avatar = _ref.avatar,
1690
2052
  options = _ref.options,
2053
+ selectedOption = _ref.selectedOption,
1691
2054
  onChangeOption = _ref.onChangeOption;
1692
2055
  var wrapperRef = useRef(null);
1693
2056
  var actionRef = useRef(null);
2057
+ var language = useSelector(function (state) {
2058
+ var _state$common;
2059
+ return state === null || state === void 0 ? void 0 : (_state$common = state.common) === null || _state$common === void 0 ? void 0 : _state$common.language;
2060
+ });
2061
+ var _useTranslation = useTranslation(),
2062
+ t = _useTranslation.t;
1694
2063
  var handleChangeOption = function handleChangeOption(val) {
1695
2064
  onChangeOption === null || onChangeOption === void 0 ? void 0 : onChangeOption(val);
1696
2065
  };
@@ -1707,10 +2076,10 @@ var ChatHeader = function ChatHeader(_ref) {
1707
2076
  return options === null || options === void 0 ? void 0 : options.map(function (i) {
1708
2077
  return {
1709
2078
  value: i.id,
1710
- label: i.title + " (" + utcToLocalTime(i.startTime) + ")"
2079
+ label: i.title + " (" + utcToLocalTime(i.startTime, t("date_time_format")) + ")"
1711
2080
  };
1712
2081
  });
1713
- }, [JSON.stringify(options)]);
2082
+ }, [JSON.stringify(options), language]);
1714
2083
  return React.createElement("div", {
1715
2084
  className: "d-flex bg-light rounded-3 p-3"
1716
2085
  }, React.createElement("div", null, React.createElement("img", {
@@ -1726,6 +2095,7 @@ var ChatHeader = function ChatHeader(_ref) {
1726
2095
  }, selectOptions !== undefined && React.createElement("div", {
1727
2096
  className: styles$1["header__select"] + " mx-3"
1728
2097
  }, React.createElement(CustomSelect, {
2098
+ value: selectedOption,
1729
2099
  options: selectOptions,
1730
2100
  onChange: handleChangeOption,
1731
2101
  isClearable: true
@@ -1843,7 +2213,7 @@ var ChatContainer = function ChatContainer(_ref) {
1843
2213
  onAddExamMessage: handleAddExamMessage
1844
2214
  }))), React.createElement("div", null, React.createElement(InputChat, Object.assign({}, inputProps, {
1845
2215
  inputRef: inputRef
1846
- }))), React.createElement(ToastContainer, null));
2216
+ }))));
1847
2217
  };
1848
2218
 
1849
2219
  var CONVERSATION_URL = BASE_URL + "/api/conversation";
@@ -1960,13 +2330,14 @@ var useMessageList = function useMessageList(userId, getListExamOptions) {
1960
2330
  examId: !examId ? messageFilter.examId : examId
1961
2331
  });
1962
2332
  return Promise.resolve(getMessagesByConversation(conversationId, filter)).then(function (res) {
2333
+ var _res$data$items2;
1963
2334
  function _temp(_getListExamOptions) {
1964
2335
  _getListExamOptions;
1965
2336
  }
1966
- setMessages(function (state) {
2337
+ if (messageFilter.beforeDate) setMessages(function (state) {
1967
2338
  var _res$data$items;
1968
2339
  return [].concat(((_res$data$items = res.data.items) === null || _res$data$items === void 0 ? void 0 : _res$data$items.reverse()) || [], state);
1969
- });
2340
+ });else setMessages((_res$data$items2 = res.data.items) === null || _res$data$items2 === void 0 ? void 0 : _res$data$items2.reverse());
1970
2341
  return getListExamOptions ? Promise.resolve(!!getListExamOptions && getListExamOptions(userId)).then(_temp) : _temp(!!getListExamOptions && getListExamOptions(userId));
1971
2342
  });
1972
2343
  }, function (error) {
@@ -2398,6 +2769,7 @@ var useChatContainer = function useChatContainer(props) {
2398
2769
  name: userName,
2399
2770
  avatar: userAvatar,
2400
2771
  options: exams,
2772
+ selectedOption: messageFilter.examId,
2401
2773
  onChangeOption: handleFilterExam
2402
2774
  },
2403
2775
  chatListProps: {
@@ -2563,9 +2935,12 @@ var useConversationList = function useConversationList() {
2563
2935
  return i.id === lastMessage.conversationId;
2564
2936
  });
2565
2937
  if (updateIndex < 0) return state;
2566
- return [].concat(state.slice(0, updateIndex), [_extends({}, state[updateIndex], {
2938
+ console.log({
2567
2939
  lastMessage: lastMessage
2568
- })], state.slice(updateIndex + 1));
2940
+ });
2941
+ return [_extends({}, state[updateIndex], {
2942
+ lastMessage: lastMessage
2943
+ })].concat(state.slice(0, updateIndex), state.slice(updateIndex + 1));
2569
2944
  });
2570
2945
  };
2571
2946
  var handleCreateConversationSuccess = function handleCreateConversationSuccess(id) {
@@ -2654,7 +3029,536 @@ var usePusherConversation = function usePusherConversation(onNewMessageConversat
2654
3029
  return {};
2655
3030
  };
2656
3031
 
3032
+ var _excluded$1 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3033
+ var CustomCreatable = function CustomCreatable(_ref) {
3034
+ var options = _ref.options,
3035
+ isDisabled = _ref.isDisabled,
3036
+ scrollBottom = _ref.scrollBottom,
3037
+ value = _ref.value,
3038
+ isMulti = _ref.isMulti,
3039
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
3040
+ var initialValues = Array.isArray(value) ? options.filter(function (i) {
3041
+ return value.includes(i.value);
3042
+ }) : isMulti ? options.filter(function (i) {
3043
+ return i.value == value;
3044
+ }) : options.find(function (i) {
3045
+ return i.value == value;
3046
+ });
3047
+ return React.createElement(CreatableSelect, Object.assign({
3048
+ isClearable: true,
3049
+ isDisabled: isDisabled,
3050
+ options: options,
3051
+ value: initialValues,
3052
+ menuPlacement: scrollBottom ? "top" : "auto",
3053
+ isMulti: isMulti
3054
+ }, rest));
3055
+ };
3056
+
3057
+ var _excluded$2 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
3058
+ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
3059
+ var isDefault = _ref.isDefault,
3060
+ options = _ref.options,
3061
+ isDisabled = _ref.isDisabled,
3062
+ scrollBottom = _ref.scrollBottom,
3063
+ value = _ref.value,
3064
+ isMulti = _ref.isMulti,
3065
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3066
+ var initialValues = Array.isArray(value) ? options.filter(function (i) {
3067
+ return value.includes(i.value);
3068
+ }) : isMulti ? options.filter(function (i) {
3069
+ return i.value == value;
3070
+ }) : options.find(function (i) {
3071
+ return i.value == value;
3072
+ });
3073
+ return React.createElement(Select, Object.assign({
3074
+ isDisabled: isDisabled,
3075
+ options: options,
3076
+ value: !isDefault ? initialValues : undefined,
3077
+ defaultValue: isDefault ? initialValues : undefined,
3078
+ menuPlacement: scrollBottom ? "top" : "auto",
3079
+ isMulti: isMulti
3080
+ }, rest));
3081
+ };
3082
+
3083
+ var styles$2 = {"question":"_2uc_W","question-article":"_2p7kY","question-title":"_2tHmc","question--active":"_3IHYm","question-label":"_26ATj","question-input":"_3R8PR","question-btn":"_1VZac"};
3084
+
3085
+ var DURATION_OPTIONS = Array.from({
3086
+ length: 120
3087
+ }, function (_, i) {
3088
+ return i + 1;
3089
+ });
3090
+ var SCORE_OPTIONS = Array.from({
3091
+ length: 10
3092
+ }, function (_, i) {
3093
+ return i + 1;
3094
+ });
3095
+ var QUESTION_OPTIONS = Array.from({
3096
+ length: 40
3097
+ }, function (_, i) {
3098
+ return i + 1;
3099
+ });
3100
+ var ANSWER_OPTIONS = Array.from({
3101
+ length: 9
3102
+ }, function (_, i) {
3103
+ return i + 2;
3104
+ });
3105
+ var DEFAULT_SCORE = 2;
3106
+ var DEFAULT_ANSWER_COUNT = 5;
3107
+
3108
+ var QuestionView = function QuestionView(_ref) {
3109
+ var index = _ref.index,
3110
+ question = _ref.question,
3111
+ answerCount = _ref.answerCount,
3112
+ isDisabled = _ref.isDisabled,
3113
+ onChangeCorrectAnswers = _ref.onChangeCorrectAnswers,
3114
+ onChangeScoreAnswer = _ref.onChangeScoreAnswer;
3115
+ var scoreOptions = SCORE_OPTIONS.map(function (i) {
3116
+ return {
3117
+ label: DEFAULT_SCORE === i ? i + "\uC810 (\uAE30\uBCF8\uAC12)" : i + "\uC810",
3118
+ value: i
3119
+ };
3120
+ });
3121
+ return React.createElement("div", {
3122
+ className: "d-flex justify-content-between"
3123
+ }, React.createElement("div", {
3124
+ className: "d-flex flex-grow-1"
3125
+ }, React.createElement("div", {
3126
+ className: styles$2["question-title"] + " me-2"
3127
+ }, "\uBB38\uC81C ", question.questionOrder + 1, "\uBC88"), React.createElement("div", {
3128
+ className: "d-flex flex-grow-1"
3129
+ }, Array.from({
3130
+ length: answerCount
3131
+ }, function (_, i) {
3132
+ return i + 1;
3133
+ }).map(function (i) {
3134
+ return React.createElement(FormGroup, {
3135
+ className: "d-flex flex-column px-4"
3136
+ }, React.createElement(Label, {
3137
+ htmlFor: "answer-" + i,
3138
+ className: "" + styles$2["question-label"]
3139
+ }, i, "\uBC88"), React.createElement(Input, {
3140
+ id: "answer-" + i,
3141
+ type: "radio",
3142
+ checked: question.correctAnswers.includes(i),
3143
+ onClick: function onClick() {
3144
+ return onChangeCorrectAnswers(i, index);
3145
+ },
3146
+ disabled: isDisabled
3147
+ }));
3148
+ }))), React.createElement("div", {
3149
+ className: "d-flex align-items-center"
3150
+ }, React.createElement(FormGroup, {
3151
+ className: "mx-3",
3152
+ style: {
3153
+ width: "140px"
3154
+ }
3155
+ }, React.createElement(CustomSelect, {
3156
+ value: question.score,
3157
+ options: scoreOptions,
3158
+ onChange: function onChange(value) {
3159
+ return onChangeScoreAnswer(value.value, index);
3160
+ },
3161
+ isDisabled: isDisabled
3162
+ }))));
3163
+ };
3164
+
3165
+ var ArticleGroupView = function ArticleGroupView(_ref) {
3166
+ var categoryOptions = _ref.categoryOptions,
3167
+ article = _ref.article,
3168
+ questions = _ref.questions,
3169
+ answerCount = _ref.answerCount,
3170
+ questionCount = _ref.questionCount,
3171
+ categoryId = _ref.categoryId,
3172
+ isActive = _ref.isActive,
3173
+ isDisabled = _ref.isDisabled,
3174
+ onChangeQuestionCount = _ref.onChangeQuestionCount,
3175
+ onChangeCategory = _ref.onChangeCategory,
3176
+ onChangeAnswerCount = _ref.onChangeAnswerCount,
3177
+ onChangeCorrectAnswers = _ref.onChangeCorrectAnswers,
3178
+ onChangeScoreAnswer = _ref.onChangeScoreAnswer;
3179
+ var _useTranslation = useTranslation(),
3180
+ t = _useTranslation.t;
3181
+ var handleChangeQuestionCount = function handleChangeQuestionCount(value) {
3182
+ onChangeQuestionCount(article, value === null || value === void 0 ? void 0 : value.value, answerCount);
3183
+ };
3184
+ var handleChangeCategory = function handleChangeCategory(value) {
3185
+ onChangeCategory(article, value === null || value === void 0 ? void 0 : value.value);
3186
+ };
3187
+ var handleChangeAnswerCount = function handleChangeAnswerCount(value) {
3188
+ onChangeAnswerCount(article, value === null || value === void 0 ? void 0 : value.value, answerCount);
3189
+ };
3190
+ var handleChangeCorrectAnswers = function handleChangeCorrectAnswers(value, index) {
3191
+ onChangeCorrectAnswers(article, index, value);
3192
+ };
3193
+ var handleChangeScoreAnswer = function handleChangeScoreAnswer(value, index) {
3194
+ onChangeScoreAnswer(article, index, value);
3195
+ };
3196
+ var questionOptions = QUESTION_OPTIONS.map(function (i) {
3197
+ return {
3198
+ label: i + "\uAC1C",
3199
+ value: i
3200
+ };
3201
+ });
3202
+ var answerOptions = ANSWER_OPTIONS.map(function (i) {
3203
+ return {
3204
+ label: i + "\uBC88",
3205
+ value: i
3206
+ };
3207
+ });
3208
+ return React.createElement("div", {
3209
+ className: "d-flex " + styles$2["question"] + " " + (isActive ? styles$2["question--active"] : "")
3210
+ }, React.createElement("div", {
3211
+ className: "py-1"
3212
+ }, React.createElement(PiDotsNineLight, {
3213
+ size: 18
3214
+ })), React.createElement("div", {
3215
+ className: "px-4"
3216
+ }, React.createElement(Row, null, React.createElement(Col, {
3217
+ xs: 12
3218
+ }, React.createElement("p", {
3219
+ className: "mb-0 " + styles$2["question-article"]
3220
+ }, "\uBB38\uD56D"), React.createElement("p", {
3221
+ className: "text-center " + styles$2["question-article"]
3222
+ }, article)))), React.createElement("div", {
3223
+ className: "flex-grow-1"
3224
+ }, React.createElement(Row, null, React.createElement(Col, {
3225
+ xs: 3
3226
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3227
+ htmlFor: "question_count",
3228
+ className: "" + styles$2["question-label"]
3229
+ }, t("question_count")), React.createElement(CustomSelect, {
3230
+ inputId: "question_count",
3231
+ value: questionCount,
3232
+ options: questionOptions,
3233
+ onChange: handleChangeQuestionCount,
3234
+ isDisabled: isDisabled
3235
+ }))), React.createElement(Col, {
3236
+ xs: 3
3237
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3238
+ htmlFor: "category",
3239
+ className: "" + styles$2["question-label"]
3240
+ }, t("category")), React.createElement(CustomSelect, {
3241
+ inputId: "category",
3242
+ value: categoryId,
3243
+ options: categoryOptions,
3244
+ onChange: handleChangeCategory,
3245
+ isDisabled: isDisabled
3246
+ }))), React.createElement(Col, {
3247
+ xs: 3
3248
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3249
+ htmlFor: "answer_count",
3250
+ className: "" + styles$2["question-label"]
3251
+ }, t("answer_count")), React.createElement(CustomSelect, {
3252
+ inputId: "answer_count",
3253
+ value: answerCount,
3254
+ options: answerOptions,
3255
+ onChange: handleChangeAnswerCount,
3256
+ isDisabled: isDisabled
3257
+ }))), React.createElement(Col, {
3258
+ xs: 3
3259
+ })), React.createElement("div", null, questions.map(function (q, index) {
3260
+ return React.createElement(QuestionView, {
3261
+ key: index,
3262
+ question: q,
3263
+ answerCount: answerCount,
3264
+ index: index,
3265
+ onChangeCorrectAnswers: handleChangeCorrectAnswers,
3266
+ onChangeScoreAnswer: handleChangeScoreAnswer,
3267
+ isDisabled: isDisabled
3268
+ });
3269
+ }))));
3270
+ };
3271
+
3272
+ var useExamDetailView = function useExamDetailView(props) {
3273
+ var exam = props.exam,
3274
+ onChangeExam = props.onChangeExam;
3275
+ var _useTranslation = useTranslation(),
3276
+ t = _useTranslation.t;
3277
+ var handleChangeQuestionCount = function handleChangeQuestionCount(article, questionCount, answerCount) {
3278
+ if (!exam) return;
3279
+ var examQuestions = exam.questions;
3280
+ var questions = examQuestions.filter(function (i) {
3281
+ return i.article === +article;
3282
+ });
3283
+ var prevQuestions = examQuestions.filter(function (i) {
3284
+ return i.article < +article;
3285
+ });
3286
+ var nextQuestions = examQuestions.filter(function (i) {
3287
+ return i.article > +article;
3288
+ });
3289
+ var lastOrder = questions[questions.length - 1].questionOrder;
3290
+ if (questions.length === questionCount) return;
3291
+ if (questions.length < questionCount) {
3292
+ var additionalQuestions = Array.from({
3293
+ length: questionCount - questions.length
3294
+ }).map(function (_, index) {
3295
+ var _questions$;
3296
+ return {
3297
+ article: +article,
3298
+ correctAnswers: [1],
3299
+ numberOfAnswers: answerCount,
3300
+ categoryId: (_questions$ = questions[0]) === null || _questions$ === void 0 ? void 0 : _questions$.categoryId,
3301
+ score: DEFAULT_SCORE,
3302
+ questionOrder: lastOrder + index + 1
3303
+ };
3304
+ });
3305
+ var newQuestions = [].concat(prevQuestions, questions, additionalQuestions, nextQuestions.map(function (i) {
3306
+ return _extends({}, i, {
3307
+ questionOrder: i.questionOrder + questionCount - questions.length
3308
+ });
3309
+ }));
3310
+ onChangeExam(_extends({}, exam, {
3311
+ questions: [].concat(newQuestions)
3312
+ }));
3313
+ } else {
3314
+ var remainQuestions = questions.slice(0, questionCount);
3315
+ var _newQuestions = [].concat(prevQuestions, remainQuestions, nextQuestions.map(function (i) {
3316
+ return _extends({}, i, {
3317
+ questionOrder: i.questionOrder - questions.length + questionCount
3318
+ });
3319
+ }));
3320
+ onChangeExam(_extends({}, exam, {
3321
+ questions: [].concat(_newQuestions)
3322
+ }));
3323
+ }
3324
+ };
3325
+ var handleChangeCategory = function handleChangeCategory(article, categoryId) {
3326
+ if (!exam) return;
3327
+ var examQuestions = exam.questions;
3328
+ var questions = examQuestions.filter(function (i) {
3329
+ return i.article === +article;
3330
+ });
3331
+ var otherQuestions = examQuestions.filter(function (i) {
3332
+ return i.article !== +article;
3333
+ });
3334
+ onChangeExam(_extends({}, exam, {
3335
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3336
+ return _extends({}, q, {
3337
+ categoryId: categoryId
3338
+ });
3339
+ }))
3340
+ }));
3341
+ };
3342
+ var handleChangeAnswerCount = function handleChangeAnswerCount(article, newAnswerCount, answerCount) {
3343
+ if (!exam) return;
3344
+ if (newAnswerCount === answerCount) return;
3345
+ var examQuestions = exam.questions;
3346
+ var questions = examQuestions.filter(function (i) {
3347
+ return i.article === +article;
3348
+ });
3349
+ var otherQuestions = examQuestions.filter(function (i) {
3350
+ return i.article !== +article;
3351
+ });
3352
+ if (answerCount < newAnswerCount) {
3353
+ onChangeExam(_extends({}, exam, {
3354
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3355
+ return _extends({}, q, {
3356
+ numberOfAnswers: newAnswerCount
3357
+ });
3358
+ }))
3359
+ }));
3360
+ } else {
3361
+ onChangeExam(_extends({}, exam, {
3362
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3363
+ return _extends({}, q, {
3364
+ numberOfAnswers: newAnswerCount,
3365
+ correctAnswers: q.correctAnswers.filter(function (i) {
3366
+ return i <= newAnswerCount;
3367
+ })
3368
+ });
3369
+ }))
3370
+ }));
3371
+ }
3372
+ };
3373
+ var handleChangeCorrectAnswers = function handleChangeCorrectAnswers(article, index, answer) {
3374
+ if (!exam) return;
3375
+ var examQuestions = exam.questions;
3376
+ var questions = examQuestions.filter(function (i) {
3377
+ return i.article === +article;
3378
+ });
3379
+ var otherQuestions = examQuestions.filter(function (i) {
3380
+ return i.article !== +article;
3381
+ });
3382
+ var selectedQuestion = questions[index];
3383
+ onChangeExam(_extends({}, exam, {
3384
+ questions: [].concat(otherQuestions, questions.slice(0, index), [_extends({}, selectedQuestion, {
3385
+ correctAnswers: [answer]
3386
+ })], questions.slice(index + 1))
3387
+ }));
3388
+ };
3389
+ var handleChangeScoreAnswer = function handleChangeScoreAnswer(article, index, score) {
3390
+ if (!exam) return;
3391
+ var examQuestions = exam.questions;
3392
+ var questions = examQuestions.filter(function (i) {
3393
+ return i.article === +article;
3394
+ });
3395
+ var otherQuestions = examQuestions.filter(function (i) {
3396
+ return i.article !== +article;
3397
+ });
3398
+ var selectedQuestion = questions[index];
3399
+ if (score === selectedQuestion.score) return;
3400
+ onChangeExam(_extends({}, exam, {
3401
+ questions: [].concat(otherQuestions, questions.slice(0, index), [_extends({}, selectedQuestion, {
3402
+ score: score
3403
+ })], questions.slice(index + 1))
3404
+ }));
3405
+ };
3406
+ var handleChangeDuration = function handleChangeDuration(value) {
3407
+ if (!exam) return;
3408
+ onChangeExam(_extends({}, exam, {
3409
+ duration: value === null || value === void 0 ? void 0 : value.value
3410
+ }));
3411
+ };
3412
+ var handleChangeTitle = function handleChangeTitle(e) {
3413
+ if (!exam) return;
3414
+ onChangeExam(_extends({}, exam, {
3415
+ title: e.target.value
3416
+ }));
3417
+ };
3418
+ var handleAddArticle = function handleAddArticle() {
3419
+ var _$maxBy, _$maxBy2;
3420
+ if (!exam) return;
3421
+ var maxArticle = ((_$maxBy = _.maxBy(exam.questions, "article")) === null || _$maxBy === void 0 ? void 0 : _$maxBy.article) || 0;
3422
+ var maxOrder = ((_$maxBy2 = _.maxBy(exam.questions, "questionOrder")) === null || _$maxBy2 === void 0 ? void 0 : _$maxBy2.questionOrder) || 0;
3423
+ onChangeExam(_extends({}, exam, {
3424
+ questions: [].concat(exam.questions, [{
3425
+ article: maxArticle + 1,
3426
+ correctAnswers: [1],
3427
+ numberOfAnswers: DEFAULT_ANSWER_COUNT,
3428
+ score: DEFAULT_SCORE,
3429
+ questionOrder: maxOrder + 1
3430
+ }])
3431
+ }));
3432
+ };
3433
+ var examGroupByArticle = useMemo(function () {
3434
+ if (!exam) return [];
3435
+ var articles = [];
3436
+ var groupedArticle = _.groupBy(exam.questions, "article");
3437
+ for (var key in groupedArticle) {
3438
+ if (Object.prototype.hasOwnProperty.call(groupedArticle, key)) {
3439
+ var _questions$find, _$maxBy3;
3440
+ var questions = groupedArticle[key];
3441
+ articles.push({
3442
+ article: +key,
3443
+ categoryId: (_questions$find = questions.find(function (i) {
3444
+ return !!i.categoryId;
3445
+ })) === null || _questions$find === void 0 ? void 0 : _questions$find.categoryId,
3446
+ answerCount: ((_$maxBy3 = _.maxBy(questions, "numberOfAnswers")) === null || _$maxBy3 === void 0 ? void 0 : _$maxBy3.numberOfAnswers) || DEFAULT_ANSWER_COUNT,
3447
+ questionCount: questions.length,
3448
+ questions: questions
3449
+ });
3450
+ }
3451
+ }
3452
+ return _.sortBy(articles, "article");
3453
+ }, [JSON.stringify(exam)]);
3454
+ var durationOptions = useMemo(function () {
3455
+ var options = DURATION_OPTIONS.map(function (i) {
3456
+ return {
3457
+ label: i + "\uBD84",
3458
+ value: i
3459
+ };
3460
+ });
3461
+ if (!!exam.duration && exam.duration > DURATION_OPTIONS[DURATION_OPTIONS.length - 1]) return [].concat(options, [{
3462
+ label: exam.duration + "\uBD84",
3463
+ value: exam.duration
3464
+ }]);
3465
+ return options;
3466
+ }, [exam.duration]);
3467
+ return {
3468
+ t: t,
3469
+ durationOptions: durationOptions,
3470
+ examGroupByArticle: examGroupByArticle,
3471
+ handleAddArticle: handleAddArticle,
3472
+ handleChangeScoreAnswer: handleChangeScoreAnswer,
3473
+ handleChangeTitle: handleChangeTitle,
3474
+ handleChangeDuration: handleChangeDuration,
3475
+ handleChangeCorrectAnswers: handleChangeCorrectAnswers,
3476
+ handleChangeAnswerCount: handleChangeAnswerCount,
3477
+ handleChangeQuestionCount: handleChangeQuestionCount,
3478
+ handleChangeCategory: handleChangeCategory
3479
+ };
3480
+ };
3481
+
3482
+ var ExamDetailView = function ExamDetailView(_ref) {
3483
+ var _ref$className = _ref.className,
3484
+ className = _ref$className === void 0 ? "" : _ref$className,
3485
+ categoryOptions = _ref.categoryOptions,
3486
+ exam = _ref.exam,
3487
+ _ref$isUsingMui = _ref.isUsingMui,
3488
+ isUsingMui = _ref$isUsingMui === void 0 ? true : _ref$isUsingMui,
3489
+ isDisabled = _ref.isDisabled,
3490
+ onChangeExam = _ref.onChangeExam;
3491
+ var _useExamDetailView = useExamDetailView({
3492
+ exam: exam,
3493
+ onChangeExam: onChangeExam
3494
+ }),
3495
+ t = _useExamDetailView.t,
3496
+ durationOptions = _useExamDetailView.durationOptions,
3497
+ examGroupByArticle = _useExamDetailView.examGroupByArticle,
3498
+ handleAddArticle = _useExamDetailView.handleAddArticle,
3499
+ handleChangeScoreAnswer = _useExamDetailView.handleChangeScoreAnswer,
3500
+ handleChangeTitle = _useExamDetailView.handleChangeTitle,
3501
+ handleChangeDuration = _useExamDetailView.handleChangeDuration,
3502
+ handleChangeCorrectAnswers = _useExamDetailView.handleChangeCorrectAnswers,
3503
+ handleChangeAnswerCount = _useExamDetailView.handleChangeAnswerCount,
3504
+ handleChangeQuestionCount = _useExamDetailView.handleChangeQuestionCount,
3505
+ handleChangeCategory = _useExamDetailView.handleChangeCategory;
3506
+ return React.createElement(Row, {
3507
+ className: "" + className
3508
+ }, React.createElement(Col, {
3509
+ xs: 5
3510
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3511
+ className: "" + styles$2["question-label"],
3512
+ htmlFor: "title"
3513
+ }, t("title")), React.createElement(Input, {
3514
+ disabled: isDisabled,
3515
+ className: "w-100 rounded-2 " + styles$2["question-input"],
3516
+ value: exam.title,
3517
+ id: "title",
3518
+ placeholder: t("enter_title"),
3519
+ onChange: handleChangeTitle
3520
+ }))), React.createElement(Col, {
3521
+ xs: 3
3522
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3523
+ className: "" + styles$2["question-label"],
3524
+ htmlFor: "duration"
3525
+ }, t("duration")), React.createElement(CustomSelect, {
3526
+ inputId: "duration",
3527
+ value: exam.duration,
3528
+ options: durationOptions,
3529
+ onChange: handleChangeDuration,
3530
+ isDisabled: isDisabled
3531
+ }))), React.createElement(Col, {
3532
+ xs: 4
3533
+ }), examGroupByArticle.map(function (i, index) {
3534
+ return React.createElement(Col, {
3535
+ xs: 12,
3536
+ key: i.article,
3537
+ className: (index === 0 && !isUsingMui ? "mt-3" : "") + " " + (!isUsingMui ? "mb-4" : "")
3538
+ }, React.createElement(ArticleGroupView, Object.assign({}, i, {
3539
+ categoryOptions: categoryOptions,
3540
+ isActive: index === examGroupByArticle.length - 1,
3541
+ onChangeQuestionCount: handleChangeQuestionCount,
3542
+ onChangeCategory: handleChangeCategory,
3543
+ onChangeAnswerCount: handleChangeAnswerCount,
3544
+ onChangeCorrectAnswers: handleChangeCorrectAnswers,
3545
+ onChangeScoreAnswer: handleChangeScoreAnswer,
3546
+ isDisabled: isDisabled
3547
+ })));
3548
+ }), React.createElement(Col, {
3549
+ xs: 12
3550
+ }, React.createElement(Button, {
3551
+ disabled: isDisabled,
3552
+ className: "w-100 d-flex justify-content-center align-items-center " + styles$2["question-btn"],
3553
+ color: "primary",
3554
+ outline: true,
3555
+ onClick: handleAddArticle
3556
+ }, React.createElement(FaPlusCircle, {
3557
+ className: "me-2"
3558
+ }), "\uBB38\uD56D \uCD94\uAC00\uD558\uAE30")));
3559
+ };
3560
+
2657
3561
  var historyCore = createBrowserHistory();
2658
3562
 
2659
- export { ACCESS_TOKEN, BASE_URL, ChatContainer, ChatItemType, CommonAlert, CommonDialog, ConfirmDialog, CustomPagination, CustomSelect, DATE_MIN_VALUE, EXAM_CHANNEL, EXAM_STUDENT_CHANNEL, ExamEvent, LayoutContext, Loading, Login, NotFound, PUSHER_CONFIG, TheLanguageDropdown, api, canAccess as canAccessRoute, diffFromNow, formatTime, getAccessToken$1 as getAccessToken, historyCore, i18n, minutesToTimeSpan, setAlert, setLanguage, setLoading, setUser, store, toISOString, useChatContainer, useConversationList, useGoogleSignOut, usePusherConversation, utcToLocalTime };
3563
+ export { ACCESS_TOKEN, BASE_URL, ChatContainer, ChatItemType, CommonAlert, CommonDialog, ConfirmDialog, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, DATE_MIN_VALUE, DATE_TIME_MIN_VALUE, EXAM_CHANNEL, EXAM_STUDENT_CHANNEL, ExamDetailView, ExamEvent, LANGUAGES, LayoutContext, Loading, Login, NotFound, PUSHER_CONFIG, Role, TheLanguageDropdown, api, canAccess as canAccessRoute, diffFromNow, formatTime, getAccessToken$1 as getAccessToken, historyCore, i18n, minutesToTimeSpan, setAlert, setLanguage, setLoading, setUser, store, toISOString, useChatContainer, useConversationList, useGoogleSignOut, useLanguage, usePusherConversation, utcToLocalTime };
2660
3564
  //# sourceMappingURL=index.modern.js.map