touchstudy-core 0.1.171 → 0.1.172

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.
@@ -18,7 +18,7 @@ import moment from 'moment';
18
18
  export { default as moment } from 'moment';
19
19
  import { FaSave, FaCaretDown, FaTimes, FaTrash, FaSortUp, FaSortDown, FaPlusCircle, FaEye, FaPlus, FaCalendar, FaUser, FaBookOpen, FaUpload, FaPencilAlt, FaCheckCircle, FaShare, FaExchangeAlt, FaBell } from 'react-icons/fa';
20
20
  import { IoMdArrowBack, IoMdSync, IoIosAlert, IoIosArrowDown, IoIosSearch, IoIosArrowUp, IoIosAdd, IoMdAdd } from 'react-icons/io';
21
- import { IoClose, IoSearch, IoCloseOutline, IoTime, IoChevronUp, IoChevronDown, IoChatbubbleEllipsesSharp, IoPrint, IoCheckmarkCircle, IoChevronUpOutline, IoChevronDownOutline, IoReceiptSharp, IoBook, IoWarning, IoCalendarClear, IoPerson, IoInformationCircle, IoTrash, IoAddCircle, IoCloseCircle, IoLogOut } from 'react-icons/io5';
21
+ import { IoClose, IoSearch, IoCloseOutline, IoTime, IoChevronUp, IoChevronDown, IoChatbubbleEllipsesSharp, IoPrint, IoCheckmarkCircle, IoChevronUpOutline, IoChevronDownOutline, IoReceiptSharp, IoBook, IoWarning, IoCalendarClear, IoPerson, IoInformationCircle, IoTrash, IoAddCircle, IoCheckmark, IoCloseCircle, IoLogOut } from 'react-icons/io5';
22
22
  import MButton from '@mui/material/Button';
23
23
  import DialogTitle$1 from '@mui/material/DialogTitle';
24
24
  import DialogContent$1 from '@mui/material/DialogContent';
@@ -48,7 +48,7 @@ import CardMedia from '@mui/material/CardMedia';
48
48
  import { object, string, number, date as date$2, array, mixed } from 'yup';
49
49
  import { blue, grey as grey$1, yellow as yellow$1 } from '@mui/material/colors';
50
50
  import { GoogleReCaptcha, GoogleReCaptchaProvider } from 'react-google-recaptcha-v3';
51
- import { MdVisibilityOff, MdVisibility, MdAutorenew, MdMoreHoriz, MdDownload, MdExpandMore } from 'react-icons/md';
51
+ import { MdVisibilityOff, MdVisibility, MdAutorenew, MdMoreHoriz, MdDownload, MdExpandMore, MdError } from 'react-icons/md';
52
52
  import { gapi } from 'gapi-script';
53
53
  import Pusher from 'pusher-js/with-encryption';
54
54
  import { BiSolidError } from 'react-icons/bi';
@@ -73,6 +73,7 @@ import { useForm } from 'react-hook-form';
73
73
  import { yupResolver } from '@hookform/resolvers/yup';
74
74
  import { PiDotsNineLight } from 'react-icons/pi';
75
75
  import Container$1 from '@mui/material/Container';
76
+ import { AiOutlineLoading3Quarters } from 'react-icons/ai';
76
77
  import { BsCheckAll } from 'react-icons/bs';
77
78
  import Popover$1 from '@mui/material/Popover';
78
79
  import MenuItem from '@mui/material/MenuItem';
@@ -1033,6 +1034,7 @@ var teacher_required = "선생님은 필수입니다";
1033
1034
  var total_users = "총 사용자";
1034
1035
  var added_date = "추가된 날짜";
1035
1036
  var sync_exam_results = "시험 결과 동기화";
1037
+ var sync_textbook_results = "교재 결과 동기화";
1036
1038
  var update_data_fail = "데이터 업데이트 실패";
1037
1039
  var add_students_to_class = "수업에 학생 추가";
1038
1040
  var add_teachers_to_class = "수업에 교사 추가";
@@ -1043,9 +1045,13 @@ var question_management = "질문 관리";
1043
1045
  var student_data = "학생 데이터";
1044
1046
  var problem_number_question_chart = "문제 {{number}}번";
1045
1047
  var are_you_sure_to_sync_exam_results_to_academy = "시험 결과를 아카데미 {{ academyName }}에 동기화하시겠습니까(백그라운드에서 실행되며 시간이 다소 소요됨)";
1048
+ var are_you_sure_to_sync_textbook_results_to_academy = "교재 학습 결과를 아카데미 {{ academyName }}에 동기화하시겠습니까? (백그라운드에서 실행되며 시간이 다소 소요됨)";
1046
1049
  var messages = {
1047
- exam_sessions_are_being_synchronized: "{{ total }} 개의 시험 세션이 동기화되고 있습니다"
1050
+ exam_sessions_are_being_synchronized: "{{ total }} 개의 시험 세션이 동기화되고 있습니다",
1051
+ textbook_sessions_are_being_synchronized: "{{ total }} 개의 교재 학습 세션이 동기화되고 있습니다"
1048
1052
  };
1053
+ var sync_exam = "시험 동기화";
1054
+ var sync_textbook = "교재 동기화";
1049
1055
  var submit = "제출하다";
1050
1056
  var must_select_a_teacher_first = "먼저 교사를 선택해야 합니다";
1051
1057
  var student_grade_is_invalid = "학생 등급은 1에서 12 사이여야 합니다";
@@ -1492,6 +1498,8 @@ var order_matters = "순서 상관 있음";
1492
1498
  var order_does_not_matter = "순서 상관 없음";
1493
1499
  var synonym_processing = "답 이음동의어 처리";
1494
1500
  var compare_type = "비교 유형";
1501
+ var all_changes_saved = "모든 변경 사항이 저장되었습니다";
1502
+ var saving = "절약";
1495
1503
  var textbook_name = "교재 이름";
1496
1504
  var korean_language = "국어";
1497
1505
  var answer_cannot_be_empty = "답변은 비워둘 수 없습니다";
@@ -1538,6 +1546,7 @@ var admin_to_teachers = "관리자에서 교사들에게";
1538
1546
  var teacher_to_teachers = "교사에서 교사들에게";
1539
1547
  var student_required = "학생은 필수입니다";
1540
1548
  var teachers_required = "교사가 필요합니다";
1549
+ var all_changes_are_not_saved_yet = "아직 모든 변경 사항이 저장되지 않았습니다";
1541
1550
  var lang_ko = {
1542
1551
  problem_solving: problem_solving,
1543
1552
  my_story: my_story,
@@ -2217,6 +2226,7 @@ var lang_ko = {
2217
2226
  total_users: total_users,
2218
2227
  added_date: added_date,
2219
2228
  sync_exam_results: sync_exam_results,
2229
+ sync_textbook_results: sync_textbook_results,
2220
2230
  update_data_fail: update_data_fail,
2221
2231
  add_students_to_class: add_students_to_class,
2222
2232
  add_teachers_to_class: add_teachers_to_class,
@@ -2227,7 +2237,10 @@ var lang_ko = {
2227
2237
  student_data: student_data,
2228
2238
  problem_number_question_chart: problem_number_question_chart,
2229
2239
  are_you_sure_to_sync_exam_results_to_academy: are_you_sure_to_sync_exam_results_to_academy,
2240
+ are_you_sure_to_sync_textbook_results_to_academy: are_you_sure_to_sync_textbook_results_to_academy,
2230
2241
  messages: messages,
2242
+ sync_exam: sync_exam,
2243
+ sync_textbook: sync_textbook,
2231
2244
  submit: submit,
2232
2245
  must_select_a_teacher_first: must_select_a_teacher_first,
2233
2246
  student_grade_is_invalid: student_grade_is_invalid,
@@ -2662,6 +2675,8 @@ var lang_ko = {
2662
2675
  order_does_not_matter: order_does_not_matter,
2663
2676
  synonym_processing: synonym_processing,
2664
2677
  compare_type: compare_type,
2678
+ all_changes_saved: all_changes_saved,
2679
+ saving: saving,
2665
2680
  textbook_name: textbook_name,
2666
2681
  korean_language: korean_language,
2667
2682
  answer_cannot_be_empty: answer_cannot_be_empty,
@@ -2707,7 +2722,8 @@ var lang_ko = {
2707
2722
  admin_to_teachers: admin_to_teachers,
2708
2723
  teacher_to_teachers: teacher_to_teachers,
2709
2724
  student_required: student_required,
2710
- teachers_required: teachers_required
2725
+ teachers_required: teachers_required,
2726
+ all_changes_are_not_saved_yet: all_changes_are_not_saved_yet
2711
2727
  };
2712
2728
 
2713
2729
  var problem_solving$1 = "Problem Solving";
@@ -3394,6 +3410,7 @@ var teacher_required$1 = "Teacher is required";
3394
3410
  var total_users$1 = "Total users";
3395
3411
  var added_date$1 = "Added date";
3396
3412
  var sync_exam_results$1 = "Sync exam results";
3413
+ var sync_textbook_results$1 = "Sync textbook results";
3397
3414
  var update_data_fail$1 = "Update data fail";
3398
3415
  var add_students_to_class$1 = "Add students to class";
3399
3416
  var add_teachers_to_class$1 = "Add teachers to class";
@@ -3404,9 +3421,13 @@ var question_management$1 = "Question Management";
3404
3421
  var student_data$1 = "Student Data";
3405
3422
  var problem_number_question_chart$1 = "Q. {{number}}";
3406
3423
  var are_you_sure_to_sync_exam_results_to_academy$1 = "Are you sure to sync exam results to academy \"{{ academyName }}\" (it will run in the background and take a while)";
3424
+ var are_you_sure_to_sync_textbook_results_to_academy$1 = "Are you sure to sync textbook results to academy \"{{ academyName }}\" (it will run in the background and take a while)";
3407
3425
  var messages$1 = {
3408
- exam_sessions_are_being_synchronized: "{{ total }} exam sessions are being synchronized"
3426
+ exam_sessions_are_being_synchronized: "{{ total }} exam sessions are being synchronized",
3427
+ textbook_sessions_are_being_synchronized: "{{ total }} textbook sessions are being synchronized"
3409
3428
  };
3429
+ var sync_exam$1 = "Sync Exam";
3430
+ var sync_textbook$1 = "Sync Textbook";
3410
3431
  var submit$1 = "Submit";
3411
3432
  var must_select_a_teacher_first$1 = "Must select a teacher first";
3412
3433
  var student_grade_is_invalid$1 = "Student grade must be from 1 to 12";
@@ -3854,6 +3875,8 @@ var order_matters$1 = "Order matters";
3854
3875
  var order_does_not_matter$1 = "Order doesn't matter";
3855
3876
  var synonym_processing$1 = "Answer Synonym processing";
3856
3877
  var compare_type$1 = "Compare Type";
3878
+ var all_changes_saved$1 = "All changes saved";
3879
+ var saving$1 = "Saving";
3857
3880
  var textbook_name$1 = "Textbook name";
3858
3881
  var korean_language$1 = "Korean";
3859
3882
  var answer_cannot_be_empty$1 = "Answer cannot be empty";
@@ -3900,6 +3923,7 @@ var admin_to_teachers$1 = "Admin to teachers";
3900
3923
  var teacher_to_teachers$1 = "Teacher to teachers";
3901
3924
  var student_required$1 = "Student is required";
3902
3925
  var teachers_required$1 = "Teachers are required";
3926
+ var all_changes_are_not_saved_yet$1 = "All changes are not saved yet";
3903
3927
  var lang_en = {
3904
3928
  problem_solving: problem_solving$1,
3905
3929
  my_story: my_story$1,
@@ -4580,6 +4604,7 @@ var lang_en = {
4580
4604
  total_users: total_users$1,
4581
4605
  added_date: added_date$1,
4582
4606
  sync_exam_results: sync_exam_results$1,
4607
+ sync_textbook_results: sync_textbook_results$1,
4583
4608
  update_data_fail: update_data_fail$1,
4584
4609
  add_students_to_class: add_students_to_class$1,
4585
4610
  add_teachers_to_class: add_teachers_to_class$1,
@@ -4590,7 +4615,10 @@ var lang_en = {
4590
4615
  student_data: student_data$1,
4591
4616
  problem_number_question_chart: problem_number_question_chart$1,
4592
4617
  are_you_sure_to_sync_exam_results_to_academy: are_you_sure_to_sync_exam_results_to_academy$1,
4618
+ are_you_sure_to_sync_textbook_results_to_academy: are_you_sure_to_sync_textbook_results_to_academy$1,
4593
4619
  messages: messages$1,
4620
+ sync_exam: sync_exam$1,
4621
+ sync_textbook: sync_textbook$1,
4594
4622
  submit: submit$1,
4595
4623
  must_select_a_teacher_first: must_select_a_teacher_first$1,
4596
4624
  student_grade_is_invalid: student_grade_is_invalid$1,
@@ -5026,6 +5054,8 @@ var lang_en = {
5026
5054
  order_does_not_matter: order_does_not_matter$1,
5027
5055
  synonym_processing: synonym_processing$1,
5028
5056
  compare_type: compare_type$1,
5057
+ all_changes_saved: all_changes_saved$1,
5058
+ saving: saving$1,
5029
5059
  textbook_name: textbook_name$1,
5030
5060
  korean_language: korean_language$1,
5031
5061
  answer_cannot_be_empty: answer_cannot_be_empty$1,
@@ -5071,7 +5101,8 @@ var lang_en = {
5071
5101
  admin_to_teachers: admin_to_teachers$1,
5072
5102
  teacher_to_teachers: teacher_to_teachers$1,
5073
5103
  student_required: student_required$1,
5074
- teachers_required: teachers_required$1
5104
+ teachers_required: teachers_required$1,
5105
+ all_changes_are_not_saved_yet: all_changes_are_not_saved_yet$1
5075
5106
  };
5076
5107
 
5077
5108
  i18n.use(initReactI18next).init({
@@ -6277,6 +6308,12 @@ var TextbookEditorType;
6277
6308
  TextbookEditorType[TextbookEditorType["Korea"] = 1] = "Korea";
6278
6309
  TextbookEditorType[TextbookEditorType["Math"] = 2] = "Math";
6279
6310
  })(TextbookEditorType || (TextbookEditorType = {}));
6311
+ var PrintStatus;
6312
+ (function (PrintStatus) {
6313
+ PrintStatus[PrintStatus["Idle"] = 0] = "Idle";
6314
+ PrintStatus[PrintStatus["Saving"] = 1] = "Saving";
6315
+ PrintStatus[PrintStatus["Saved"] = 2] = "Saved";
6316
+ })(PrintStatus || (PrintStatus = {}));
6280
6317
 
6281
6318
  var SchoolType$1;
6282
6319
  (function (SchoolType) {
@@ -33873,11 +33910,11 @@ var TextbookRow = function TextbookRow(_ref) {
33873
33910
  });
33874
33911
  var _useTranslation = useTranslation(),
33875
33912
  t = _useTranslation.t;
33876
- var isEditable = (!onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && data.isShared && (((_data$createdBy = data.createdBy) === null || _data$createdBy === void 0 ? void 0 : _data$createdBy.id) === (infoUser === null || infoUser === void 0 ? void 0 : infoUser.id) || ((_data$textbookOwners = data.textbookOwners) === null || _data$textbookOwners === void 0 ? void 0 : _data$textbookOwners.some(function (i) {
33913
+ var isEditable = !onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && data.isShared && (((_data$createdBy = data.createdBy) === null || _data$createdBy === void 0 ? void 0 : _data$createdBy.id) === (infoUser === null || infoUser === void 0 ? void 0 : infoUser.id) || ((_data$textbookOwners = data.textbookOwners) === null || _data$textbookOwners === void 0 ? void 0 : _data$textbookOwners.some(function (i) {
33877
33914
  var _infoUser$email, _infoUser$email$trim;
33878
33915
  return (i === null || i === void 0 ? void 0 : i.email.trim().toUpperCase()) === (infoUser === null || infoUser === void 0 ? void 0 : (_infoUser$email = infoUser.email) === null || _infoUser$email === void 0 ? void 0 : (_infoUser$email$trim = _infoUser$email.trim()) === null || _infoUser$email$trim === void 0 ? void 0 : _infoUser$email$trim.toUpperCase()) && (i === null || i === void 0 ? void 0 : i.academyId) === (academy === null || academy === void 0 ? void 0 : academy.id);
33879
- })))) && data.totalUses <= 0;
33880
- var isDeleteAble = !onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && data.isShared && ((_data$createdBy2 = data.createdBy) === null || _data$createdBy2 === void 0 ? void 0 : _data$createdBy2.id) === (infoUser === null || infoUser === void 0 ? void 0 : infoUser.id) && data.totalUses <= 0;
33916
+ })));
33917
+ var isDeleteAble = !onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && data.isShared && ((_data$createdBy2 = data.createdBy) === null || _data$createdBy2 === void 0 ? void 0 : _data$createdBy2.id) === (infoUser === null || infoUser === void 0 ? void 0 : infoUser.id);
33881
33918
  var isSharable = !data.isPublic && data.isShared && onAcademy && (isAdminSite || isSuperAdminUser || !isAdmin && data.createdBy.id === infoUser.id);
33882
33919
  var handleUpdateTextbook = function handleUpdateTextbook() {
33883
33920
  onUpdateTextbook(data);
@@ -34898,10 +34935,10 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
34898
34935
  var isAdminSite = role === Role.Admin;
34899
34936
  var onAcademy = !!(user !== null && user !== void 0 && user.academyDomain);
34900
34937
  var isSuperAdminUser = !!user && user.isSuperAdmin;
34901
- var isEditable = !selectedTextbook || (!onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && selectedTextbook.isShared && (((_selectedTextbook$cre = selectedTextbook.createdBy) === null || _selectedTextbook$cre === void 0 ? void 0 : _selectedTextbook$cre.id) === (user === null || user === void 0 ? void 0 : user.id) || selectedTextbook.textbookOwners.some(function (i) {
34938
+ var isEditable = !selectedTextbook || !onAcademy || isAdminSite || isSuperAdmin || isSuperAdminUser || !isAdmin && selectedTextbook.isShared && (((_selectedTextbook$cre = selectedTextbook.createdBy) === null || _selectedTextbook$cre === void 0 ? void 0 : _selectedTextbook$cre.id) === (user === null || user === void 0 ? void 0 : user.id) || selectedTextbook.textbookOwners.some(function (i) {
34902
34939
  var _user$email, _user$email$trim;
34903
34940
  return i.email.trim().toUpperCase() === (user === null || user === void 0 ? void 0 : (_user$email = user.email) === null || _user$email === void 0 ? void 0 : (_user$email$trim = _user$email.trim()) === null || _user$email$trim === void 0 ? void 0 : _user$email$trim.toUpperCase()) && i.academyId === (academy === null || academy === void 0 ? void 0 : academy.id);
34904
- }))) && selectedTextbook.totalUses <= 0;
34941
+ }));
34905
34942
  var disabledTextbookOwners = !selectedTextbook && isAdmin || selectedTextbook && (!isEditable || isTeacher && ((_selectedTextbook$cre2 = selectedTextbook.createdBy) === null || _selectedTextbook$cre2 === void 0 ? void 0 : _selectedTextbook$cre2.id) !== (user === null || user === void 0 ? void 0 : user.id) || isAdmin && !isSuperAdminUser);
34906
34943
  var handleOpenConfirmDeleteChapterDialog = function handleOpenConfirmDeleteChapterDialog(chapter) {
34907
34944
  setSelectedChapter(chapter);
@@ -35003,6 +35040,24 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
35003
35040
  return Promise.reject(e);
35004
35041
  }
35005
35042
  };
35043
+ var handleSaveData = useCallback(function (values) {
35044
+ try {
35045
+ if (!coverImage && !(values !== null && values !== void 0 && values.coverImage)) {
35046
+ return Promise.resolve();
35047
+ }
35048
+ return Promise.resolve(_catch(function () {
35049
+ var coverImg = coverImage || (values === null || values === void 0 ? void 0 : values.coverImage);
35050
+ return Promise.resolve(updateTextbookApi$1(_extends({}, values, {
35051
+ coverImage: coverImg
35052
+ }), (selectedTextbook === null || selectedTextbook === void 0 ? void 0 : selectedTextbook.id) || 0, isSuperAdmin)).then(function () {});
35053
+ }, function (error) {
35054
+ toast.error(getErrorMessage(t, error));
35055
+ throw error;
35056
+ }));
35057
+ } catch (e) {
35058
+ return Promise.reject(e);
35059
+ }
35060
+ }, [coverImage, isSuperAdmin, JSON.stringify(selectedTextbook)]);
35006
35061
  useEffect(function () {
35007
35062
  if (!textbookId) return;
35008
35063
  handleGetTextbookDetail();
@@ -35021,6 +35076,7 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
35021
35076
  isSuperAdminUser: isSuperAdminUser,
35022
35077
  openDialog: openDialog,
35023
35078
  handleSubmit: handleSubmit,
35079
+ handleSaveData: handleSaveData,
35024
35080
  selectedTextbook: selectedTextbook,
35025
35081
  handleOpenDialog: handleOpenDialog,
35026
35082
  handleCloseDialog: handleCloseDialog,
@@ -35314,6 +35370,8 @@ var CompareTypeOptions = [{
35314
35370
  label: "synonym_processing",
35315
35371
  value: QuestionAnswerType.SynonymProcessing
35316
35372
  }];
35373
+ var SAVE_TIME_INTERVAL_IN_MILLISECONDS = 60 * 1000;
35374
+ var SAVE_TIME_MAX_DIFF_IN_MILLISECONDS = 500;
35317
35375
 
35318
35376
  var CustomTextbookTab = function CustomTextbookTab(props) {
35319
35377
  var children = props.children,
@@ -38489,7 +38547,7 @@ var TextbookOwnersTab = function TextbookOwnersTab(_ref) {
38489
38547
  }));
38490
38548
  };
38491
38549
 
38492
- var _excluded$n = ["isCreatedByAdmin", "isSuperAdminUser", "isSuperAdmin", "isAdmin", "textbookId", "selected", "coverImage", "disabled", "ownersDisabled", "onChangeTab", "onUploadImage"];
38550
+ var _excluded$n = ["isCreatedByAdmin", "isSuperAdminUser", "isSuperAdmin", "isAdmin", "textbookId", "selected", "coverImage", "disabled", "ownersDisabled", "selectedTextbook", "handleSaveData", "onChangeTab", "onUploadImage"];
38493
38551
  var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38494
38552
  var isCreatedByAdmin = _ref.isCreatedByAdmin,
38495
38553
  isSuperAdminUser = _ref.isSuperAdminUser,
@@ -38500,6 +38558,8 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38500
38558
  coverImage = _ref.coverImage,
38501
38559
  disabled = _ref.disabled,
38502
38560
  ownersDisabled = _ref.ownersDisabled,
38561
+ selectedTextbook = _ref.selectedTextbook,
38562
+ handleSaveData = _ref.handleSaveData,
38503
38563
  onChangeTab = _ref.onChangeTab,
38504
38564
  onUploadImage = _ref.onUploadImage,
38505
38565
  formikProps = _objectWithoutPropertiesLoose(_ref, _excluded$n);
@@ -38508,6 +38568,23 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38508
38568
  dirty = formikProps.dirty,
38509
38569
  submitCount = formikProps.submitCount,
38510
38570
  setValues = formikProps.setValues;
38571
+ var theme = useTheme();
38572
+ var savedRunRef = useRef(Date.now());
38573
+ var runTimeRef = useRef(Date.now());
38574
+ var valuesTextbook = useRef(null);
38575
+ var isFirstLoad = true;
38576
+ var _React$useState = React__default.useState(PrintStatus.Idle),
38577
+ saveStatus = _React$useState[0],
38578
+ setSaveStatus = _React$useState[1];
38579
+ var timeoutRef = useRef(null);
38580
+ var isProcessingRef = useRef(false);
38581
+ var pendingValuesRef = useRef(null);
38582
+ var _useState = useState(),
38583
+ saved = _useState[0],
38584
+ setSaved = _useState[1];
38585
+ var _useState2 = useState(),
38586
+ lastEdited = _useState2[0],
38587
+ setLastEdited = _useState2[1];
38511
38588
  useEffect(function () {
38512
38589
  var handleBeforeUnload = function handleBeforeUnload(event) {
38513
38590
  var message = t$1("are_you_sure_you_want_to_quit_yours_changes_may_not_be_saved");
@@ -38528,9 +38605,100 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38528
38605
  var newValues = _resetAllCategoriesAndQuestionTypesBySubject(values, val);
38529
38606
  setValues(newValues);
38530
38607
  };
38608
+ useEffect(function () {
38609
+ if (!valuesTextbook.current && isFirstLoad && !_$8.isEqual(values, DEFAULT_TEXTBOOK_REQUEST)) {
38610
+ valuesTextbook.current = _$8.cloneDeep(values);
38611
+ isFirstLoad = false;
38612
+ }
38613
+ }, [values]);
38614
+ var _handleSave = function handleSave(valuesProps) {
38615
+ try {
38616
+ var _temp = _finallyRethrows(function () {
38617
+ return _catch(function () {
38618
+ isProcessingRef.current = true;
38619
+ setSaveStatus(PrintStatus.Saving);
38620
+ var valuesToSave = valuesProps || values;
38621
+ return Promise.resolve(handleSaveData(valuesToSave)).then(function () {
38622
+ valuesTextbook.current = _$8.cloneDeep(valuesToSave);
38623
+ var now = Date.now();
38624
+ savedRunRef.current = now;
38625
+ runTimeRef.current = now;
38626
+ setSaveStatus(PrintStatus.Saved);
38627
+ setSaved(valuesToSave);
38628
+ });
38629
+ }, function (error) {
38630
+ setSaveStatus(PrintStatus.Idle);
38631
+ console.error(error);
38632
+ });
38633
+ }, function (_wasThrown, _result) {
38634
+ isProcessingRef.current = false;
38635
+ if (pendingValuesRef.current) {
38636
+ if (timeoutRef.current) {
38637
+ clearTimeout(timeoutRef.current);
38638
+ }
38639
+ timeoutRef.current = setTimeout(function () {
38640
+ timeoutRef.current = null;
38641
+ var pendingValues = pendingValuesRef.current;
38642
+ if (pendingValues) {
38643
+ _handleSave(pendingValues);
38644
+ pendingValuesRef.current = null;
38645
+ }
38646
+ }, SAVE_TIME_INTERVAL_IN_MILLISECONDS);
38647
+ }
38648
+ if (_wasThrown) throw _result;
38649
+ return _result;
38650
+ });
38651
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
38652
+ } catch (e) {
38653
+ return Promise.reject(e);
38654
+ }
38655
+ };
38656
+ useEffect(function () {
38657
+ var now = Date.now();
38658
+ if (valuesTextbook.current && !_$8.isEqual(values, valuesTextbook.current)) setLastEdited(now);
38659
+ if (!_$8.isEmpty(errors) || !valuesTextbook.current || !(selectedTextbook !== null && selectedTextbook !== void 0 && selectedTextbook.id)) return;
38660
+ if (valuesTextbook.current && _$8.isEqual(values, valuesTextbook.current)) return;
38661
+ if (isProcessingRef.current) {
38662
+ pendingValuesRef.current = _$8.cloneDeep(values);
38663
+ return;
38664
+ }
38665
+ var timeSinceLastRun = now - runTimeRef.current;
38666
+ var maxTime = SAVE_TIME_INTERVAL_IN_MILLISECONDS + SAVE_TIME_MAX_DIFF_IN_MILLISECONDS;
38667
+ if (timeSinceLastRun > maxTime) {
38668
+ runTimeRef.current = now;
38669
+ timeSinceLastRun = 0;
38670
+ }
38671
+ if (timeSinceLastRun >= SAVE_TIME_INTERVAL_IN_MILLISECONDS) {
38672
+ if (timeoutRef.current) {
38673
+ clearTimeout(timeoutRef.current);
38674
+ timeoutRef.current = null;
38675
+ pendingValuesRef.current = null;
38676
+ }
38677
+ _handleSave();
38678
+ } else {
38679
+ pendingValuesRef.current = _$8.cloneDeep(values);
38680
+ var intevalTime = SAVE_TIME_INTERVAL_IN_MILLISECONDS - timeSinceLastRun;
38681
+ timeoutRef.current = setTimeout(function () {
38682
+ timeoutRef.current = null;
38683
+ var pendingValues = pendingValuesRef.current;
38684
+ if (pendingValues) {
38685
+ clearTimeout(timeoutRef.current);
38686
+ _handleSave(pendingValues);
38687
+ pendingValuesRef.current = null;
38688
+ }
38689
+ }, intevalTime);
38690
+ }
38691
+ return function () {
38692
+ if (timeoutRef.current) {
38693
+ clearTimeout(timeoutRef.current);
38694
+ }
38695
+ };
38696
+ }, [values, errors]);
38531
38697
  var inforErrors = errors.coverImage || errors.grade || errors.isbn || errors.preparedType || errors.publicationDate || errors.publisher;
38532
38698
  var contentsErrors = errors.chapters;
38533
38699
  var textbookOwnersErrors = errors.textbookOwners;
38700
+ var hasError = !_$8.isEmpty(errors);
38701
+ var isSaved = !lastEdited || _$8.isEqual(values, saved != null ? saved : {});
38534
38702
  return React__default.createElement(Form, null, React__default.createElement(Stack, {
38535
38703
  direction: "column",
38536
38704
  gap: 3
@@ -38618,7 +38786,45 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38618
38786
  }), React__default.createElement(FormLabel, {
38619
38787
  htmlFor: "type",
38620
38788
  className: "text-center"
38621
- }, t$1("math"))))), React__default.createElement(Box, null, React__default.createElement(Button, {
38789
+ }, t$1("math"))))), React__default.createElement(Stack, {
38790
+ flexDirection: "row",
38791
+ gap: "8px"
38792
+ }, React__default.createElement(Stack, {
38793
+ padding: "6px 12px",
38794
+ sx: {
38795
+ transition: "opacity 0.3s ease",
38796
+ opacity: saveStatus === PrintStatus.Idle && isSaved ? 0 : 1,
38797
+ pointerEvents: "none",
38798
+ gap: "8px",
38799
+ flexDirection: "row",
38800
+ justifyContent: "center",
38801
+ alignItems: "center"
38802
+ }
38803
+ }, saveStatus === PrintStatus.Saving && React__default.createElement(AiOutlineLoading3Quarters, {
38804
+ style: {
38805
+ animation: "spin 1s linear infinite"
38806
+ }
38807
+ }), saveStatus === PrintStatus.Saved && isSaved && React__default.createElement(IoCheckmark, null), saveStatus !== PrintStatus.Saving && !isSaved && React__default.createElement(Fragment$1, null, hasError ? React__default.createElement(MdError, {
38808
+ color: red[900]
38809
+ }) : React__default.createElement(FaClockRotateLeft, {
38810
+ size: "14px"
38811
+ })), React__default.createElement(Typography, {
38812
+ sx: {
38813
+ color: theme.palette.grey[700],
38814
+ fontSize: "14px",
38815
+ display: "flex",
38816
+ alignItems: "center",
38817
+ gap: 1,
38818
+ "@keyframes spin": {
38819
+ "0%": {
38820
+ transform: "rotate(0deg)"
38821
+ },
38822
+ "100%": {
38823
+ transform: "rotate(360deg)"
38824
+ }
38825
+ }
38826
+ }
38827
+ }, saveStatus === PrintStatus.Saving && t$1("saving"), saveStatus === PrintStatus.Saved && isSaved && t$1("all_changes_saved"), saveStatus !== PrintStatus.Saving && (selectedTextbook === null || selectedTextbook === void 0 ? void 0 : selectedTextbook.id) && !isSaved && t$1("all_changes_are_not_saved_yet"))), React__default.createElement(Button, {
38622
38828
  type: "submit",
38623
38829
  sx: {
38624
38830
  width: "fit-content"
@@ -38725,6 +38931,7 @@ var PreparedTextbookView = function PreparedTextbookView(_ref) {
38725
38931
  isSuperAdminUser = _useTextbookManagemen.isSuperAdminUser,
38726
38932
  isAdmin = _useTextbookManagemen.isAdmin,
38727
38933
  coverImage = _useTextbookManagemen.coverImage,
38934
+ handleSaveData = _useTextbookManagemen.handleSaveData,
38728
38935
  selectedTextbook = _useTextbookManagemen.selectedTextbook,
38729
38936
  handleSubmit = _useTextbookManagemen.handleSubmit,
38730
38937
  handleUploadImage = _useTextbookManagemen.handleUploadImage;
@@ -38747,7 +38954,9 @@ var PreparedTextbookView = function PreparedTextbookView(_ref) {
38747
38954
  isAdmin: isAdmin,
38748
38955
  isSuperAdmin: isSuperAdmin,
38749
38956
  selected: selected,
38957
+ handleSaveData: handleSaveData,
38750
38958
  textbookId: textbookId,
38959
+ selectedTextbook: selectedTextbook,
38751
38960
  onChangeTab: handleChangeTab,
38752
38961
  onUploadImage: handleUploadImage,
38753
38962
  coverImage: coverImage,