touchstudy-core 0.1.177 → 0.1.179

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({
@@ -6280,6 +6311,12 @@ var TextbookEditorType;
6280
6311
  TextbookEditorType[TextbookEditorType["Korea"] = 1] = "Korea";
6281
6312
  TextbookEditorType[TextbookEditorType["Math"] = 2] = "Math";
6282
6313
  })(TextbookEditorType || (TextbookEditorType = {}));
6314
+ var PrintStatus;
6315
+ (function (PrintStatus) {
6316
+ PrintStatus[PrintStatus["Idle"] = 0] = "Idle";
6317
+ PrintStatus[PrintStatus["Saving"] = 1] = "Saving";
6318
+ PrintStatus[PrintStatus["Saved"] = 2] = "Saved";
6319
+ })(PrintStatus || (PrintStatus = {}));
6283
6320
 
6284
6321
  var SchoolType$1;
6285
6322
  (function (SchoolType) {
@@ -33929,11 +33966,11 @@ var TextbookRow = function TextbookRow(_ref) {
33929
33966
  });
33930
33967
  var _useTranslation = useTranslation(),
33931
33968
  t = _useTranslation.t;
33932
- 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) {
33969
+ 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) {
33933
33970
  var _infoUser$email, _infoUser$email$trim;
33934
33971
  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);
33935
- })))) && data.totalUses <= 0;
33936
- 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;
33972
+ })));
33973
+ 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);
33937
33974
  var isSharable = !data.isPublic && data.isShared && onAcademy && (isAdminSite || isSuperAdminUser || !isAdmin && data.createdBy.id === infoUser.id);
33938
33975
  var handleUpdateTextbook = function handleUpdateTextbook() {
33939
33976
  onUpdateTextbook(data);
@@ -34954,10 +34991,10 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
34954
34991
  var isAdminSite = role === Role.Admin;
34955
34992
  var onAcademy = !!(user !== null && user !== void 0 && user.academyDomain);
34956
34993
  var isSuperAdminUser = !!user && user.isSuperAdmin;
34957
- 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) {
34994
+ 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) {
34958
34995
  var _user$email, _user$email$trim;
34959
34996
  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);
34960
- }))) && selectedTextbook.totalUses <= 0;
34997
+ }));
34961
34998
  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);
34962
34999
  var handleOpenConfirmDeleteChapterDialog = function handleOpenConfirmDeleteChapterDialog(chapter) {
34963
35000
  setSelectedChapter(chapter);
@@ -35059,6 +35096,24 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
35059
35096
  return Promise.reject(e);
35060
35097
  }
35061
35098
  };
35099
+ var handleSaveData = useCallback(function (values) {
35100
+ try {
35101
+ if (!coverImage && !(values !== null && values !== void 0 && values.coverImage)) {
35102
+ return Promise.resolve();
35103
+ }
35104
+ return Promise.resolve(_catch(function () {
35105
+ var coverImg = coverImage || (values === null || values === void 0 ? void 0 : values.coverImage);
35106
+ return Promise.resolve(updateTextbookApi$1(_extends({}, values, {
35107
+ coverImage: coverImg
35108
+ }), (selectedTextbook === null || selectedTextbook === void 0 ? void 0 : selectedTextbook.id) || 0, isSuperAdmin)).then(function () {});
35109
+ }, function (error) {
35110
+ toast.error(getErrorMessage(t, error));
35111
+ throw error;
35112
+ }));
35113
+ } catch (e) {
35114
+ return Promise.reject(e);
35115
+ }
35116
+ }, [coverImage, isSuperAdmin, JSON.stringify(selectedTextbook)]);
35062
35117
  useEffect(function () {
35063
35118
  if (!textbookId) return;
35064
35119
  handleGetTextbookDetail();
@@ -35077,6 +35132,7 @@ var useTextbookManagement = function useTextbookManagement(_ref) {
35077
35132
  isSuperAdminUser: isSuperAdminUser,
35078
35133
  openDialog: openDialog,
35079
35134
  handleSubmit: handleSubmit,
35135
+ handleSaveData: handleSaveData,
35080
35136
  selectedTextbook: selectedTextbook,
35081
35137
  handleOpenDialog: handleOpenDialog,
35082
35138
  handleCloseDialog: handleCloseDialog,
@@ -35370,6 +35426,8 @@ var CompareTypeOptions = [{
35370
35426
  label: "synonym_processing",
35371
35427
  value: QuestionAnswerType.SynonymProcessing
35372
35428
  }];
35429
+ var SAVE_TIME_INTERVAL_IN_MILLISECONDS = 60 * 1000;
35430
+ var SAVE_TIME_MAX_DIFF_IN_MILLISECONDS = 1000;
35373
35431
 
35374
35432
  var CustomTextbookTab = function CustomTextbookTab(props) {
35375
35433
  var children = props.children,
@@ -38545,8 +38603,9 @@ var TextbookOwnersTab = function TextbookOwnersTab(_ref) {
38545
38603
  }));
38546
38604
  };
38547
38605
 
38548
- var _excluded$n = ["isCreatedByAdmin", "isSuperAdminUser", "isSuperAdmin", "isAdmin", "textbookId", "selected", "coverImage", "disabled", "ownersDisabled", "onChangeTab", "onUploadImage"];
38606
+ var _excluded$n = ["isCreatedByAdmin", "isSuperAdminUser", "isSuperAdmin", "isAdmin", "textbookId", "selected", "coverImage", "disabled", "ownersDisabled", "selectedTextbook", "handleSaveData", "onChangeTab", "onUploadImage"];
38549
38607
  var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38608
+ var _valuesTextbook$curre;
38550
38609
  var isCreatedByAdmin = _ref.isCreatedByAdmin,
38551
38610
  isSuperAdminUser = _ref.isSuperAdminUser,
38552
38611
  isSuperAdmin = _ref.isSuperAdmin,
@@ -38556,6 +38615,8 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38556
38615
  coverImage = _ref.coverImage,
38557
38616
  disabled = _ref.disabled,
38558
38617
  ownersDisabled = _ref.ownersDisabled,
38618
+ selectedTextbook = _ref.selectedTextbook,
38619
+ handleSaveData = _ref.handleSaveData,
38559
38620
  onChangeTab = _ref.onChangeTab,
38560
38621
  onUploadImage = _ref.onUploadImage,
38561
38622
  formikProps = _objectWithoutPropertiesLoose(_ref, _excluded$n);
@@ -38564,6 +38625,20 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38564
38625
  dirty = formikProps.dirty,
38565
38626
  submitCount = formikProps.submitCount,
38566
38627
  setValues = formikProps.setValues;
38628
+ var theme = useTheme();
38629
+ var savedRunRef = useRef(Date.now());
38630
+ var runTimeRef = useRef(Date.now());
38631
+ var valuesTextbook = useRef(null);
38632
+ var isFirstLoadRef = useRef(true);
38633
+ var _React$useState = React__default.useState(PrintStatus.Idle),
38634
+ saveStatus = _React$useState[0],
38635
+ setSaveStatus = _React$useState[1];
38636
+ var timeoutRef = useRef(null);
38637
+ var isProcessingRef = useRef(false);
38638
+ var pendingValuesRef = useRef(null);
38639
+ var _useState = useState(),
38640
+ lastEdited = _useState[0],
38641
+ setLastEdited = _useState[1];
38567
38642
  useEffect(function () {
38568
38643
  var handleBeforeUnload = function handleBeforeUnload(event) {
38569
38644
  var message = t$1("are_you_sure_you_want_to_quit_yours_changes_may_not_be_saved");
@@ -38584,9 +38659,99 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38584
38659
  var newValues = _resetAllCategoriesAndQuestionTypesBySubject(values, val);
38585
38660
  setValues(newValues);
38586
38661
  };
38662
+ useEffect(function () {
38663
+ if (!valuesTextbook.current && isFirstLoadRef.current && !_$8.isEqual(values, DEFAULT_TEXTBOOK_REQUEST)) {
38664
+ valuesTextbook.current = _$8.cloneDeep(values);
38665
+ isFirstLoadRef.current = false;
38666
+ }
38667
+ }, [values]);
38668
+ var _handleSave = function handleSave(valuesProps) {
38669
+ try {
38670
+ var _temp = _finallyRethrows(function () {
38671
+ return _catch(function () {
38672
+ isProcessingRef.current = true;
38673
+ setSaveStatus(PrintStatus.Saving);
38674
+ var valuesToSave = valuesProps || values;
38675
+ return Promise.resolve(handleSaveData(valuesToSave)).then(function () {
38676
+ valuesTextbook.current = _$8.cloneDeep(valuesToSave);
38677
+ var now = Date.now();
38678
+ savedRunRef.current = now;
38679
+ runTimeRef.current = now;
38680
+ setSaveStatus(PrintStatus.Saved);
38681
+ });
38682
+ }, function (error) {
38683
+ setSaveStatus(PrintStatus.Idle);
38684
+ console.error(error);
38685
+ });
38686
+ }, function (_wasThrown, _result) {
38687
+ isProcessingRef.current = false;
38688
+ if (pendingValuesRef.current) {
38689
+ if (timeoutRef.current) {
38690
+ clearTimeout(timeoutRef.current);
38691
+ }
38692
+ timeoutRef.current = setTimeout(function () {
38693
+ timeoutRef.current = null;
38694
+ var pendingValues = pendingValuesRef.current;
38695
+ if (pendingValues) {
38696
+ _handleSave(pendingValues);
38697
+ pendingValuesRef.current = null;
38698
+ }
38699
+ }, SAVE_TIME_INTERVAL_IN_MILLISECONDS);
38700
+ }
38701
+ if (_wasThrown) throw _result;
38702
+ return _result;
38703
+ });
38704
+ return Promise.resolve(_temp && _temp.then ? _temp.then(function () {}) : void 0);
38705
+ } catch (e) {
38706
+ return Promise.reject(e);
38707
+ }
38708
+ };
38709
+ useEffect(function () {
38710
+ var now = Date.now();
38711
+ if (valuesTextbook.current && !_$8.isEqual(values, valuesTextbook.current)) setLastEdited(now);
38712
+ if (!_$8.isEmpty(errors) || !valuesTextbook.current || !(selectedTextbook !== null && selectedTextbook !== void 0 && selectedTextbook.id)) return;
38713
+ if (valuesTextbook.current && _$8.isEqual(values, valuesTextbook.current)) return;
38714
+ if (isProcessingRef.current) {
38715
+ pendingValuesRef.current = _$8.cloneDeep(values);
38716
+ return;
38717
+ }
38718
+ var timeSinceLastRun = now - runTimeRef.current;
38719
+ var maxTime = SAVE_TIME_INTERVAL_IN_MILLISECONDS + SAVE_TIME_MAX_DIFF_IN_MILLISECONDS;
38720
+ if (timeSinceLastRun > maxTime) {
38721
+ runTimeRef.current = now;
38722
+ timeSinceLastRun = 0;
38723
+ }
38724
+ if (timeSinceLastRun >= SAVE_TIME_INTERVAL_IN_MILLISECONDS) {
38725
+ if (timeoutRef.current) {
38726
+ clearTimeout(timeoutRef.current);
38727
+ timeoutRef.current = null;
38728
+ pendingValuesRef.current = null;
38729
+ }
38730
+ _handleSave();
38731
+ } else {
38732
+ pendingValuesRef.current = _$8.cloneDeep(values);
38733
+ var intevalTime = SAVE_TIME_INTERVAL_IN_MILLISECONDS - timeSinceLastRun;
38734
+ timeoutRef.current = setTimeout(function () {
38735
+ timeoutRef.current = null;
38736
+ var pendingValues = pendingValuesRef.current;
38737
+ if (pendingValues) {
38738
+ clearTimeout(timeoutRef.current);
38739
+ _handleSave(pendingValues);
38740
+ pendingValuesRef.current = null;
38741
+ }
38742
+ }, intevalTime);
38743
+ }
38744
+ return function () {
38745
+ if (timeoutRef.current) {
38746
+ clearTimeout(timeoutRef.current);
38747
+ }
38748
+ };
38749
+ }, [values, errors]);
38587
38750
  var inforErrors = errors.coverImage || errors.grade || errors.isbn || errors.preparedType || errors.publicationDate || errors.publisher;
38588
38751
  var contentsErrors = errors.chapters;
38589
38752
  var textbookOwnersErrors = errors.textbookOwners;
38753
+ var hasError = !_$8.isEmpty(errors);
38754
+ var isSaved = !lastEdited || _$8.isEqual(values, (_valuesTextbook$curre = valuesTextbook.current) != null ? _valuesTextbook$curre : {});
38590
38755
  return React__default.createElement(Form, null, React__default.createElement(Stack, {
38591
38756
  direction: "column",
38592
38757
  gap: 3
@@ -38674,7 +38839,45 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
38674
38839
  }), React__default.createElement(FormLabel, {
38675
38840
  htmlFor: "type",
38676
38841
  className: "text-center"
38677
- }, t$1("math"))))), React__default.createElement(Box, null, React__default.createElement(Button, {
38842
+ }, t$1("math"))))), React__default.createElement(Stack, {
38843
+ flexDirection: "row",
38844
+ gap: "8px"
38845
+ }, !!(selectedTextbook !== null && selectedTextbook !== void 0 && selectedTextbook.id) && React__default.createElement(Stack, {
38846
+ padding: "6px 12px",
38847
+ sx: {
38848
+ transition: "opacity 0.3s ease",
38849
+ opacity: saveStatus === PrintStatus.Idle && isSaved ? 0 : 1,
38850
+ pointerEvents: "none",
38851
+ gap: "8px",
38852
+ flexDirection: "row",
38853
+ justifyContent: "center",
38854
+ alignItems: "center"
38855
+ }
38856
+ }, saveStatus === PrintStatus.Saving && React__default.createElement(AiOutlineLoading3Quarters, {
38857
+ style: {
38858
+ animation: "spin 1s linear infinite"
38859
+ }
38860
+ }), saveStatus === PrintStatus.Saved && isSaved && React__default.createElement(IoCheckmark, null), saveStatus !== PrintStatus.Saving && !isSaved && React__default.createElement(Fragment$1, null, hasError ? React__default.createElement(MdError, {
38861
+ color: red[900]
38862
+ }) : React__default.createElement(FaClockRotateLeft, {
38863
+ size: "14px"
38864
+ })), React__default.createElement(Typography, {
38865
+ sx: {
38866
+ color: theme.palette.grey[700],
38867
+ fontSize: "14px",
38868
+ display: "flex",
38869
+ alignItems: "center",
38870
+ gap: 1,
38871
+ "@keyframes spin": {
38872
+ "0%": {
38873
+ transform: "rotate(0deg)"
38874
+ },
38875
+ "100%": {
38876
+ transform: "rotate(360deg)"
38877
+ }
38878
+ }
38879
+ }
38880
+ }, saveStatus === PrintStatus.Saving && t$1("saving"), saveStatus === PrintStatus.Saved && isSaved && t$1("all_changes_saved"), saveStatus !== PrintStatus.Saving && !isSaved && t$1("all_changes_are_not_saved_yet"))), React__default.createElement(Button, {
38678
38881
  type: "submit",
38679
38882
  sx: {
38680
38883
  width: "fit-content"
@@ -38781,6 +38984,7 @@ var PreparedTextbookView = function PreparedTextbookView(_ref) {
38781
38984
  isSuperAdminUser = _useTextbookManagemen.isSuperAdminUser,
38782
38985
  isAdmin = _useTextbookManagemen.isAdmin,
38783
38986
  coverImage = _useTextbookManagemen.coverImage,
38987
+ handleSaveData = _useTextbookManagemen.handleSaveData,
38784
38988
  selectedTextbook = _useTextbookManagemen.selectedTextbook,
38785
38989
  handleSubmit = _useTextbookManagemen.handleSubmit,
38786
38990
  handleUploadImage = _useTextbookManagemen.handleUploadImage;
@@ -38803,7 +39007,9 @@ var PreparedTextbookView = function PreparedTextbookView(_ref) {
38803
39007
  isAdmin: isAdmin,
38804
39008
  isSuperAdmin: isSuperAdmin,
38805
39009
  selected: selected,
39010
+ handleSaveData: handleSaveData,
38806
39011
  textbookId: textbookId,
39012
+ selectedTextbook: selectedTextbook,
38807
39013
  onChangeTab: handleChangeTab,
38808
39014
  onUploadImage: handleUploadImage,
38809
39015
  coverImage: coverImage,