touchstudy-core 0.1.9 → 0.1.11

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.
Files changed (30) hide show
  1. package/dist/components/Chats/ChatContainer.d.ts +6 -0
  2. package/dist/components/Chats/ChatHeader.d.ts +1 -0
  3. package/dist/components/Chats/ChatItem.d.ts +2 -1
  4. package/dist/components/Chats/ChatList.d.ts +1 -1
  5. package/dist/components/Chats/configs/types.d.ts +2 -0
  6. package/dist/components/Chats/hooks/useChatContainer.d.ts +6 -1
  7. package/dist/components/Chats/hooks/useMessageList.d.ts +2 -1
  8. package/dist/components/Dialogs/ConfirmDialog.d.ts +1 -0
  9. package/dist/components/Selects/CustomAsyncSelect.d.ts +3 -0
  10. package/dist/components/Selects/CustomCreatable.d.ts +3 -0
  11. package/dist/components/Selects/CustomSelect.d.ts +1 -1
  12. package/dist/containers/Exams/components/ArticleGroupView.d.ts +19 -0
  13. package/dist/containers/Exams/components/QuestionView.d.ts +11 -0
  14. package/dist/containers/Exams/configs/constants.d.ts +8 -0
  15. package/dist/containers/Exams/configs/interfaces.d.ts +9 -0
  16. package/dist/containers/Exams/configs/types.d.ts +21 -0
  17. package/dist/containers/Exams/hooks/useExamDetailView.d.ts +23 -0
  18. package/dist/containers/Exams/views/ExamDetailView.d.ts +4 -0
  19. package/dist/containers/Login/configs/constants.d.ts +5 -0
  20. package/dist/containers/Login/views/Login.d.ts +2 -1
  21. package/dist/containers/Login/views/block/BlockLogin.d.ts +2 -1
  22. package/dist/index.css +40 -1
  23. package/dist/index.d.ts +11 -1
  24. package/dist/index.js +993 -112
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.modern.js +978 -113
  27. package/dist/index.modern.js.map +1 -1
  28. package/dist/utils/useLanguage.d.ts +10 -0
  29. package/package.json +3 -1
  30. package/dist/services/api.d.ts +0 -3
@@ -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 } 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,16 @@ 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 Select, { components } from 'react-select';
18
+ import { FaCaretDown, FaPlusCircle } from 'react-icons/fa';
17
19
  import { Link } from 'react-router-dom';
18
20
  import { IoIosCloseCircle, IoMdSend } from 'react-icons/io';
19
- import { ToastContainer, toast } from 'react-toastify';
20
21
  import Pusher from 'pusher-js';
22
+ import { toast } from 'react-toastify';
23
+ export { ToastContainer, toast } from 'react-toastify';
24
+ import CreatableSelect from 'react-select/creatable';
25
+ import { PiDotsNineLight } from 'react-icons/pi';
26
+ import _ from 'lodash';
21
27
 
22
28
  var setLoading = createAction("common/setLoading");
23
29
  var setAlert = createAction("common/setAlert");
@@ -147,6 +153,12 @@ var AuthenticationMessage;
147
153
  AuthenticationMessage["NotAllowedToRegister"] = "NotAllowedToRegister";
148
154
  AuthenticationMessage["InvalidGoogleToken"] = "InvalidGoogleToken";
149
155
  })(AuthenticationMessage || (AuthenticationMessage = {}));
156
+ var Role;
157
+ (function (Role) {
158
+ Role["Student"] = "Student";
159
+ Role["Teacher"] = "Teacher";
160
+ Role["Admin"] = "Admin";
161
+ })(Role || (Role = {}));
150
162
 
151
163
  var useGoogleSignOut = function useGoogleSignOut(props) {
152
164
  var dispatch = useDispatch();
@@ -193,7 +205,8 @@ var schema = object({
193
205
  var BlockLogin = function BlockLogin(_ref) {
194
206
  var defaultInfo = _ref.defaultInfo,
195
207
  onNavigate = _ref.onNavigate,
196
- isTeacher = _ref.isTeacher;
208
+ _ref$role = _ref.role,
209
+ role = _ref$role === void 0 ? Role.Student : _ref$role;
197
210
  var dispatch = useDispatch();
198
211
  var _useGoogleSignOut = useGoogleSignOut({
199
212
  onNavigate: onNavigate
@@ -219,7 +232,6 @@ var BlockLogin = function BlockLogin(_ref) {
219
232
  token: accessToken,
220
233
  googleId: googleId
221
234
  };
222
- var role = isTeacher ? "Teacher" : "Student";
223
235
  dispatch(setLoading(true));
224
236
  var _temp = _catch(function () {
225
237
  return Promise.resolve(apiLoginGoogle(infoLogin, role)).then(function (res1) {
@@ -227,7 +239,7 @@ var BlockLogin = function BlockLogin(_ref) {
227
239
  var tokenJWT = res1.data.token;
228
240
  localStorage.setItem("USER_INFORMATION", JSON.stringify(infoLogin));
229
241
  localStorage.setItem(ACCESS_TOKEN, tokenJWT);
230
- if (!isTeacher && isFirstLogin) {
242
+ if (role === Role.Student && isFirstLogin) {
231
243
  onNavigate("/register/info");
232
244
  } else {
233
245
  onNavigate("/");
@@ -346,7 +358,7 @@ var useLogin = function useLogin(onNavigate) {
346
358
 
347
359
  var Login = function Login(_ref) {
348
360
  var onNavigate = _ref.onNavigate,
349
- isTeacher = _ref.isTeacher;
361
+ role = _ref.role;
350
362
  var _useLogin = useLogin(onNavigate),
351
363
  defaultInfo = _useLogin.defaultInfo;
352
364
  return React.createElement("div", {
@@ -361,7 +373,7 @@ var Login = function Login(_ref) {
361
373
  }, React.createElement(BlockLogin, {
362
374
  defaultInfo: defaultInfo,
363
375
  onNavigate: onNavigate,
364
- isTeacher: isTeacher
376
+ role: role
365
377
  }))));
366
378
  };
367
379
 
@@ -602,11 +614,11 @@ var NotFound = function NotFound() {
602
614
  document.title = TITLE;
603
615
  });
604
616
  return React.createElement("div", {
605
- className: "not-found"
617
+ className: "not-found d-flex justify-content-center"
606
618
  }, React.createElement("div", {
607
- className: "clearfix"
619
+ className: "clearfix pt-5"
608
620
  }, React.createElement("h1", {
609
- className: "float-left display-3 mr-4"
621
+ className: "float-left display-3 fw-bold mr-4 text-center"
610
622
  }, "404"), React.createElement("div", {
611
623
  className: "float-left"
612
624
  }, React.createElement("h4", {
@@ -661,16 +673,13 @@ var LayoutContext = function LayoutContext(_ref) {
661
673
  var _state$common;
662
674
  return state === null || state === void 0 ? void 0 : (_state$common = state.common) === null || _state$common === void 0 ? void 0 : _state$common.user;
663
675
  });
676
+ var roles = (user === null || user === void 0 ? void 0 : user.roles) || [];
664
677
  var resetAuth = function resetAuth() {
665
678
  handleSignOut();
666
679
  };
667
680
  var checkRoleUser = useCallback(function () {
668
- var _user$roles, _user$roles2;
669
681
  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))) {
682
+ if (!roles.includes(role)) {
674
683
  alert(user.email + " not allow to register " + role);
675
684
  resetAuth();
676
685
  }
@@ -723,19 +732,47 @@ var ConfirmDialog = function ConfirmDialog(_ref) {
723
732
  _ref$title = _ref.title,
724
733
  title = _ref$title === void 0 ? "Confirmation" : _ref$title,
725
734
  toggle = _ref.toggle,
726
- onConfirm = _ref.onConfirm;
735
+ onConfirm = _ref.onConfirm,
736
+ confirmText = _ref.confirmText;
737
+ var _useState = useState(),
738
+ confirmTextValue = _useState[0],
739
+ setConfirmTextValue = _useState[1];
740
+ var handleConfirm = function handleConfirm() {
741
+ onConfirm();
742
+ };
743
+ var handleChangeConfirmText = function handleChangeConfirmText(e) {
744
+ setConfirmTextValue(e.target.value);
745
+ };
746
+ var handlePaste = function handlePaste(e) {
747
+ e.preventDefault();
748
+ };
749
+ useEffect(function () {
750
+ !open && setConfirmTextValue(undefined);
751
+ }, [open]);
752
+ var isValid = !!confirmText && !!confirmTextValue && confirmTextValue.trim() === confirmText.trim();
727
753
  return React.createElement(Modal, {
728
754
  isOpen: open,
729
755
  toggle: toggle,
730
- centered: true
756
+ centered: true,
757
+ zIndex: 1102
731
758
  }, React.createElement(ModalHeader, {
732
759
  toggle: toggle
733
- }, title), React.createElement(ModalBody, null, text), React.createElement(ModalFooter, null, React.createElement(Button, {
760
+ }, 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, {
761
+ value: confirmTextValue,
762
+ onChange: handleChangeConfirmText,
763
+ placeholder: "Please enter...",
764
+ onPaste: handlePaste,
765
+ invalid: !isValid && confirmTextValue !== undefined,
766
+ valid: isValid
767
+ }))), React.createElement(ModalFooter, null, React.createElement(Button, {
734
768
  color: "secondary",
769
+ className: "px-3",
735
770
  onClick: toggle
736
771
  }, cancelText), React.createElement(Button, {
737
772
  color: isDelete ? "danger" : "primary",
738
- onClick: onConfirm
773
+ className: "px-3",
774
+ disabled: !!confirmText && (confirmTextValue === null || confirmTextValue === void 0 ? void 0 : confirmTextValue.trim()) !== confirmText.trim(),
775
+ onClick: handleConfirm
739
776
  }, okText)));
740
777
  };
741
778
 
@@ -753,7 +790,8 @@ var CommonDialog = function CommonDialog(_ref) {
753
790
  isOpen: open,
754
791
  toggle: onClose,
755
792
  centered: centered,
756
- size: size
793
+ size: size,
794
+ zIndex: 1102
757
795
  }, React.createElement(ModalHeader, {
758
796
  toggle: onClose
759
797
  }, title), children);
@@ -970,6 +1008,18 @@ var problem = "문제";
970
1008
  var problem_solving_time = "문제풀이 시간";
971
1009
  var minutes = "분";
972
1010
  var correct_rate = "정확한 비율";
1011
+ var title = "시험명";
1012
+ var duration = "시험 시간";
1013
+ var answer_count = "답변 수";
1014
+ var question_count = "문제 갯수";
1015
+ var category = "문항 카테고리";
1016
+ var save_and_exit = "저장 및 종료";
1017
+ var update_exam = "시험 업데이트";
1018
+ var create_exam = "새 시험 만들기";
1019
+ var enter_title = "시험 제목을 입력하세요";
1020
+ var select_placeholder = "선택하다...";
1021
+ var view_exam = "시험 보기";
1022
+ var back = "뒤쪽에";
973
1023
  var lang_ko = {
974
1024
  problem_solving: problem_solving,
975
1025
  my_story: my_story,
@@ -1027,7 +1077,19 @@ var lang_ko = {
1027
1077
  problem: problem,
1028
1078
  problem_solving_time: problem_solving_time,
1029
1079
  minutes: minutes,
1030
- correct_rate: correct_rate
1080
+ correct_rate: correct_rate,
1081
+ title: title,
1082
+ duration: duration,
1083
+ answer_count: answer_count,
1084
+ question_count: question_count,
1085
+ category: category,
1086
+ save_and_exit: save_and_exit,
1087
+ update_exam: update_exam,
1088
+ create_exam: create_exam,
1089
+ enter_title: enter_title,
1090
+ select_placeholder: select_placeholder,
1091
+ view_exam: view_exam,
1092
+ back: back
1031
1093
  };
1032
1094
 
1033
1095
  var problem_solving$1 = "Problem Solving";
@@ -1087,6 +1149,58 @@ var problem$1 = "Problem ";
1087
1149
  var problem_solving_time$1 = "Problem solving time";
1088
1150
  var minutes$1 = "m";
1089
1151
  var correct_rate$1 = "Correct rate";
1152
+ var difficult_level = "Difficult level";
1153
+ var difficulty_explain = "(The Difficulty Level provides an indication of the difficulty level of each test question)";
1154
+ var explain_your_answer = "Explain your answer";
1155
+ var hint = "Hint";
1156
+ var save_and_add_next_question = "Save and add next question";
1157
+ var save_and_exit$1 = "Save and exit";
1158
+ var question_text = "Question text";
1159
+ var title$1 = "Title";
1160
+ var create_question = "Create question";
1161
+ var parent_question = "Parent question";
1162
+ var edit_question = "Edit question";
1163
+ var easy = "Easy";
1164
+ var intermediate = "Intermediate";
1165
+ var difficult = "Difficult";
1166
+ var article = "Article";
1167
+ var correct_answer = "Correct answer";
1168
+ var mark = "Mark";
1169
+ var answer = "Answer";
1170
+ var add_new_row = "Add new row";
1171
+ var question_text_required = "Question text is required";
1172
+ var create_question_success = "Question is created successfully";
1173
+ var update_question_success = "Question is updated successfully";
1174
+ var number_of_answers = "Number of answers";
1175
+ var correct_answers = "Correct answers";
1176
+ var category$1 = "Category";
1177
+ var score = "Score";
1178
+ var enter_title$1 = "Enter title";
1179
+ var enter_score = "Enter score";
1180
+ var exam_title_required = "Exam title is required";
1181
+ var question_category_required = "Question category is required";
1182
+ var start_time = "Start time";
1183
+ var end_time = "End time";
1184
+ var enter_class_name = "Enter class name";
1185
+ var class_required = "Class name is required";
1186
+ var total_teachers = "Total teachers";
1187
+ var start_time_required = "Start time is required";
1188
+ var end_time_required = "End time is required";
1189
+ var full_name = "Full name";
1190
+ var email = "Email";
1191
+ var is_paid = "Is paid";
1192
+ var payment_time = "Payment time";
1193
+ var create_and_continue = "Create and continue";
1194
+ var payments = "Payments";
1195
+ var duration$1 = "Duration";
1196
+ var answer_count$1 = "Answer count";
1197
+ var question_count$1 = "Question count";
1198
+ var multi_choice = "Is multiple";
1199
+ var select_placeholder$1 = "Select...";
1200
+ var view_exam$1 = "View exam";
1201
+ var update_exam$1 = "Update exam";
1202
+ var create_exam$1 = "Create exam";
1203
+ var back$1 = "Back";
1090
1204
  var lang_en = {
1091
1205
  problem_solving: problem_solving$1,
1092
1206
  my_story: my_story$1,
@@ -1144,7 +1258,59 @@ var lang_en = {
1144
1258
  problem: problem$1,
1145
1259
  problem_solving_time: problem_solving_time$1,
1146
1260
  minutes: minutes$1,
1147
- correct_rate: correct_rate$1
1261
+ correct_rate: correct_rate$1,
1262
+ difficult_level: difficult_level,
1263
+ difficulty_explain: difficulty_explain,
1264
+ explain_your_answer: explain_your_answer,
1265
+ hint: hint,
1266
+ save_and_add_next_question: save_and_add_next_question,
1267
+ save_and_exit: save_and_exit$1,
1268
+ question_text: question_text,
1269
+ title: title$1,
1270
+ create_question: create_question,
1271
+ parent_question: parent_question,
1272
+ edit_question: edit_question,
1273
+ easy: easy,
1274
+ intermediate: intermediate,
1275
+ difficult: difficult,
1276
+ article: article,
1277
+ correct_answer: correct_answer,
1278
+ mark: mark,
1279
+ answer: answer,
1280
+ add_new_row: add_new_row,
1281
+ question_text_required: question_text_required,
1282
+ create_question_success: create_question_success,
1283
+ update_question_success: update_question_success,
1284
+ number_of_answers: number_of_answers,
1285
+ correct_answers: correct_answers,
1286
+ category: category$1,
1287
+ score: score,
1288
+ enter_title: enter_title$1,
1289
+ enter_score: enter_score,
1290
+ exam_title_required: exam_title_required,
1291
+ question_category_required: question_category_required,
1292
+ start_time: start_time,
1293
+ end_time: end_time,
1294
+ enter_class_name: enter_class_name,
1295
+ class_required: class_required,
1296
+ total_teachers: total_teachers,
1297
+ start_time_required: start_time_required,
1298
+ end_time_required: end_time_required,
1299
+ full_name: full_name,
1300
+ email: email,
1301
+ is_paid: is_paid,
1302
+ payment_time: payment_time,
1303
+ create_and_continue: create_and_continue,
1304
+ payments: payments,
1305
+ duration: duration$1,
1306
+ answer_count: answer_count$1,
1307
+ question_count: question_count$1,
1308
+ multi_choice: multi_choice,
1309
+ select_placeholder: select_placeholder$1,
1310
+ view_exam: view_exam$1,
1311
+ update_exam: update_exam$1,
1312
+ create_exam: create_exam$1,
1313
+ back: back$1
1148
1314
  };
1149
1315
 
1150
1316
  i18n.use(initReactI18next).init({
@@ -1183,7 +1349,7 @@ var SUPPORTED_LANGUAGES_CODE = LANGUAGES.map(function (i) {
1183
1349
  return i.code;
1184
1350
  });
1185
1351
 
1186
- var TheLanguageDropdown = function TheLanguageDropdown() {
1352
+ var useLanguage = function useLanguage() {
1187
1353
  var defaultLanguage = !!localStorage.getItem("language") ? localStorage.getItem("language") : navigator.language || DEFAULT_LANGUAGE_CODE;
1188
1354
  var dispatch = useDispatch();
1189
1355
  var _useTranslation = useTranslation(),
@@ -1206,19 +1372,32 @@ var TheLanguageDropdown = function TheLanguageDropdown() {
1206
1372
  setItemLanguage(lang);
1207
1373
  dispatch(setLanguage(lang));
1208
1374
  };
1375
+ useEffect(function () {
1376
+ changeLanguageApp(language);
1377
+ }, [language]);
1209
1378
  var currentLanguage = useMemo(function () {
1210
1379
  var currentLang = LANGUAGES.find(function (i) {
1211
1380
  return i.code === language;
1212
1381
  });
1213
1382
  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);
1383
+ return currentLang;
1221
1384
  }, [language]);
1385
+ return {
1386
+ language: language,
1387
+ dropdownOpen: dropdownOpen,
1388
+ currentLanguage: currentLanguage,
1389
+ toggle: toggle,
1390
+ setItemLanguage: setItemLanguage
1391
+ };
1392
+ };
1393
+
1394
+ var TheLanguageDropdown = function TheLanguageDropdown() {
1395
+ var _useLanguage = useLanguage(),
1396
+ currentLanguage = _useLanguage.currentLanguage,
1397
+ language = _useLanguage.language,
1398
+ dropdownOpen = _useLanguage.dropdownOpen,
1399
+ toggle = _useLanguage.toggle,
1400
+ setItemLanguage = _useLanguage.setItemLanguage;
1222
1401
  return React.createElement(Dropdown, {
1223
1402
  isOpen: dropdownOpen,
1224
1403
  toggle: toggle,
@@ -1232,7 +1411,10 @@ var TheLanguageDropdown = function TheLanguageDropdown() {
1232
1411
  display: 'flex',
1233
1412
  alignItems: 'center'
1234
1413
  }
1235
- }, currentLanguage, React.createElement(IoChevronDown, {
1414
+ }, !!currentLanguage && React.createElement("img", {
1415
+ className: "mr-2 " + styles['dropdown-menu-flag'],
1416
+ src: currentLanguage.image
1417
+ }), !!currentLanguage && currentLanguage.shortName, React.createElement(IoChevronDown, {
1236
1418
  className: "ml-2",
1237
1419
  style: {
1238
1420
  fontSize: '15px',
@@ -1316,14 +1498,54 @@ function _objectWithoutPropertiesLoose(source, excluded) {
1316
1498
  return target;
1317
1499
  }
1318
1500
 
1319
- var _excluded = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
1501
+ var _excluded = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
1502
+ var DropdownIndicator = function DropdownIndicator(props) {
1503
+ return React.createElement(components.DropdownIndicator, Object.assign({}, props), React.createElement(FaCaretDown, {
1504
+ color: "#5458D5"
1505
+ }));
1506
+ };
1507
+ var CustomOption = function CustomOption(props) {
1508
+ return React.createElement(components.Option, Object.assign({}, props), React.createElement("div", {
1509
+ style: {
1510
+ fontSize: "14px",
1511
+ fontWeight: 500
1512
+ }
1513
+ }, props.data.label));
1514
+ };
1515
+ var customStyles = {
1516
+ control: function control(baseStyles, state) {
1517
+ return _extends({}, baseStyles, {
1518
+ fontSize: "14px",
1519
+ fontWeight: 700,
1520
+ color: "#5458D5",
1521
+ borderColor: state.isFocused ? '#5458D5' : '#C3C5FE'
1522
+ });
1523
+ },
1524
+ input: function input(baseStyles, _) {
1525
+ return _extends({}, baseStyles, {
1526
+ fontSize: "14px",
1527
+ fontWeight: 700,
1528
+ color: "#5458D5"
1529
+ });
1530
+ },
1531
+ singleValue: function singleValue(baseStyles) {
1532
+ return _extends({}, baseStyles, {
1533
+ fontSize: "14px",
1534
+ fontWeight: 700,
1535
+ color: "#5458D5"
1536
+ });
1537
+ }
1538
+ };
1320
1539
  var CustomSelect = function CustomSelect(_ref) {
1321
- var options = _ref.options,
1540
+ var isDefault = _ref.isDefault,
1541
+ options = _ref.options,
1322
1542
  isDisabled = _ref.isDisabled,
1323
1543
  scrollBottom = _ref.scrollBottom,
1324
1544
  value = _ref.value,
1325
1545
  isMulti = _ref.isMulti,
1326
1546
  rest = _objectWithoutPropertiesLoose(_ref, _excluded);
1547
+ var _useTranslation = useTranslation(),
1548
+ t = _useTranslation.t;
1327
1549
  var initialValues = Array.isArray(value) ? options.filter(function (i) {
1328
1550
  return value.includes(i.value);
1329
1551
  }) : isMulti ? options.filter(function (i) {
@@ -1334,9 +1556,19 @@ var CustomSelect = function CustomSelect(_ref) {
1334
1556
  return React.createElement(Select, Object.assign({
1335
1557
  isDisabled: isDisabled,
1336
1558
  options: options,
1337
- value: initialValues,
1559
+ value: !isDefault ? initialValues != null ? initialValues : null : undefined,
1560
+ defaultValue: isDefault ? initialValues : undefined,
1338
1561
  menuPlacement: scrollBottom ? "top" : "auto",
1339
- isMulti: isMulti
1562
+ isMulti: isMulti,
1563
+ components: {
1564
+ IndicatorSeparator: function IndicatorSeparator() {
1565
+ return null;
1566
+ },
1567
+ DropdownIndicator: DropdownIndicator,
1568
+ Option: CustomOption
1569
+ },
1570
+ styles: customStyles,
1571
+ placeholder: t("select_placeholder")
1340
1572
  }, rest));
1341
1573
  };
1342
1574
 
@@ -1380,11 +1612,10 @@ var MessageStatus;
1380
1612
  })(MessageStatus || (MessageStatus = {}));
1381
1613
 
1382
1614
  var ChatRightItem = function ChatRightItem(_ref) {
1383
- var content = _ref.content,
1615
+ var id = _ref.id,
1616
+ content = _ref.content,
1384
1617
  createdAt = _ref.createdAt,
1385
1618
  isRead = _ref.isRead,
1386
- _ref$type = _ref.type,
1387
- type = _ref$type === void 0 ? ChatItemType.Default : _ref$type,
1388
1619
  examCode = _ref.examCode,
1389
1620
  isSystemLog = _ref.isSystemLog,
1390
1621
  parentId = _ref.parentId,
@@ -1398,8 +1629,11 @@ var ChatRightItem = function ChatRightItem(_ref) {
1398
1629
  examTitle = _ref.examTitle,
1399
1630
  parentContent = _ref.parentContent,
1400
1631
  status = _ref.status,
1632
+ selectedReplyMessageId = _ref.selectedReplyMessageId,
1633
+ selectedReplyItemRef = _ref.selectedReplyItemRef,
1401
1634
  onAddExamMessage = _ref.onAddExamMessage,
1402
- onReTrySendMessage = _ref.onReTrySendMessage;
1635
+ onReTrySendMessage = _ref.onReTrySendMessage,
1636
+ onGotoParentMessage = _ref.onGotoParentMessage;
1403
1637
  var _useState = useState(false),
1404
1638
  isShowTime = _useState[0],
1405
1639
  setShowTime = _useState[1];
@@ -1424,16 +1658,17 @@ var ChatRightItem = function ChatRightItem(_ref) {
1424
1658
  setShowTime(isSystemLog || !!isFirst);
1425
1659
  }, [isFirst, isSystemLog]);
1426
1660
  return React.createElement("li", {
1661
+ ref: selectedReplyMessageId === id ? selectedReplyItemRef : undefined,
1427
1662
  className: "px-3 " + (!isLast ? "pb-1" : "pb-3") + " " + (!!examCode ? "border border-top-0 border-info" : "") + " " + (!!examCode && isLast ? "border-bottom-1 mb-3" : "border-bottom-0")
1428
1663
  }, showExamHeader && isFirst && React.createElement("div", {
1429
1664
  className: "d-flex bg-info justify-content-between px-3 mb-3 py-1 " + styles$1["list__item__header"]
1430
1665
  }, React.createElement(Link, {
1431
1666
  to: "" + (actionLink || "/"),
1432
1667
  className: "text-black"
1433
- }, examTitle), !!examId && !!examTitle && React.createElement("span", {
1668
+ }, examTitle), !!examId && !!examTitle && !!examCode && React.createElement("span", {
1434
1669
  className: "pointer text-black",
1435
1670
  onClick: function onClick() {
1436
- return onAddExamMessage === null || onAddExamMessage === void 0 ? void 0 : onAddExamMessage(examId, examTitle);
1671
+ return onAddExamMessage === null || onAddExamMessage === void 0 ? void 0 : onAddExamMessage(examId, examTitle, examCode);
1437
1672
  }
1438
1673
  }, "Add message to exam")), isSystemLog || !!isFirst ? React.createElement("p", {
1439
1674
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
@@ -1453,14 +1688,17 @@ var ChatRightItem = function ChatRightItem(_ref) {
1453
1688
  }, React.createElement("div", {
1454
1689
  className: "d-flex flex-column align-items-end"
1455
1690
  }, parentId && React.createElement("p", {
1456
- className: "opacity-50 mb-0 py-2 px-3 fw-medium pointer " + styles$1["list__item__message"] + " " + styles$1["list__item__message--reply-from-right"] + " text-end bg-primary text-white"
1691
+ className: "px-3 bg-light opacity-50 pointer " + styles$1["list__item__message"] + " " + styles$1["list__item__message--reply-from-right"] + " mb-0 fw-medium " + styles$1["reply-text"],
1692
+ onClick: function onClick() {
1693
+ return onGotoParentMessage === null || onGotoParentMessage === void 0 ? void 0 : onGotoParentMessage(parentId);
1694
+ }
1457
1695
  }, React.createElement("b", null, "Reply To:"), " ", parentContent), React.createElement("p", {
1458
1696
  className: "mb-0 py-2 px-3 fw-medium pointer " + styles$1["list__item__message"] + " " + (parentId ? styles$1["list__item__message--reply-right"] : "") + " text-end bg-primary text-white",
1459
1697
  onClick: handleShowInfo
1460
1698
  }, content), status !== MessageStatus.Default && React.createElement("p", {
1461
1699
  onClick: handleReTrySendMessage,
1462
1700
  className: "fs-6 mb-0 " + (status === MessageStatus.SentError ? "text-danger text-decoration-underline pointer" : "")
1463
- }, status), (type !== ChatItemType.Exam || !examCode) && status === MessageStatus.Default && React.createElement(Collapse, {
1701
+ }, status), !isSystemLog && status === MessageStatus.Default && React.createElement(Collapse, {
1464
1702
  isOpen: isShowInfo
1465
1703
  }, React.createElement("p", {
1466
1704
  className: "mb-0 py-1 px-3 fs-6 text-muted text-end"
@@ -1488,7 +1726,8 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
1488
1726
  onReply = _ref.onReply,
1489
1727
  selectedReplyMessageId = _ref.selectedReplyMessageId,
1490
1728
  onToggleReply = _ref.onToggleReply,
1491
- selectedReplyItemRef = _ref.selectedReplyItemRef;
1729
+ selectedReplyItemRef = _ref.selectedReplyItemRef,
1730
+ onGotoParentMessage = _ref.onGotoParentMessage;
1492
1731
  var _useState = useState(false),
1493
1732
  isShowTime = _useState[0],
1494
1733
  setShowTime = _useState[1];
@@ -1516,10 +1755,10 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
1516
1755
  }, React.createElement(Link, {
1517
1756
  to: "" + (actionLink || "/"),
1518
1757
  className: "text-black"
1519
- }, examTitle), !!examId && !!examTitle && React.createElement("span", {
1758
+ }, examTitle), !!examId && !!examTitle && !!examCode && React.createElement("span", {
1520
1759
  className: "pointer text-black",
1521
1760
  onClick: function onClick() {
1522
- return onAddExamMessage === null || onAddExamMessage === void 0 ? void 0 : onAddExamMessage(examId, examTitle);
1761
+ return onAddExamMessage === null || onAddExamMessage === void 0 ? void 0 : onAddExamMessage(examId, examTitle, examCode);
1523
1762
  }
1524
1763
  }, "Add message to exam")), isSystemLog || !!isFirst ? React.createElement("p", {
1525
1764
  className: "mb-0 py-1 px-3 fs-6 text-muted text-center"
@@ -1544,7 +1783,10 @@ var ChatLeftItem = function ChatLeftItem(_ref) {
1544
1783
  })), React.createElement("div", {
1545
1784
  className: "d-flex flex-column"
1546
1785
  }, parentId && React.createElement("p", {
1547
- className: "opacity-50 mb-0 py-2 px-3 fw-medium pointer " + styles$1["list__item__message"] + " " + styles$1["list__item__message--reply-from"] + " text-start bg-light"
1786
+ className: "opacity-50 mb-0 px-3 fw-medium pointer " + styles$1["list__item__message"] + " " + styles$1["list__item__message--reply-from"] + " " + styles$1["reply-text"] + " text-start bg-light",
1787
+ onClick: function onClick() {
1788
+ return onGotoParentMessage === null || onGotoParentMessage === void 0 ? void 0 : onGotoParentMessage(parentId);
1789
+ }
1548
1790
  }, React.createElement("b", null, "Reply To:"), " ", parentContent), React.createElement("p", {
1549
1791
  className: "mb-0 py-2 px-3 fw-medium pointer " + styles$1["list__item__message"] + " " + (parentId ? styles$1["list__item__message--reply"] : "") + " text-start bg-light",
1550
1792
  onClick: handleShowInfo
@@ -1585,6 +1827,11 @@ var ChatList = function ChatList(_ref) {
1585
1827
  var handleToggleReply = function handleToggleReply(id) {
1586
1828
  setSelectedReplyMessageId(id === selectedReplyMessageId ? undefined : id);
1587
1829
  };
1830
+ var handleSelectParentMessage = function handleSelectParentMessage(id) {
1831
+ if (id === selectedReplyMessageId) selectedReplyItemRef.current && selectedReplyItemRef.current.scrollIntoView({
1832
+ behavior: "smooth"
1833
+ });else setSelectedReplyMessageId(id);
1834
+ };
1588
1835
  useEffect(function () {
1589
1836
  selectedReplyMessageId && selectedReplyItemRef.current && selectedReplyItemRef.current.scrollIntoView({
1590
1837
  behavior: "smooth"
@@ -1607,7 +1854,8 @@ var ChatList = function ChatList(_ref) {
1607
1854
  selectedReplyMessageId: selectedReplyMessageId,
1608
1855
  onToggleReply: handleToggleReply,
1609
1856
  selectedReplyItemRef: selectedReplyItemRef,
1610
- onReTrySendMessage: onReTrySendMessage
1857
+ onReTrySendMessage: onReTrySendMessage,
1858
+ onGotoParentMessage: handleSelectParentMessage
1611
1859
  }));
1612
1860
  }));
1613
1861
  };
@@ -1672,6 +1920,7 @@ var ChatHeader = function ChatHeader(_ref) {
1672
1920
  var name = _ref.name,
1673
1921
  avatar = _ref.avatar,
1674
1922
  options = _ref.options,
1923
+ selectedOption = _ref.selectedOption,
1675
1924
  onChangeOption = _ref.onChangeOption;
1676
1925
  var wrapperRef = useRef(null);
1677
1926
  var actionRef = useRef(null);
@@ -1710,6 +1959,7 @@ var ChatHeader = function ChatHeader(_ref) {
1710
1959
  }, selectOptions !== undefined && React.createElement("div", {
1711
1960
  className: styles$1["header__select"] + " mx-3"
1712
1961
  }, React.createElement(CustomSelect, {
1962
+ value: selectedOption,
1713
1963
  options: selectOptions,
1714
1964
  onChange: handleChangeOption,
1715
1965
  isClearable: true
@@ -1722,7 +1972,15 @@ var ChatContainer = function ChatContainer(_ref) {
1722
1972
  var chatHeaderProps = _ref.chatHeaderProps,
1723
1973
  chatListProps = _ref.chatListProps,
1724
1974
  inputProps = _ref.inputProps,
1725
- onRead = _ref.onRead;
1975
+ _ref$scrollOffset = _ref.scrollOffset,
1976
+ scrollOffset = _ref$scrollOffset === void 0 ? 0 : _ref$scrollOffset,
1977
+ _ref$isLoading = _ref.isLoading,
1978
+ isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
1979
+ isScrollToEnd = _ref.isScrollToEnd,
1980
+ onRead = _ref.onRead,
1981
+ onReachTop = _ref.onReachTop,
1982
+ onReachBottom = _ref.onReachBottom,
1983
+ onEndScrollToEnd = _ref.onEndScrollToEnd;
1726
1984
  var onReply = chatListProps.onReply,
1727
1985
  onAddExamMessage = chatListProps.onAddExamMessage;
1728
1986
  var onChangeOption = chatHeaderProps.onChangeOption;
@@ -1737,10 +1995,10 @@ var ChatContainer = function ChatContainer(_ref) {
1737
1995
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
1738
1996
  onReply === null || onReply === void 0 ? void 0 : onReply(id, content, examId);
1739
1997
  };
1740
- var handleAddExamMessage = function handleAddExamMessage(examId, examTitle) {
1998
+ var handleAddExamMessage = function handleAddExamMessage(examId, examTitle, examCode) {
1741
1999
  var _inputRef$current2;
1742
2000
  (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
1743
- onAddExamMessage(examId, examTitle);
2001
+ onAddExamMessage(examId, examTitle, examCode);
1744
2002
  };
1745
2003
  var handleChangeExamOption = function handleChangeExamOption(val) {
1746
2004
  var _inputRef$current3;
@@ -1748,6 +2006,16 @@ var ChatContainer = function ChatContainer(_ref) {
1748
2006
  onChangeOption === null || onChangeOption === void 0 ? void 0 : onChangeOption(val);
1749
2007
  };
1750
2008
  var handleScroll = function handleScroll() {
2009
+ if (listRef.current) {
2010
+ var scrollTop = listRef.current.scrollTop;
2011
+ var scrollHeight = listRef.current.scrollHeight;
2012
+ var clientHeight = listRef.current.clientHeight;
2013
+ if (scrollTop + clientHeight + scrollOffset >= scrollHeight) {
2014
+ onReachBottom === null || onReachBottom === void 0 ? void 0 : onReachBottom();
2015
+ } else if (scrollTop <= scrollOffset) {
2016
+ onReachTop === null || onReachTop === void 0 ? void 0 : onReachTop();
2017
+ }
2018
+ }
1751
2019
  if (scrollRef.current) clearTimeout(scrollRef.current);
1752
2020
  scrollRef.current = setTimeout(function () {
1753
2021
  onRead === null || onRead === void 0 ? void 0 : onRead();
@@ -1757,36 +2025,40 @@ var ChatContainer = function ChatContainer(_ref) {
1757
2025
  if (focusRef.current) clearTimeout(focusRef.current);
1758
2026
  focusRef.current = setTimeout(function () {
1759
2027
  onRead === null || onRead === void 0 ? void 0 : onRead();
1760
- }, 800);
2028
+ }, 300);
1761
2029
  };
1762
2030
  useEffect(function () {
1763
- var _listRef$current, _listItemRef$current, _listItemRef$current$;
2031
+ var _listRef$current, _chatListProps$messag, _listRef$current3;
1764
2032
  scrollRef.current && clearTimeout(scrollRef.current);
1765
2033
  addEventTimeout.current && clearTimeout(addEventTimeout.current);
1766
2034
  (_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener("scroll", handleScroll);
1767
- (_listItemRef$current = listItemRef.current) === null || _listItemRef$current === void 0 ? void 0 : (_listItemRef$current$ = _listItemRef$current.lastElementChild) === null || _listItemRef$current$ === void 0 ? void 0 : _listItemRef$current$.scrollIntoView({
1768
- behavior: "smooth"
1769
- });
1770
- addEventTimeout.current = setTimeout(function () {
1771
- var _listRef$current2;
1772
- (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.addEventListener("scroll", handleScroll);
1773
- }, 800);
2035
+ if (isScrollToEnd && !isLoading && (_chatListProps$messag = chatListProps.messages) !== null && _chatListProps$messag !== void 0 && _chatListProps$messag.length) {
2036
+ var _listItemRef$current, _listItemRef$current$;
2037
+ (_listItemRef$current = listItemRef.current) === null || _listItemRef$current === void 0 ? void 0 : (_listItemRef$current$ = _listItemRef$current.lastElementChild) === null || _listItemRef$current$ === void 0 ? void 0 : _listItemRef$current$.scrollIntoView({
2038
+ behavior: "smooth"
2039
+ });
2040
+ onEndScrollToEnd === null || onEndScrollToEnd === void 0 ? void 0 : onEndScrollToEnd();
2041
+ addEventTimeout.current = setTimeout(function () {
2042
+ var _listRef$current2;
2043
+ (_listRef$current2 = listRef.current) === null || _listRef$current2 === void 0 ? void 0 : _listRef$current2.addEventListener("scroll", handleScroll);
2044
+ }, 800);
2045
+ } else (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.addEventListener("scroll", handleScroll);
1774
2046
  return function () {
1775
- var _listRef$current3;
1776
- (_listRef$current3 = listRef.current) === null || _listRef$current3 === void 0 ? void 0 : _listRef$current3.removeEventListener("scroll", handleScroll);
2047
+ var _listRef$current4;
2048
+ (_listRef$current4 = listRef.current) === null || _listRef$current4 === void 0 ? void 0 : _listRef$current4.removeEventListener("scroll", handleScroll);
1777
2049
  scrollRef.current && clearTimeout(scrollRef.current);
1778
2050
  addEventTimeout.current && clearTimeout(addEventTimeout.current);
1779
2051
  };
1780
- }, [listItemRef.current, JSON.stringify(chatListProps.messages)]);
2052
+ }, [JSON.stringify(chatListProps.messages), scrollOffset, isLoading, onEndScrollToEnd, onRead, isScrollToEnd]);
1781
2053
  useEffect(function () {
1782
2054
  var _inputRef$current4;
1783
2055
  (_inputRef$current4 = inputRef.current) === null || _inputRef$current4 === void 0 ? void 0 : _inputRef$current4.addEventListener("focus", handleFocus);
1784
2056
  return function () {
1785
2057
  var _inputRef$current5;
1786
2058
  (_inputRef$current5 = inputRef.current) === null || _inputRef$current5 === void 0 ? void 0 : _inputRef$current5.removeEventListener("focus", handleFocus);
1787
- if (focusRef.current) clearTimeout(focusRef.current);
2059
+ focusRef.current && clearTimeout(focusRef.current);
1788
2060
  };
1789
- }, []);
2061
+ }, [onRead]);
1790
2062
  return React.createElement("div", {
1791
2063
  className: "d-flex flex-column w-100 h-100 border border-1 border-light rounded-3 shadow-sm"
1792
2064
  }, React.createElement("div", null, React.createElement(ChatHeader, Object.assign({}, chatHeaderProps, {
@@ -1794,13 +2066,18 @@ var ChatContainer = function ChatContainer(_ref) {
1794
2066
  }))), React.createElement("div", {
1795
2067
  ref: listRef,
1796
2068
  className: "flex-grow-1 " + styles$1["body"]
1797
- }, React.createElement(ChatList, Object.assign({}, chatListProps, {
2069
+ }, isLoading && React.createElement("div", {
2070
+ className: "d-flex justify-content-center"
2071
+ }, React.createElement(Spinner, {
2072
+ color: "secondary",
2073
+ className: "my-2"
2074
+ }, "Loading...")), React.createElement(ChatList, Object.assign({}, chatListProps, {
1798
2075
  listItemRef: listItemRef,
1799
2076
  onReply: handleReply,
1800
2077
  onAddExamMessage: handleAddExamMessage
1801
2078
  }))), React.createElement("div", null, React.createElement(InputChat, Object.assign({}, inputProps, {
1802
2079
  inputRef: inputRef
1803
- }))), React.createElement(ToastContainer, null));
2080
+ }))));
1804
2081
  };
1805
2082
 
1806
2083
  var CONVERSATION_URL = BASE_URL + "/api/conversation";
@@ -1843,7 +2120,7 @@ var CONVERSATION_DEFAULT_FILTER = {
1843
2120
  };
1844
2121
  var MESSAGE_DEFAULT_FILTER = {
1845
2122
  currentPage: 1,
1846
- pageSize: -1,
2123
+ pageSize: 12,
1847
2124
  textSearch: "",
1848
2125
  sortColumnDirection: OrderBy.DESC,
1849
2126
  sortColumnName: MessageSortBy.CreatedAt
@@ -1903,43 +2180,69 @@ var useMessageList = function useMessageList(userId, getListExamOptions) {
1903
2180
  var _useState2 = useState(MESSAGE_DEFAULT_FILTER),
1904
2181
  messageFilter = _useState2[0],
1905
2182
  setMessageFilter = _useState2[1];
2183
+ var _useState3 = useState(false),
2184
+ isLoading = _useState3[0],
2185
+ setLoading = _useState3[1];
1906
2186
  var getMessageList = function getMessageList(conversationId, examId) {
1907
2187
  try {
1908
- var filter = _extends({}, messageFilter, {
1909
- examId: !examId ? messageFilter.examId : examId
1910
- });
1911
- return Promise.resolve(getMessagesByConversation(conversationId, filter)).then(function (res) {
1912
- var _res$data$items;
1913
- function _temp(_getListExamOptions) {
1914
- _getListExamOptions;
1915
- }
1916
- setMessages(((_res$data$items = res.data.items) === null || _res$data$items === void 0 ? void 0 : _res$data$items.reverse()) || []);
1917
- return getListExamOptions ? Promise.resolve(!!getListExamOptions && getListExamOptions(userId)).then(_temp) : _temp(!!getListExamOptions && getListExamOptions(userId));
2188
+ var _temp3 = function _temp3() {
2189
+ setLoading(false);
2190
+ };
2191
+ setLoading(true);
2192
+ var _temp2 = _catch(function () {
2193
+ var filter = _extends({}, messageFilter, {
2194
+ examId: !examId ? messageFilter.examId : examId
2195
+ });
2196
+ return Promise.resolve(getMessagesByConversation(conversationId, filter)).then(function (res) {
2197
+ var _res$data$items2;
2198
+ function _temp(_getListExamOptions) {
2199
+ _getListExamOptions;
2200
+ }
2201
+ if (messageFilter.beforeDate) setMessages(function (state) {
2202
+ var _res$data$items;
2203
+ return [].concat(((_res$data$items = res.data.items) === null || _res$data$items === void 0 ? void 0 : _res$data$items.reverse()) || [], state);
2204
+ });else setMessages((_res$data$items2 = res.data.items) === null || _res$data$items2 === void 0 ? void 0 : _res$data$items2.reverse());
2205
+ return getListExamOptions ? Promise.resolve(!!getListExamOptions && getListExamOptions(userId)).then(_temp) : _temp(!!getListExamOptions && getListExamOptions(userId));
2206
+ });
2207
+ }, function (error) {
2208
+ console.log({
2209
+ error: error
2210
+ });
1918
2211
  });
2212
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(_temp3) : _temp3(_temp2));
1919
2213
  } catch (e) {
1920
2214
  return Promise.reject(e);
1921
2215
  }
1922
2216
  };
2217
+ var handleLoadMore = function handleLoadMore() {
2218
+ if (isLoading) return;
2219
+ var lastItem = messages[0];
2220
+ if (!lastItem) return;
2221
+ var newFilter = _extends({}, messageFilter, {
2222
+ currentPage: 1,
2223
+ beforeDate: lastItem.createdAt
2224
+ });
2225
+ setMessageFilter(newFilter);
2226
+ return JSON.stringify(newFilter) === JSON.stringify(messageFilter);
2227
+ };
1923
2228
  var handleMarkReadMessage = function handleMarkReadMessage(conversationId, messageId) {
1924
2229
  try {
1925
- var _temp2 = _catch(function () {
2230
+ var _temp4 = _catch(function () {
1926
2231
  return Promise.resolve(apiMarkReadMessage(conversationId, messageId)).then(function () {});
1927
2232
  }, function (error) {
1928
2233
  console.log({
1929
2234
  error: error
1930
2235
  });
1931
2236
  });
1932
- return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
2237
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(function () {}) : void 0);
1933
2238
  } catch (e) {
1934
2239
  return Promise.reject(e);
1935
2240
  }
1936
2241
  };
1937
2242
  var resetMessages = function resetMessages() {
2243
+ setMessageFilter(MESSAGE_DEFAULT_FILTER);
1938
2244
  setMessages([]);
1939
2245
  };
1940
- var handleChangeMessageFilter = function handleChangeMessageFilter(filter) {
1941
- setMessageFilter(_extends({}, messageFilter, filter));
1942
- };
1943
2246
  var handleChangeExamId = function handleChangeExamId(value) {
1944
2247
  setMessageFilter(_extends({}, messageFilter, {
1945
2248
  examId: value === null || value === void 0 ? void 0 : value.value,
@@ -1947,14 +2250,15 @@ var useMessageList = function useMessageList(userId, getListExamOptions) {
1947
2250
  }));
1948
2251
  };
1949
2252
  return {
2253
+ isLoading: isLoading,
1950
2254
  messageFilter: messageFilter,
1951
2255
  messages: messages,
1952
2256
  getMessageList: getMessageList,
1953
2257
  setMessages: setMessages,
1954
2258
  resetMessages: resetMessages,
1955
- handleChangeMessageFilter: handleChangeMessageFilter,
1956
2259
  handleChangeExamId: handleChangeExamId,
1957
- handleMarkReadMessage: handleMarkReadMessage
2260
+ handleMarkReadMessage: handleMarkReadMessage,
2261
+ handleLoadMore: handleLoadMore
1958
2262
  };
1959
2263
  };
1960
2264
 
@@ -1970,6 +2274,7 @@ var useChatContainer = function useChatContainer(props) {
1970
2274
  var channel = useRef();
1971
2275
  var channelName = useRef();
1972
2276
  var loadingRef = useRef(false);
2277
+ var firstLoadRef = useRef(true);
1973
2278
  var dispatch = useDispatch();
1974
2279
  var roles = useSelector(function (state) {
1975
2280
  var _state$common, _state$common$user;
@@ -1985,16 +2290,26 @@ var useChatContainer = function useChatContainer(props) {
1985
2290
  var _useState3 = useState(MessageStatus.Default),
1986
2291
  messageStatus = _useState3[0],
1987
2292
  setMessageStatus = _useState3[1];
2293
+ var _useState4 = useState(true),
2294
+ isScrollToEnd = _useState4[0],
2295
+ setScrollToEnd = _useState4[1];
1988
2296
  var _useExamList = useExamList(isStudent),
1989
2297
  exams = _useExamList.exams,
1990
2298
  getListExam = _useExamList.getListExam;
1991
2299
  var _useMessageList = useMessageList(isStudent ? selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation = selectedConversation.teacher) === null || _selectedConversation === void 0 ? void 0 : _selectedConversation.id : selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation2 = selectedConversation.student) === null || _selectedConversation2 === void 0 ? void 0 : _selectedConversation2.id, !userId ? getListExam : undefined),
2300
+ isLoadingMessages = _useMessageList.isLoading,
1992
2301
  messages = _useMessageList.messages,
1993
2302
  messageFilter = _useMessageList.messageFilter,
1994
2303
  getMessageList = _useMessageList.getMessageList,
1995
2304
  resetMessages = _useMessageList.resetMessages,
1996
2305
  handleChangeExamId = _useMessageList.handleChangeExamId,
1997
- setMessages = _useMessageList.setMessages;
2306
+ setMessages = _useMessageList.setMessages,
2307
+ handleLoadMore = _useMessageList.handleLoadMore;
2308
+ var handleToggleScrollToEnd = function handleToggleScrollToEnd() {
2309
+ setScrollToEnd(function (state) {
2310
+ return !state;
2311
+ });
2312
+ };
1998
2313
  var handleAddMessage = function handleAddMessage() {
1999
2314
  try {
2000
2315
  var _message$content, _message$content$trim;
@@ -2007,6 +2322,7 @@ var useChatContainer = function useChatContainer(props) {
2007
2322
  })) return Promise.resolve();
2008
2323
  loadingRef.current = true;
2009
2324
  if (!(selectedConversation !== null && selectedConversation !== void 0 && selectedConversation.id) || !(message !== null && message !== void 0 && (_message$content = message.content) !== null && _message$content !== void 0 && (_message$content$trim = _message$content.trim()) !== null && _message$content$trim !== void 0 && _message$content$trim.length)) return Promise.resolve();
2325
+ setScrollToEnd(true);
2010
2326
  setMessages(function (state) {
2011
2327
  return [].concat(state, [{
2012
2328
  id: 0,
@@ -2019,7 +2335,7 @@ var useChatContainer = function useChatContainer(props) {
2019
2335
  id: message.examId,
2020
2336
  startTime: moment().format("YYYY-MM-DDTHH:mm:ss"),
2021
2337
  title: message.examTitle || "",
2022
- code: "temp",
2338
+ code: message.examCode || "",
2023
2339
  createdAt: moment().format("YYYY-MM-DDTHH:mm:ss")
2024
2340
  } : undefined,
2025
2341
  isRead: false,
@@ -2059,14 +2375,16 @@ var useChatContainer = function useChatContainer(props) {
2059
2375
  return Promise.reject(e);
2060
2376
  }
2061
2377
  };
2062
- var handleAddExamMessage = function handleAddExamMessage(examId, title) {
2378
+ var handleAddExamMessage = function handleAddExamMessage(examId, title, examCode) {
2063
2379
  setMessage(!!message ? _extends({}, message, {
2064
2380
  examId: examId,
2381
+ examCode: examCode,
2065
2382
  examTitle: title,
2066
2383
  parentId: undefined,
2067
2384
  parentContent: ""
2068
2385
  }) : {
2069
2386
  examId: examId,
2387
+ examCode: examCode,
2070
2388
  content: "",
2071
2389
  examTitle: title,
2072
2390
  parentId: undefined,
@@ -2158,7 +2476,8 @@ var useChatContainer = function useChatContainer(props) {
2158
2476
  return results;
2159
2477
  }, [JSON.stringify(messages), JSON.stringify(message), isStudent, JSON.stringify(selectedConversation), messageFilter.examId, isStudent, userId, messageStatus]);
2160
2478
  var handleNewMessageSent = function handleNewMessageSent(data) {
2161
- if (!messageFilter.examId || messageFilter.examId && data.examId === messageFilter.examId) {
2479
+ if (!messageFilter.examId && !examId || messageFilter.examId && data.examId === messageFilter.examId || examId && examId === data.examId) {
2480
+ setScrollToEnd(true);
2162
2481
  setMessages(function (state) {
2163
2482
  if (state.some(function (i) {
2164
2483
  return i.id === 0;
@@ -2178,6 +2497,11 @@ var useChatContainer = function useChatContainer(props) {
2178
2497
  }));
2179
2498
  });
2180
2499
  };
2500
+ var handleLoadMoreMessages = function handleLoadMoreMessages() {
2501
+ if (handleLoadMore()) {
2502
+ getMessageConversation();
2503
+ }
2504
+ };
2181
2505
  var cleanupPusher = function cleanupPusher() {
2182
2506
  var _pusher$current, _pusher$current2;
2183
2507
  (_pusher$current = pusher.current) === null || _pusher$current === void 0 ? void 0 : _pusher$current.unbind("new-message-event", handleNewMessageSent);
@@ -2203,13 +2527,15 @@ var useChatContainer = function useChatContainer(props) {
2203
2527
  pusher.current.bind("message-read-event", handleMessageMarkRead);
2204
2528
  }
2205
2529
  return cleanupPusher;
2206
- }, [selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id, messageFilter.examId]);
2530
+ }, [selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id, messageFilter.examId, examId]);
2207
2531
  useEffect(function () {
2208
2532
  var getConversation = function getConversation() {
2209
2533
  try {
2210
2534
  var _temp6 = function _temp6() {
2211
2535
  dispatch(setLoading(false));
2212
2536
  };
2537
+ resetMessages();
2538
+ setScrollToEnd(true);
2213
2539
  if ((conversation === null || conversation === void 0 ? void 0 : conversation.id) !== undefined) {
2214
2540
  setSelectedConversation(conversation);
2215
2541
  return Promise.resolve();
@@ -2242,7 +2568,7 @@ var useChatContainer = function useChatContainer(props) {
2242
2568
  };
2243
2569
  getConversation();
2244
2570
  }, [conversation === null || conversation === void 0 ? void 0 : conversation.id, userId]);
2245
- var handleMarkRead = function handleMarkRead() {
2571
+ var handleMarkRead = useCallback(function () {
2246
2572
  try {
2247
2573
  if (!(selectedConversation !== null && selectedConversation !== void 0 && selectedConversation.id)) return Promise.resolve();
2248
2574
  var _temp7 = _catch(function () {
@@ -2256,17 +2582,12 @@ var useChatContainer = function useChatContainer(props) {
2256
2582
  } catch (e) {
2257
2583
  return Promise.reject(e);
2258
2584
  }
2259
- };
2585
+ }, [selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id]);
2260
2586
  var getMessageConversation = function getMessageConversation() {
2261
2587
  try {
2262
- var _temp12 = function _temp12() {
2263
- dispatch(setLoading(false));
2264
- };
2265
2588
  if (!roles.length) return Promise.resolve();
2266
2589
  if ((selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id) === undefined) return Promise.resolve();
2267
- if (messageFilter.currentPage === 1) resetMessages();
2268
- dispatch(setLoading(true));
2269
- var _temp11 = _catch(function () {
2590
+ return Promise.resolve(_catch(function () {
2270
2591
  var _temp10 = function () {
2271
2592
  if (selectedConversation.id === 0) {
2272
2593
  var _userId = isStudent ? selectedConversation.teacher.id : selectedConversation.student.id;
@@ -2281,7 +2602,11 @@ var useChatContainer = function useChatContainer(props) {
2281
2602
  });
2282
2603
  };
2283
2604
  var _temp8 = function () {
2284
- if (messageFilter.currentPage === 1) return Promise.resolve(handleMarkRead()).then(function () {});
2605
+ if (firstLoadRef.current) {
2606
+ return Promise.resolve(handleMarkRead()).then(function () {
2607
+ firstLoadRef.current = false;
2608
+ });
2609
+ }
2285
2610
  }();
2286
2611
  return _temp8 && _temp8.then ? _temp8.then(_temp9) : _temp9(_temp8);
2287
2612
  }
@@ -2289,22 +2614,26 @@ var useChatContainer = function useChatContainer(props) {
2289
2614
  if (_temp10 && _temp10.then) return _temp10.then(function () {});
2290
2615
  }, function () {
2291
2616
  toast.error("Fail to fetch data!");
2292
- });
2293
- return Promise.resolve(_temp11 && _temp11.then ? _temp11.then(_temp12) : _temp12(_temp11));
2617
+ }));
2294
2618
  } catch (e) {
2295
2619
  return Promise.reject(e);
2296
2620
  }
2297
2621
  };
2622
+ var handleConversationChange = function handleConversationChange() {
2623
+ resetMessages();
2624
+ setScrollToEnd(true);
2625
+ };
2298
2626
  useEffect(function () {
2299
2627
  getMessageConversation();
2300
- }, [selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.id, selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.teacher.id, selectedConversation === null || selectedConversation === void 0 ? void 0 : selectedConversation.student.id, isStudent, roles.length, JSON.stringify(messageFilter), examId]);
2301
- var userName = isStudent ? selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation3 = selectedConversation.teacher) === null || _selectedConversation3 === void 0 ? void 0 : _selectedConversation3.displayName : selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation4 = selectedConversation.student) === null || _selectedConversation4 === void 0 ? void 0 : _selectedConversation4.displayName;
2302
- var userAvatar = isStudent ? selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation5 = selectedConversation.teacher) === null || _selectedConversation5 === void 0 ? void 0 : _selectedConversation5.avatar : selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation6 = selectedConversation.student) === null || _selectedConversation6 === void 0 ? void 0 : _selectedConversation6.avatar;
2628
+ }, [JSON.stringify(selectedConversation), JSON.stringify(roles), JSON.stringify(messageFilter), examId]);
2629
+ var userName = (isStudent ? selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation3 = selectedConversation.teacher) === null || _selectedConversation3 === void 0 ? void 0 : _selectedConversation3.displayName : selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation4 = selectedConversation.student) === null || _selectedConversation4 === void 0 ? void 0 : _selectedConversation4.displayName) || "";
2630
+ var userAvatar = (isStudent ? selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation5 = selectedConversation.teacher) === null || _selectedConversation5 === void 0 ? void 0 : _selectedConversation5.avatar : selectedConversation === null || selectedConversation === void 0 ? void 0 : (_selectedConversation6 = selectedConversation.student) === null || _selectedConversation6 === void 0 ? void 0 : _selectedConversation6.avatar) || "";
2303
2631
  return {
2304
2632
  chatHeaderProps: {
2305
- name: userName || "",
2306
- avatar: userAvatar || "",
2633
+ name: userName,
2634
+ avatar: userAvatar,
2307
2635
  options: exams,
2636
+ selectedOption: messageFilter.examId,
2308
2637
  onChangeOption: handleFilterExam
2309
2638
  },
2310
2639
  chatListProps: {
@@ -2321,15 +2650,19 @@ var useChatContainer = function useChatContainer(props) {
2321
2650
  onSubmit: handleAddMessage,
2322
2651
  onClearReply: !messageFilter.examId || message !== null && message !== void 0 && message.parentContent ? handleClearReply : undefined
2323
2652
  },
2653
+ isScrollToEnd: isScrollToEnd,
2654
+ isLoadingMessages: isLoadingMessages,
2324
2655
  exams: exams,
2325
2656
  messageList: messageList,
2326
2657
  selectedConversation: selectedConversation,
2327
2658
  messageStatus: messageStatus,
2328
2659
  messageFilter: messageFilter,
2660
+ handleToggleScrollToEnd: handleToggleScrollToEnd,
2661
+ handleLoadMoreMessages: handleLoadMoreMessages,
2329
2662
  getMessageList: getMessageList,
2330
2663
  handleFilterExam: handleFilterExam,
2331
2664
  setMessage: setMessage,
2332
- resetMessages: resetMessages,
2665
+ resetMessages: handleConversationChange,
2333
2666
  getMessageConversation: getMessageConversation,
2334
2667
  handleMarkRead: handleMarkRead
2335
2668
  };
@@ -2369,8 +2702,8 @@ var useConversationList = function useConversationList() {
2369
2702
  return i.id === val.id;
2370
2703
  });
2371
2704
  if (index > -1 && JSON.stringify(val) !== JSON.stringify(state[index])) {
2372
- return [].concat(state.slice(0, index), [val], state.slice(index + 1));
2373
- } else return [].concat(state, [val]);
2705
+ return [val].concat(state.slice(0, index), state.slice(index + 1));
2706
+ } else return [val].concat(state);
2374
2707
  });
2375
2708
  setSelectedConversation(function (state) {
2376
2709
  if (!state) return val;
@@ -2466,9 +2799,12 @@ var useConversationList = function useConversationList() {
2466
2799
  return i.id === lastMessage.conversationId;
2467
2800
  });
2468
2801
  if (updateIndex < 0) return state;
2469
- return [].concat(state.slice(0, updateIndex), [_extends({}, state[updateIndex], {
2802
+ console.log({
2470
2803
  lastMessage: lastMessage
2471
- })], state.slice(updateIndex + 1));
2804
+ });
2805
+ return [_extends({}, state[updateIndex], {
2806
+ lastMessage: lastMessage
2807
+ })].concat(state.slice(0, updateIndex), state.slice(updateIndex + 1));
2472
2808
  });
2473
2809
  };
2474
2810
  var handleCreateConversationSuccess = function handleCreateConversationSuccess(id) {
@@ -2557,7 +2893,536 @@ var usePusherConversation = function usePusherConversation(onNewMessageConversat
2557
2893
  return {};
2558
2894
  };
2559
2895
 
2896
+ var _excluded$1 = ["defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
2897
+ var CustomCreatable = function CustomCreatable(_ref) {
2898
+ var options = _ref.options,
2899
+ isDisabled = _ref.isDisabled,
2900
+ scrollBottom = _ref.scrollBottom,
2901
+ value = _ref.value,
2902
+ isMulti = _ref.isMulti,
2903
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$1);
2904
+ var initialValues = Array.isArray(value) ? options.filter(function (i) {
2905
+ return value.includes(i.value);
2906
+ }) : isMulti ? options.filter(function (i) {
2907
+ return i.value == value;
2908
+ }) : options.find(function (i) {
2909
+ return i.value == value;
2910
+ });
2911
+ return React.createElement(CreatableSelect, Object.assign({
2912
+ isClearable: true,
2913
+ isDisabled: isDisabled,
2914
+ options: options,
2915
+ value: initialValues,
2916
+ menuPlacement: scrollBottom ? "top" : "auto",
2917
+ isMulti: isMulti
2918
+ }, rest));
2919
+ };
2920
+
2921
+ var _excluded$2 = ["isDefault", "defaultValue", "options", "isDisabled", "scrollBottom", "value", "isMulti"];
2922
+ var CustomAsyncSelect = function CustomAsyncSelect(_ref) {
2923
+ var isDefault = _ref.isDefault,
2924
+ options = _ref.options,
2925
+ isDisabled = _ref.isDisabled,
2926
+ scrollBottom = _ref.scrollBottom,
2927
+ value = _ref.value,
2928
+ isMulti = _ref.isMulti,
2929
+ rest = _objectWithoutPropertiesLoose(_ref, _excluded$2);
2930
+ var initialValues = Array.isArray(value) ? options.filter(function (i) {
2931
+ return value.includes(i.value);
2932
+ }) : isMulti ? options.filter(function (i) {
2933
+ return i.value == value;
2934
+ }) : options.find(function (i) {
2935
+ return i.value == value;
2936
+ });
2937
+ return React.createElement(Select, Object.assign({
2938
+ isDisabled: isDisabled,
2939
+ options: options,
2940
+ value: !isDefault ? initialValues : undefined,
2941
+ defaultValue: isDefault ? initialValues : undefined,
2942
+ menuPlacement: scrollBottom ? "top" : "auto",
2943
+ isMulti: isMulti
2944
+ }, rest));
2945
+ };
2946
+
2947
+ var styles$2 = {"question":"_2uc_W","question-article":"_2p7kY","question-title":"_2tHmc","question--active":"_3IHYm","question-label":"_26ATj","question-input":"_3R8PR","question-btn":"_1VZac"};
2948
+
2949
+ var DURATION_OPTIONS = Array.from({
2950
+ length: 120
2951
+ }, function (_, i) {
2952
+ return i + 1;
2953
+ });
2954
+ var SCORE_OPTIONS = Array.from({
2955
+ length: 10
2956
+ }, function (_, i) {
2957
+ return i + 1;
2958
+ });
2959
+ var QUESTION_OPTIONS = Array.from({
2960
+ length: 40
2961
+ }, function (_, i) {
2962
+ return i + 1;
2963
+ });
2964
+ var ANSWER_OPTIONS = Array.from({
2965
+ length: 9
2966
+ }, function (_, i) {
2967
+ return i + 2;
2968
+ });
2969
+ var DEFAULT_SCORE = 2;
2970
+ var DEFAULT_ANSWER_COUNT = 5;
2971
+
2972
+ var QuestionView = function QuestionView(_ref) {
2973
+ var index = _ref.index,
2974
+ question = _ref.question,
2975
+ answerCount = _ref.answerCount,
2976
+ isDisabled = _ref.isDisabled,
2977
+ onChangeCorrectAnswers = _ref.onChangeCorrectAnswers,
2978
+ onChangeScoreAnswer = _ref.onChangeScoreAnswer;
2979
+ var scoreOptions = SCORE_OPTIONS.map(function (i) {
2980
+ return {
2981
+ label: DEFAULT_SCORE === i ? i + "\uC810 (\uAE30\uBCF8\uAC12)" : i + "\uC810",
2982
+ value: i
2983
+ };
2984
+ });
2985
+ return React.createElement("div", {
2986
+ className: "d-flex justify-content-between"
2987
+ }, React.createElement("div", {
2988
+ className: "d-flex flex-grow-1"
2989
+ }, React.createElement("div", {
2990
+ className: styles$2["question-title"] + " me-2"
2991
+ }, "\uBB38\uC81C ", question.questionOrder + 1, "\uBC88"), React.createElement("div", {
2992
+ className: "d-flex flex-grow-1"
2993
+ }, Array.from({
2994
+ length: answerCount
2995
+ }, function (_, i) {
2996
+ return i + 1;
2997
+ }).map(function (i) {
2998
+ return React.createElement(FormGroup, {
2999
+ className: "d-flex flex-column px-4"
3000
+ }, React.createElement(Label, {
3001
+ htmlFor: "answer-" + i,
3002
+ className: "" + styles$2["question-label"]
3003
+ }, i, "\uBC88"), React.createElement(Input, {
3004
+ id: "answer-" + i,
3005
+ type: "radio",
3006
+ checked: question.correctAnswers.includes(i),
3007
+ onClick: function onClick() {
3008
+ return onChangeCorrectAnswers(i, index);
3009
+ },
3010
+ disabled: isDisabled
3011
+ }));
3012
+ }))), React.createElement("div", {
3013
+ className: "d-flex align-items-center"
3014
+ }, React.createElement(FormGroup, {
3015
+ className: "mx-3",
3016
+ style: {
3017
+ width: "140px"
3018
+ }
3019
+ }, React.createElement(CustomSelect, {
3020
+ value: question.score,
3021
+ options: scoreOptions,
3022
+ onChange: function onChange(value) {
3023
+ return onChangeScoreAnswer(value.value, index);
3024
+ },
3025
+ isDisabled: isDisabled
3026
+ }))));
3027
+ };
3028
+
3029
+ var ArticleGroupView = function ArticleGroupView(_ref) {
3030
+ var categoryOptions = _ref.categoryOptions,
3031
+ article = _ref.article,
3032
+ questions = _ref.questions,
3033
+ answerCount = _ref.answerCount,
3034
+ questionCount = _ref.questionCount,
3035
+ categoryId = _ref.categoryId,
3036
+ isActive = _ref.isActive,
3037
+ isDisabled = _ref.isDisabled,
3038
+ onChangeQuestionCount = _ref.onChangeQuestionCount,
3039
+ onChangeCategory = _ref.onChangeCategory,
3040
+ onChangeAnswerCount = _ref.onChangeAnswerCount,
3041
+ onChangeCorrectAnswers = _ref.onChangeCorrectAnswers,
3042
+ onChangeScoreAnswer = _ref.onChangeScoreAnswer;
3043
+ var _useTranslation = useTranslation(),
3044
+ t = _useTranslation.t;
3045
+ var handleChangeQuestionCount = function handleChangeQuestionCount(value) {
3046
+ onChangeQuestionCount(article, value === null || value === void 0 ? void 0 : value.value, answerCount);
3047
+ };
3048
+ var handleChangeCategory = function handleChangeCategory(value) {
3049
+ onChangeCategory(article, value === null || value === void 0 ? void 0 : value.value);
3050
+ };
3051
+ var handleChangeAnswerCount = function handleChangeAnswerCount(value) {
3052
+ onChangeAnswerCount(article, value === null || value === void 0 ? void 0 : value.value, answerCount);
3053
+ };
3054
+ var handleChangeCorrectAnswers = function handleChangeCorrectAnswers(value, index) {
3055
+ onChangeCorrectAnswers(article, index, value);
3056
+ };
3057
+ var handleChangeScoreAnswer = function handleChangeScoreAnswer(value, index) {
3058
+ onChangeScoreAnswer(article, index, value);
3059
+ };
3060
+ var questionOptions = QUESTION_OPTIONS.map(function (i) {
3061
+ return {
3062
+ label: i + "\uAC1C",
3063
+ value: i
3064
+ };
3065
+ });
3066
+ var answerOptions = ANSWER_OPTIONS.map(function (i) {
3067
+ return {
3068
+ label: i + "\uBC88",
3069
+ value: i
3070
+ };
3071
+ });
3072
+ return React.createElement("div", {
3073
+ className: "d-flex " + styles$2["question"] + " " + (isActive ? styles$2["question--active"] : "")
3074
+ }, React.createElement("div", {
3075
+ className: "py-1"
3076
+ }, React.createElement(PiDotsNineLight, {
3077
+ size: 18
3078
+ })), React.createElement("div", {
3079
+ className: "px-4"
3080
+ }, React.createElement(Row, null, React.createElement(Col, {
3081
+ xs: 12
3082
+ }, React.createElement("p", {
3083
+ className: "mb-0 " + styles$2["question-article"]
3084
+ }, "\uBB38\uD56D"), React.createElement("p", {
3085
+ className: "text-center " + styles$2["question-article"]
3086
+ }, article)))), React.createElement("div", {
3087
+ className: "flex-grow-1"
3088
+ }, React.createElement(Row, null, React.createElement(Col, {
3089
+ xs: 3
3090
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3091
+ htmlFor: "question_count",
3092
+ className: "" + styles$2["question-label"]
3093
+ }, t("question_count")), React.createElement(CustomSelect, {
3094
+ inputId: "question_count",
3095
+ value: questionCount,
3096
+ options: questionOptions,
3097
+ onChange: handleChangeQuestionCount,
3098
+ isDisabled: isDisabled
3099
+ }))), React.createElement(Col, {
3100
+ xs: 3
3101
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3102
+ htmlFor: "category",
3103
+ className: "" + styles$2["question-label"]
3104
+ }, t("category")), React.createElement(CustomSelect, {
3105
+ inputId: "category",
3106
+ value: categoryId,
3107
+ options: categoryOptions,
3108
+ onChange: handleChangeCategory,
3109
+ isDisabled: isDisabled
3110
+ }))), React.createElement(Col, {
3111
+ xs: 3
3112
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3113
+ htmlFor: "answer_count",
3114
+ className: "" + styles$2["question-label"]
3115
+ }, t("answer_count")), React.createElement(CustomSelect, {
3116
+ inputId: "answer_count",
3117
+ value: answerCount,
3118
+ options: answerOptions,
3119
+ onChange: handleChangeAnswerCount,
3120
+ isDisabled: isDisabled
3121
+ }))), React.createElement(Col, {
3122
+ xs: 3
3123
+ })), React.createElement("div", null, questions.map(function (q, index) {
3124
+ return React.createElement(QuestionView, {
3125
+ key: index,
3126
+ question: q,
3127
+ answerCount: answerCount,
3128
+ index: index,
3129
+ onChangeCorrectAnswers: handleChangeCorrectAnswers,
3130
+ onChangeScoreAnswer: handleChangeScoreAnswer,
3131
+ isDisabled: isDisabled
3132
+ });
3133
+ }))));
3134
+ };
3135
+
3136
+ var useExamDetailView = function useExamDetailView(props) {
3137
+ var exam = props.exam,
3138
+ onChangeExam = props.onChangeExam;
3139
+ var _useTranslation = useTranslation(),
3140
+ t = _useTranslation.t;
3141
+ var handleChangeQuestionCount = function handleChangeQuestionCount(article, questionCount, answerCount) {
3142
+ if (!exam) return;
3143
+ var examQuestions = exam.questions;
3144
+ var questions = examQuestions.filter(function (i) {
3145
+ return i.article === +article;
3146
+ });
3147
+ var prevQuestions = examQuestions.filter(function (i) {
3148
+ return i.article < +article;
3149
+ });
3150
+ var nextQuestions = examQuestions.filter(function (i) {
3151
+ return i.article > +article;
3152
+ });
3153
+ var lastOrder = questions[questions.length - 1].questionOrder;
3154
+ if (questions.length === questionCount) return;
3155
+ if (questions.length < questionCount) {
3156
+ var additionalQuestions = Array.from({
3157
+ length: questionCount - questions.length
3158
+ }).map(function (_, index) {
3159
+ var _questions$;
3160
+ return {
3161
+ article: +article,
3162
+ correctAnswers: [1],
3163
+ numberOfAnswers: answerCount,
3164
+ categoryId: (_questions$ = questions[0]) === null || _questions$ === void 0 ? void 0 : _questions$.categoryId,
3165
+ score: DEFAULT_SCORE,
3166
+ questionOrder: lastOrder + index + 1
3167
+ };
3168
+ });
3169
+ var newQuestions = [].concat(prevQuestions, questions, additionalQuestions, nextQuestions.map(function (i) {
3170
+ return _extends({}, i, {
3171
+ questionOrder: i.questionOrder + questionCount - questions.length
3172
+ });
3173
+ }));
3174
+ onChangeExam(_extends({}, exam, {
3175
+ questions: [].concat(newQuestions)
3176
+ }));
3177
+ } else {
3178
+ var remainQuestions = questions.slice(0, questionCount);
3179
+ var _newQuestions = [].concat(prevQuestions, remainQuestions, nextQuestions.map(function (i) {
3180
+ return _extends({}, i, {
3181
+ questionOrder: i.questionOrder - questions.length + questionCount
3182
+ });
3183
+ }));
3184
+ onChangeExam(_extends({}, exam, {
3185
+ questions: [].concat(_newQuestions)
3186
+ }));
3187
+ }
3188
+ };
3189
+ var handleChangeCategory = function handleChangeCategory(article, categoryId) {
3190
+ if (!exam) return;
3191
+ var examQuestions = exam.questions;
3192
+ var questions = examQuestions.filter(function (i) {
3193
+ return i.article === +article;
3194
+ });
3195
+ var otherQuestions = examQuestions.filter(function (i) {
3196
+ return i.article !== +article;
3197
+ });
3198
+ onChangeExam(_extends({}, exam, {
3199
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3200
+ return _extends({}, q, {
3201
+ categoryId: categoryId
3202
+ });
3203
+ }))
3204
+ }));
3205
+ };
3206
+ var handleChangeAnswerCount = function handleChangeAnswerCount(article, newAnswerCount, answerCount) {
3207
+ if (!exam) return;
3208
+ if (newAnswerCount === answerCount) return;
3209
+ var examQuestions = exam.questions;
3210
+ var questions = examQuestions.filter(function (i) {
3211
+ return i.article === +article;
3212
+ });
3213
+ var otherQuestions = examQuestions.filter(function (i) {
3214
+ return i.article !== +article;
3215
+ });
3216
+ if (answerCount < newAnswerCount) {
3217
+ onChangeExam(_extends({}, exam, {
3218
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3219
+ return _extends({}, q, {
3220
+ numberOfAnswers: newAnswerCount
3221
+ });
3222
+ }))
3223
+ }));
3224
+ } else {
3225
+ onChangeExam(_extends({}, exam, {
3226
+ questions: [].concat(otherQuestions, questions.map(function (q) {
3227
+ return _extends({}, q, {
3228
+ numberOfAnswers: newAnswerCount,
3229
+ correctAnswers: q.correctAnswers.filter(function (i) {
3230
+ return i <= newAnswerCount;
3231
+ })
3232
+ });
3233
+ }))
3234
+ }));
3235
+ }
3236
+ };
3237
+ var handleChangeCorrectAnswers = function handleChangeCorrectAnswers(article, index, answer) {
3238
+ if (!exam) return;
3239
+ var examQuestions = exam.questions;
3240
+ var questions = examQuestions.filter(function (i) {
3241
+ return i.article === +article;
3242
+ });
3243
+ var otherQuestions = examQuestions.filter(function (i) {
3244
+ return i.article !== +article;
3245
+ });
3246
+ var selectedQuestion = questions[index];
3247
+ onChangeExam(_extends({}, exam, {
3248
+ questions: [].concat(otherQuestions, questions.slice(0, index), [_extends({}, selectedQuestion, {
3249
+ correctAnswers: [answer]
3250
+ })], questions.slice(index + 1))
3251
+ }));
3252
+ };
3253
+ var handleChangeScoreAnswer = function handleChangeScoreAnswer(article, index, score) {
3254
+ if (!exam) return;
3255
+ var examQuestions = exam.questions;
3256
+ var questions = examQuestions.filter(function (i) {
3257
+ return i.article === +article;
3258
+ });
3259
+ var otherQuestions = examQuestions.filter(function (i) {
3260
+ return i.article !== +article;
3261
+ });
3262
+ var selectedQuestion = questions[index];
3263
+ if (score === selectedQuestion.score) return;
3264
+ onChangeExam(_extends({}, exam, {
3265
+ questions: [].concat(otherQuestions, questions.slice(0, index), [_extends({}, selectedQuestion, {
3266
+ score: score
3267
+ })], questions.slice(index + 1))
3268
+ }));
3269
+ };
3270
+ var handleChangeDuration = function handleChangeDuration(value) {
3271
+ if (!exam) return;
3272
+ onChangeExam(_extends({}, exam, {
3273
+ duration: value === null || value === void 0 ? void 0 : value.value
3274
+ }));
3275
+ };
3276
+ var handleChangeTitle = function handleChangeTitle(e) {
3277
+ if (!exam) return;
3278
+ onChangeExam(_extends({}, exam, {
3279
+ title: e.target.value
3280
+ }));
3281
+ };
3282
+ var handleAddArticle = function handleAddArticle() {
3283
+ var _$maxBy, _$maxBy2;
3284
+ if (!exam) return;
3285
+ var maxArticle = ((_$maxBy = _.maxBy(exam.questions, "article")) === null || _$maxBy === void 0 ? void 0 : _$maxBy.article) || 0;
3286
+ var maxOrder = ((_$maxBy2 = _.maxBy(exam.questions, "questionOrder")) === null || _$maxBy2 === void 0 ? void 0 : _$maxBy2.questionOrder) || 0;
3287
+ onChangeExam(_extends({}, exam, {
3288
+ questions: [].concat(exam.questions, [{
3289
+ article: maxArticle + 1,
3290
+ correctAnswers: [1],
3291
+ numberOfAnswers: DEFAULT_ANSWER_COUNT,
3292
+ score: DEFAULT_SCORE,
3293
+ questionOrder: maxOrder + 1
3294
+ }])
3295
+ }));
3296
+ };
3297
+ var examGroupByArticle = useMemo(function () {
3298
+ if (!exam) return [];
3299
+ var articles = [];
3300
+ var groupedArticle = _.groupBy(exam.questions, "article");
3301
+ for (var key in groupedArticle) {
3302
+ if (Object.prototype.hasOwnProperty.call(groupedArticle, key)) {
3303
+ var _questions$find, _$maxBy3;
3304
+ var questions = groupedArticle[key];
3305
+ articles.push({
3306
+ article: +key,
3307
+ categoryId: (_questions$find = questions.find(function (i) {
3308
+ return !!i.categoryId;
3309
+ })) === null || _questions$find === void 0 ? void 0 : _questions$find.categoryId,
3310
+ answerCount: ((_$maxBy3 = _.maxBy(questions, "numberOfAnswers")) === null || _$maxBy3 === void 0 ? void 0 : _$maxBy3.numberOfAnswers) || DEFAULT_ANSWER_COUNT,
3311
+ questionCount: questions.length,
3312
+ questions: questions
3313
+ });
3314
+ }
3315
+ }
3316
+ return _.sortBy(articles, "article");
3317
+ }, [JSON.stringify(exam)]);
3318
+ var durationOptions = useMemo(function () {
3319
+ var options = DURATION_OPTIONS.map(function (i) {
3320
+ return {
3321
+ label: i + "\uBD84",
3322
+ value: i
3323
+ };
3324
+ });
3325
+ if (!!exam.duration && exam.duration > DURATION_OPTIONS[DURATION_OPTIONS.length - 1]) return [].concat(options, [{
3326
+ label: exam.duration + "\uBD84",
3327
+ value: exam.duration
3328
+ }]);
3329
+ return options;
3330
+ }, [exam.duration]);
3331
+ return {
3332
+ t: t,
3333
+ durationOptions: durationOptions,
3334
+ examGroupByArticle: examGroupByArticle,
3335
+ handleAddArticle: handleAddArticle,
3336
+ handleChangeScoreAnswer: handleChangeScoreAnswer,
3337
+ handleChangeTitle: handleChangeTitle,
3338
+ handleChangeDuration: handleChangeDuration,
3339
+ handleChangeCorrectAnswers: handleChangeCorrectAnswers,
3340
+ handleChangeAnswerCount: handleChangeAnswerCount,
3341
+ handleChangeQuestionCount: handleChangeQuestionCount,
3342
+ handleChangeCategory: handleChangeCategory
3343
+ };
3344
+ };
3345
+
3346
+ var ExamDetailView = function ExamDetailView(_ref) {
3347
+ var _ref$className = _ref.className,
3348
+ className = _ref$className === void 0 ? "" : _ref$className,
3349
+ categoryOptions = _ref.categoryOptions,
3350
+ exam = _ref.exam,
3351
+ _ref$isUsingMui = _ref.isUsingMui,
3352
+ isUsingMui = _ref$isUsingMui === void 0 ? true : _ref$isUsingMui,
3353
+ isDisabled = _ref.isDisabled,
3354
+ onChangeExam = _ref.onChangeExam;
3355
+ var _useExamDetailView = useExamDetailView({
3356
+ exam: exam,
3357
+ onChangeExam: onChangeExam
3358
+ }),
3359
+ t = _useExamDetailView.t,
3360
+ durationOptions = _useExamDetailView.durationOptions,
3361
+ examGroupByArticle = _useExamDetailView.examGroupByArticle,
3362
+ handleAddArticle = _useExamDetailView.handleAddArticle,
3363
+ handleChangeScoreAnswer = _useExamDetailView.handleChangeScoreAnswer,
3364
+ handleChangeTitle = _useExamDetailView.handleChangeTitle,
3365
+ handleChangeDuration = _useExamDetailView.handleChangeDuration,
3366
+ handleChangeCorrectAnswers = _useExamDetailView.handleChangeCorrectAnswers,
3367
+ handleChangeAnswerCount = _useExamDetailView.handleChangeAnswerCount,
3368
+ handleChangeQuestionCount = _useExamDetailView.handleChangeQuestionCount,
3369
+ handleChangeCategory = _useExamDetailView.handleChangeCategory;
3370
+ return React.createElement(Row, {
3371
+ className: "" + className
3372
+ }, React.createElement(Col, {
3373
+ xs: 5
3374
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3375
+ className: "" + styles$2["question-label"],
3376
+ htmlFor: "title"
3377
+ }, t("title")), React.createElement(Input, {
3378
+ disabled: isDisabled,
3379
+ className: "w-100 rounded-2 " + styles$2["question-input"],
3380
+ value: exam.title,
3381
+ id: "title",
3382
+ placeholder: t("enter_title"),
3383
+ onChange: handleChangeTitle
3384
+ }))), React.createElement(Col, {
3385
+ xs: 3
3386
+ }, React.createElement(FormGroup, null, React.createElement(Label, {
3387
+ className: "" + styles$2["question-label"],
3388
+ htmlFor: "duration"
3389
+ }, t("duration")), React.createElement(CustomSelect, {
3390
+ inputId: "duration",
3391
+ value: exam.duration,
3392
+ options: durationOptions,
3393
+ onChange: handleChangeDuration,
3394
+ isDisabled: isDisabled
3395
+ }))), React.createElement(Col, {
3396
+ xs: 4
3397
+ }), examGroupByArticle.map(function (i, index) {
3398
+ return React.createElement(Col, {
3399
+ xs: 12,
3400
+ key: i.article,
3401
+ className: (index === 0 && !isUsingMui ? "mt-3" : "") + " " + (!isUsingMui ? "mb-4" : "")
3402
+ }, React.createElement(ArticleGroupView, Object.assign({}, i, {
3403
+ categoryOptions: categoryOptions,
3404
+ isActive: index === examGroupByArticle.length - 1,
3405
+ onChangeQuestionCount: handleChangeQuestionCount,
3406
+ onChangeCategory: handleChangeCategory,
3407
+ onChangeAnswerCount: handleChangeAnswerCount,
3408
+ onChangeCorrectAnswers: handleChangeCorrectAnswers,
3409
+ onChangeScoreAnswer: handleChangeScoreAnswer,
3410
+ isDisabled: isDisabled
3411
+ })));
3412
+ }), React.createElement(Col, {
3413
+ xs: 12
3414
+ }, React.createElement(Button, {
3415
+ disabled: isDisabled,
3416
+ className: "w-100 d-flex justify-content-center align-items-center " + styles$2["question-btn"],
3417
+ color: "primary",
3418
+ outline: true,
3419
+ onClick: handleAddArticle
3420
+ }, React.createElement(FaPlusCircle, {
3421
+ className: "me-2"
3422
+ }), "\uBB38\uD56D \uCD94\uAC00\uD558\uAE30")));
3423
+ };
3424
+
2560
3425
  var historyCore = createBrowserHistory();
2561
3426
 
2562
- 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 };
3427
+ export { ACCESS_TOKEN, BASE_URL, ChatContainer, ChatItemType, CommonAlert, CommonDialog, ConfirmDialog, CustomAsyncSelect, CustomCreatable, CustomPagination, CustomSelect, DATE_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 };
2563
3428
  //# sourceMappingURL=index.modern.js.map