touchstudy-core 0.1.130 → 0.1.132

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  export declare const customStyles: {
2
2
  control: (baseStyles: any, state: any) => any;
3
3
  input: (baseStyles: any, _: any) => any;
4
+ placeholder: (baseStyles: any, _: any) => any;
4
5
  singleValue: (baseStyles: any) => any;
5
6
  option: (baseStyles: any, state: any) => any;
6
7
  menuPortal: (base: any) => any;
@@ -19,7 +19,7 @@ interface Props extends FormikProps<TextbookRequest> {
19
19
  onOpenSubCategoryMenu: (path: string, id?: number) => void;
20
20
  onOpenCategoryMenu: (path: string) => void;
21
21
  onCloseCategoryMenu: () => void;
22
- onOpenQuestionTypeMenu: (path: string) => void;
22
+ onOpenQuestionTypeMenu: (path: string, categoryId?: number, subCategoryId?: number) => void;
23
23
  onCloseQuestionTypeMenu: () => void;
24
24
  }
25
25
  declare const ChapterBlock: FC<Props>;
@@ -17,7 +17,7 @@ interface Props extends FormikProps<TextbookRequest> {
17
17
  onOpenSubCategoryMenu: (path: string, id?: number) => void;
18
18
  onOpenCategoryMenu: (path: string) => void;
19
19
  onCloseCategoryMenu: () => void;
20
- onOpenQuestionTypeMenu: (path: string) => void;
20
+ onOpenQuestionTypeMenu: (path: string, categoryId?: number, subCategoryId?: number) => void;
21
21
  onCloseQuestionTypeMenu: () => void;
22
22
  }
23
23
  declare const ChapterBlockBody: FC<Props>;
@@ -21,7 +21,7 @@ interface Props extends FormikProps<TextbookRequest> {
21
21
  onOpenCategoryMenu: (path: string) => void;
22
22
  onCloseCategoryMenu: () => void;
23
23
  onCopiedPrevQuestionGroup: (path: string, paths: number[]) => QuestionGroupRequest | undefined;
24
- onOpenQuestionTypeMenu: (path: string) => void;
24
+ onOpenQuestionTypeMenu: (path: string, categoryId?: number, subCategoryId?: number) => void;
25
25
  onCloseQuestionTypeMenu: () => void;
26
26
  }
27
27
  declare const QuestionGroupBlock: FC<Props>;
@@ -15,7 +15,7 @@ interface Props extends FormikProps<TextbookRequest> {
15
15
  onOpenSubCategoryMenu: (path: string, id?: number) => void;
16
16
  onOpenCategoryMenu: (path: string) => void;
17
17
  onCloseCategoryMenu: () => void;
18
- onOpenQuestionTypeMenu: (path: string) => void;
18
+ onOpenQuestionTypeMenu: (path: string, categoryId?: number, subCategoryId?: number) => void;
19
19
  onCloseQuestionTypeMenu: () => void;
20
20
  }
21
21
  declare const _default: React.NamedExoticComponent<Props>;
@@ -1,3 +1,4 @@
1
1
  import { TextbookDetailResponse } from "./types";
2
- export declare const reduceToMathArticles: (textbook: any, isMath: number, isInit?: boolean) => any;
2
+ export declare const reduceToMathArticles: (textbook: any, isMath?: number | undefined) => any;
3
+ export declare const resetAllCrategoriesAndQuestionTypesBySubject: (textbook: any, subject?: any) => any;
3
4
  export declare const convertResponseToRequest: (selectedTextbook?: TextbookDetailResponse | undefined) => import("./types").TextbookRequest;
@@ -0,0 +1,6 @@
1
+ export declare const labelStyle: {
2
+ textOverflow: string;
3
+ overflowX: string;
4
+ width: string;
5
+ whiteSpace: string;
6
+ };
package/dist/index.js CHANGED
@@ -1424,6 +1424,7 @@ var subjective_answer = "주관식 정답";
1424
1424
  var current_correct_answer_entered = "현재 입력한 정답";
1425
1425
  var correct_answer_is_required = "정답은 필수입니다.";
1426
1426
  var cancel_2 = "취소하기";
1427
+ var article_required = "기사가 필요합니다";
1427
1428
  var lang_ko = {
1428
1429
  problem_solving: problem_solving,
1429
1430
  my_story: my_story,
@@ -2483,7 +2484,8 @@ var lang_ko = {
2483
2484
  subjective_answer: subjective_answer,
2484
2485
  current_correct_answer_entered: current_correct_answer_entered,
2485
2486
  correct_answer_is_required: correct_answer_is_required,
2486
- cancel_2: cancel_2
2487
+ cancel_2: cancel_2,
2488
+ article_required: article_required
2487
2489
  };
2488
2490
 
2489
2491
  var problem_solving$1 = "Problem Solving";
@@ -3566,6 +3568,7 @@ var subjective_answer$1 = "Subjective answer";
3566
3568
  var current_correct_answer_entered$1 = "Current correct answer entered";
3567
3569
  var correct_answer_is_required$1 = "Correct answer is required";
3568
3570
  var cancel_2$1 = "Cancel";
3571
+ var article_required$1 = "Article is required";
3569
3572
  var lang_en = {
3570
3573
  problem_solving: problem_solving$1,
3571
3574
  my_story: my_story$1,
@@ -4627,7 +4630,8 @@ var lang_en = {
4627
4630
  subjective_answer: subjective_answer$1,
4628
4631
  current_correct_answer_entered: current_correct_answer_entered$1,
4629
4632
  correct_answer_is_required: correct_answer_is_required$1,
4630
- cancel_2: cancel_2$1
4633
+ cancel_2: cancel_2$1,
4634
+ article_required: article_required$1
4631
4635
  };
4632
4636
 
4633
4637
  i18n__default.use(reactI18next.initReactI18next).init({
@@ -5972,6 +5976,11 @@ var customStyles = {
5972
5976
  color: styles.darker
5973
5977
  });
5974
5978
  },
5979
+ placeholder: function placeholder(baseStyles, _) {
5980
+ return _extends({}, baseStyles, {
5981
+ whiteSpace: "nowrap"
5982
+ });
5983
+ },
5975
5984
  singleValue: function singleValue(baseStyles) {
5976
5985
  return _extends({}, baseStyles, {
5977
5986
  fontSize: "14px",
@@ -5989,7 +5998,7 @@ var customStyles = {
5989
5998
  },
5990
5999
  menuPortal: function menuPortal(base) {
5991
6000
  return _extends({}, base, {
5992
- zIndex: 1
6001
+ zIndex: 99
5993
6002
  });
5994
6003
  }
5995
6004
  };
@@ -21624,7 +21633,8 @@ var UserDialog = function UserDialog(_ref) {
21624
21633
  setLoadingDefaultPassCode(true);
21625
21634
  var _temp3 = _catch(function () {
21626
21635
  return Promise.resolve(getUserDefaultPassCodeApi(parentPhoneNumber, phoneNumber, email, true)).then(function (res) {
21627
- setPassCode(res.data);
21636
+ var _res$data;
21637
+ setPassCode((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.toString());
21628
21638
  });
21629
21639
  }, function (error) {
21630
21640
  reactToastify.toast.error(getErrorMessage(t, error));
@@ -21680,6 +21690,9 @@ var UserDialog = function UserDialog(_ref) {
21680
21690
  setRoles([].concat((data === null || data === void 0 ? void 0 : data.roles) || [exports.Role.Teacher]));
21681
21691
  }
21682
21692
  }, [open]);
21693
+ React.useEffect(function () {
21694
+ getDefaultPassCode();
21695
+ }, [getValues().parentPhoneNumber, getValues().phoneNumber]);
21683
21696
  var handleUseDefaultPassCode = function handleUseDefaultPassCode() {
21684
21697
  setUseDefaultPassCode(true);
21685
21698
  setPassCode(undefined);
@@ -21908,16 +21921,9 @@ var UserDialog = function UserDialog(_ref) {
21908
21921
  color: theme.palette.success.main,
21909
21922
  fontWeight: 600
21910
21923
  }
21911
- }, defaultPassCodeValue), React__default.createElement(material.Box, null, isLoadingDefaultPassCode ? React__default.createElement(material.CircularProgress, {
21924
+ }, defaultPassCodeValue), React__default.createElement(material.Box, null, isLoadingDefaultPassCode && React__default.createElement(material.CircularProgress, {
21912
21925
  size: "1rem"
21913
- }) : React__default.createElement(material.IconButton, {
21914
- className: "bg-success",
21915
- onClick: getDefaultPassCode,
21916
- disabled: disabled
21917
- }, React__default.createElement(fa6.FaRotateRight, {
21918
- color: "#FFF",
21919
- size: 10
21920
- }))))), React__default.createElement(material.FormControlLabel, {
21926
+ })))), React__default.createElement(material.FormControlLabel, {
21921
21927
  control: React__default.createElement(material.Radio, {
21922
21928
  checked: !useDefaultPassCode,
21923
21929
  onChange: function onChange() {
@@ -27472,6 +27478,9 @@ var preparedTextbookSchema = function preparedTextbookSchema(t) {
27472
27478
  },
27473
27479
  then: function then(schema) {
27474
27480
  return schema.min(1, t("category_required"));
27481
+ },
27482
+ otherwise: function otherwise(schema) {
27483
+ return schema.min(1, t("article_required"));
27475
27484
  }
27476
27485
  }),
27477
27486
  questions: yup.array().of(yup.object())
@@ -27490,7 +27499,17 @@ var preparedTextbookSchema = function preparedTextbookSchema(t) {
27490
27499
  title: yup.string().notRequired(),
27491
27500
  author: yup.string().notRequired(),
27492
27501
  subject: yup.string().notRequired()
27493
- })),
27502
+ })).when("$type", {
27503
+ is: function is(type) {
27504
+ return type === 2;
27505
+ },
27506
+ then: function then(schema) {
27507
+ return schema.min(1, t("category_required"));
27508
+ },
27509
+ otherwise: function otherwise(schema) {
27510
+ return schema.min(1, t("article_required"));
27511
+ }
27512
+ }),
27494
27513
  questions: yup.array().of(yup.object())
27495
27514
  }))
27496
27515
  }))
@@ -27726,6 +27745,14 @@ var ArticleBlock = function ArticleBlock(_ref) {
27726
27745
  var handleOpenCategoryMenu = function handleOpenCategoryMenu() {
27727
27746
  onOpenCategoryMenu(path + ".categories[0]");
27728
27747
  };
27748
+ var handleChangeCategory = function handleChangeCategory(val) {
27749
+ setFieldValue(path + ".categoryOptions", [val]);
27750
+ setFieldValue(path + ".categories", [val === null || val === void 0 ? void 0 : val.value]);
27751
+ };
27752
+ var handleChangeSubCategory = function handleChangeSubCategory(val) {
27753
+ setFieldValue(path + ".categoryOptions[1]", [val]);
27754
+ setFieldValue(path + ".categories[1]", [val === null || val === void 0 ? void 0 : val.value]);
27755
+ };
27729
27756
  return React__default.createElement(material.Stack, {
27730
27757
  direction: "row",
27731
27758
  alignItems: "center",
@@ -27792,10 +27819,7 @@ var ArticleBlock = function ArticleBlock(_ref) {
27792
27819
  onMenuOpen: handleOpenCategoryMenu,
27793
27820
  onMenuClose: onCloseCategoryMenu
27794
27821
  },
27795
- onChange: function onChange(val) {
27796
- setFieldValue(path + ".categories[0]", val === null || val === void 0 ? void 0 : val.value);
27797
- setFieldValue(path + ".categoryOptions[0]", val);
27798
- },
27822
+ onChange: handleChangeCategory,
27799
27823
  placeholder: t("select_category")
27800
27824
  });
27801
27825
  }
@@ -27832,10 +27856,7 @@ var ArticleBlock = function ArticleBlock(_ref) {
27832
27856
  onMenuOpen: handleOpenSubCategoryMenu,
27833
27857
  onMenuClose: onCloseCategoryMenu
27834
27858
  },
27835
- onChange: function onChange(val) {
27836
- setFieldValue(path + ".categories[1]", val === null || val === void 0 ? void 0 : val.value);
27837
- setFieldValue(path + ".categoryOptions[1]", val);
27838
- },
27859
+ onChange: handleChangeSubCategory,
27839
27860
  isDisabled: !data.categories[0],
27840
27861
  placeholder: t("select_category")
27841
27862
  });
@@ -27931,15 +27952,14 @@ var ArticleBlock$1 = React.memo(ArticleBlock, isEqual);
27931
27952
 
27932
27953
  var styles$9 = {"question":"_1_ONI","question-article":"_2FdrR","question-title":"_3mgRf","question-label":"_2h0kA","question-input":"_exAl-","question-btn":"_2ksp8"};
27933
27954
 
27955
+ var labelStyle = {
27956
+ textOverflow: "ellipsis",
27957
+ overflowX: "hidden",
27958
+ width: "100%",
27959
+ whiteSpace: "nowrap"
27960
+ };
27961
+
27934
27962
  var _excluded$e = ["onChange"];
27935
- var answerTypeOptions = Object.keys(exports.QuestionAnswerType).filter(function (key) {
27936
- return Number.isNaN(+key);
27937
- }).map(function (label, index) {
27938
- return {
27939
- label: i18n.t(label.toLowerCase()),
27940
- value: index
27941
- };
27942
- });
27943
27963
  var BpIcon$1 = material.styled("span")(function (_ref) {
27944
27964
  var theme = _ref.theme;
27945
27965
  return {
@@ -28010,13 +28030,13 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28010
28030
  }, React__default.createElement(material.FormLabel, {
28011
28031
  htmlFor: "textual_answer",
28012
28032
  className: styles$9["question-label"] + " form-label"
28013
- }, i18n.t("textual_answer")), React__default.createElement(formik.Field, {
28033
+ }, t("textual_answer")), React__default.createElement(formik.Field, {
28014
28034
  name: path + ".textualAnswer",
28015
28035
  render: function render(_ref3) {
28016
28036
  var field = _ref3.field;
28017
28037
  return React__default.createElement(material.TextField, Object.assign({}, field, {
28018
28038
  size: "small",
28019
- placeholder: i18n.t("textual_answer")
28039
+ placeholder: t("textual_answer")
28020
28040
  }));
28021
28041
  }
28022
28042
  }));
@@ -28042,7 +28062,7 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28042
28062
  return handleCheckMultiChoice(+e.target.value);
28043
28063
  }
28044
28064
  }),
28045
- label: i18n.t("number_question", {
28065
+ label: t("number_question", {
28046
28066
  number: i
28047
28067
  })
28048
28068
  });
@@ -28078,7 +28098,7 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28078
28098
  checkedIcon: React__default.createElement(BpCheckedIcon$1, null),
28079
28099
  icon: React__default.createElement(BpIcon$1, null)
28080
28100
  }),
28081
- label: i18n.t("number_question", {
28101
+ label: t("number_question", {
28082
28102
  number: i
28083
28103
  })
28084
28104
  });
@@ -28087,10 +28107,27 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28087
28107
  return null;
28088
28108
  }
28089
28109
  };
28090
- console.log({
28091
- isLoadingQuestionTypes: isLoadingQuestionTypes,
28092
- path: path
28110
+ var handleChangeQuestionType = function handleChangeQuestionType(val) {
28111
+ if (typeof (val === null || val === void 0 ? void 0 : val.value) === "string") {
28112
+ setFieldValue(path + ".questionTypeId", 0);
28113
+ setFieldValue(path + ".questionTypeName", val === null || val === void 0 ? void 0 : val.value);
28114
+ } else {
28115
+ setFieldValue(path + ".questionTypeId", (val === null || val === void 0 ? void 0 : val.value) || 0);
28116
+ }
28117
+ setFieldValue(path + ".questionType", val);
28118
+ };
28119
+ var _useTranslation = reactI18next.useTranslation(),
28120
+ t = _useTranslation.t;
28121
+ var answerTypeOptions = Object.keys(exports.QuestionAnswerType).filter(function (key) {
28122
+ return Number.isNaN(+key);
28123
+ }).map(function (label, index) {
28124
+ return {
28125
+ label: t(label.toLowerCase()),
28126
+ value: index
28127
+ };
28093
28128
  });
28129
+ var theme = material.useTheme();
28130
+ var isTabletUp = material.useMediaQuery(theme.breakpoints.up('lg'));
28094
28131
  return React__default.createElement(material.Stack, {
28095
28132
  direction: "row",
28096
28133
  alignItems: "center",
@@ -28099,11 +28136,12 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28099
28136
  }, React__default.createElement(material.Stack, {
28100
28137
  direction: "row",
28101
28138
  alignItems: "center",
28139
+ minWidth: "50%",
28102
28140
  flexGrow: 1
28103
28141
  }, React__default.createElement(material.Box, null, React__default.createElement(material.Box, {
28104
28142
  className: styles$9["question-title"] + " me-2 text-nowrap",
28105
28143
  sx: questionTitleStyle
28106
- }, i18n.t("problem_number_question", {
28144
+ }, t("problem_number_question", {
28107
28145
  number: data.questionOrder + 1
28108
28146
  }))), React__default.createElement(material.Box, {
28109
28147
  flexGrow: 1
@@ -28113,12 +28151,13 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28113
28151
  }, React__default.createElement(material.FormControl, {
28114
28152
  sx: {
28115
28153
  flexGrow: 1,
28116
- width: "168px"
28154
+ width: isTabletUp ? "120px" : "100px"
28117
28155
  }
28118
28156
  }, React__default.createElement(material.FormLabel, {
28119
28157
  htmlFor: "score",
28120
- className: styles$9["question-label"] + " form-label"
28121
- }, i18n.t("score")), React__default.createElement(formik.Field, {
28158
+ className: styles$9["question-label"] + " form-label",
28159
+ sx: labelStyle
28160
+ }, t("score")), React__default.createElement(formik.Field, {
28122
28161
  name: path + ".score",
28123
28162
  render: function render(_ref4) {
28124
28163
  var field = _ref4.field;
@@ -28132,12 +28171,13 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28132
28171
  })), isMath && React__default.createElement(material.FormGroup, {
28133
28172
  sx: {
28134
28173
  flexGrow: 1,
28135
- width: "240px"
28174
+ width: isTabletUp ? "180px" : "120px"
28136
28175
  }
28137
28176
  }, React__default.createElement(material.FormLabel, {
28138
28177
  htmlFor: "type",
28139
- className: styles$9["question-label"] + " form-label"
28140
- }, i18n.t("type")), React__default.createElement(formik.Field, {
28178
+ className: styles$9["question-label"] + " form-label",
28179
+ sx: labelStyle
28180
+ }, t("type")), React__default.createElement(formik.Field, {
28141
28181
  name: path + ".questionTypeId",
28142
28182
  render: function render(_ref5) {
28143
28183
  var _ref5$field = _ref5.field,
@@ -28149,26 +28189,20 @@ var QuestionBlock = function QuestionBlock(_ref2) {
28149
28189
  isLoading: optionKey === path + ".questionTypeId" ? isLoadingQuestionTypes : false,
28150
28190
  onMenuOpen: handleOpenQuestionTypeMenu,
28151
28191
  onMenuClose: onCloseQuestionTypeMenu,
28152
- onChange: function onChange(val) {
28153
- if (typeof (val === null || val === void 0 ? void 0 : val.value) === "string") {
28154
- setFieldValue(path + ".questionTypeId", 0);
28155
- setFieldValue(path + ".questionTypeName", val === null || val === void 0 ? void 0 : val.value);
28156
- } else {
28157
- setFieldValue(path + ".questionTypeId", (val === null || val === void 0 ? void 0 : val.value) || 0);
28158
- }
28159
- setFieldValue(path + ".questionType", val);
28160
- }
28192
+ onChange: handleChangeQuestionType,
28193
+ isClearable: true
28161
28194
  }));
28162
28195
  }
28163
28196
  })), React__default.createElement(material.FormGroup, {
28164
28197
  sx: {
28165
28198
  flexGrow: 1,
28166
- width: "240px"
28199
+ width: isTabletUp ? "180px" : "100px"
28167
28200
  }
28168
28201
  }, React__default.createElement(material.FormLabel, {
28169
28202
  htmlFor: "question_answer_type",
28170
- className: styles$9["question-label"] + " form-label"
28171
- }, i18n.t("question_answer_type")), React__default.createElement(formik.Field, {
28203
+ className: styles$9["question-label"] + " form-label",
28204
+ sx: labelStyle
28205
+ }, t("question_answer_type")), React__default.createElement(formik.Field, {
28172
28206
  name: path + ".questionAnswerType",
28173
28207
  render: function render(_ref6) {
28174
28208
  var field = _ref6.field;
@@ -28196,6 +28230,7 @@ var QuestionBlock$1 = React.memo(QuestionBlock, isEqual$1);
28196
28230
 
28197
28231
  var _excluded$f = ["data", "path", "isMath", "open", "isLoadingCategories", "isLoadingQuestionTypes", "optionKey", "categories", "questionTypes", "onDelete", "onOpenSubCategoryMenu", "onOpenCategoryMenu", "onCloseCategoryMenu", "onCloseQuestionTypeMenu", "onOpenQuestionTypeMenu"];
28198
28232
  var QuestionGroupBlockBody = function QuestionGroupBlockBody(_ref) {
28233
+ var _data$articles$3, _data$articles$3$cate, _data$articles$4, _data$articles$4$cate;
28199
28234
  var data = _ref.data,
28200
28235
  path = _ref.path,
28201
28236
  isMath = _ref.isMath,
@@ -28216,6 +28251,10 @@ var QuestionGroupBlockBody = function QuestionGroupBlockBody(_ref) {
28216
28251
  var articles = data.articles,
28217
28252
  questions = data.questions;
28218
28253
  var blockErrors = _.get(errors, path);
28254
+ var handleOpenQuestionTypeMenu = React.useCallback(function (key) {
28255
+ var _data$articles$, _data$articles$$categ, _data$articles$2, _data$articles$2$cate;
28256
+ onOpenQuestionTypeMenu(key, (_data$articles$ = data.articles[0]) === null || _data$articles$ === void 0 ? void 0 : (_data$articles$$categ = _data$articles$.categories) === null || _data$articles$$categ === void 0 ? void 0 : _data$articles$$categ[0], (_data$articles$2 = data.articles[0]) === null || _data$articles$2 === void 0 ? void 0 : (_data$articles$2$cate = _data$articles$2.categories) === null || _data$articles$2$cate === void 0 ? void 0 : _data$articles$2$cate[1]);
28257
+ }, [(_data$articles$3 = data.articles[0]) === null || _data$articles$3 === void 0 ? void 0 : (_data$articles$3$cate = _data$articles$3.categories) === null || _data$articles$3$cate === void 0 ? void 0 : _data$articles$3$cate[0], (_data$articles$4 = data.articles[0]) === null || _data$articles$4 === void 0 ? void 0 : (_data$articles$4$cate = _data$articles$4.categories) === null || _data$articles$4$cate === void 0 ? void 0 : _data$articles$4$cate[1]]);
28219
28258
  return React__default.createElement(formik.FieldArray, {
28220
28259
  name: path + ".articles",
28221
28260
  render: function render(arrayHelpers) {
@@ -28277,7 +28316,7 @@ var QuestionGroupBlockBody = function QuestionGroupBlockBody(_ref) {
28277
28316
  questionTypes: questionTypes,
28278
28317
  isLoadingQuestionTypes: isLoadingQuestionTypes,
28279
28318
  optionKey: optionKey,
28280
- onOpenQuestionTypeMenu: onOpenQuestionTypeMenu,
28319
+ onOpenQuestionTypeMenu: handleOpenQuestionTypeMenu,
28281
28320
  onCloseQuestionTypeMenu: onCloseQuestionTypeMenu
28282
28321
  }, formikProps));
28283
28322
  }
@@ -28399,6 +28438,14 @@ var QuestionGroupBlock = function QuestionGroupBlock(_ref) {
28399
28438
  setFieldValue(path + ".articles[0].categoryOptions", (_questionGroup$articl2 = questionGroup.articles[0]) === null || _questionGroup$articl2 === void 0 ? void 0 : _questionGroup$articl2.categoryOptions);
28400
28439
  }
28401
28440
  };
28441
+ var handleChangeCategory = function handleChangeCategory(val) {
28442
+ setFieldValue(path + ".articles[0].categoryOptions", [val]);
28443
+ setFieldValue(path + ".articles[0].categories", [val === null || val === void 0 ? void 0 : val.value]);
28444
+ };
28445
+ var handleChangeSubCategory = function handleChangeSubCategory(val) {
28446
+ setFieldValue(path + ".articles[0].categories[1]", val === null || val === void 0 ? void 0 : val.value);
28447
+ setFieldValue(path + ".articles[0].categoryOptions[1]", val);
28448
+ };
28402
28449
  var summary = open ? "" : [t("number_questions", {
28403
28450
  n: data.questionCount
28404
28451
  }), (_data$articles$2 = data.articles[0]) === null || _data$articles$2 === void 0 ? void 0 : (_data$articles$2$cate = _data$articles$2.categoryOptions) === null || _data$articles$2$cate === void 0 ? void 0 : (_data$articles$2$cate2 = _data$articles$2$cate[0]) === null || _data$articles$2$cate2 === void 0 ? void 0 : _data$articles$2$cate2.label, (_data$articles$3 = data.articles[0]) === null || _data$articles$3 === void 0 ? void 0 : (_data$articles$3$cate = _data$articles$3.categoryOptions) === null || _data$articles$3$cate === void 0 ? void 0 : (_data$articles$3$cate2 = _data$articles$3$cate[1]) === null || _data$articles$3$cate2 === void 0 ? void 0 : _data$articles$3$cate2.label, isMath ? data.questions.map(function (i) {
@@ -28511,10 +28558,7 @@ var QuestionGroupBlock = function QuestionGroupBlock(_ref) {
28511
28558
  onMenuOpen: handleOpenCategoryMenu,
28512
28559
  onMenuClose: onCloseCategoryMenu
28513
28560
  },
28514
- onChange: function onChange(val) {
28515
- setFieldValue(path + ".articles[0].categories[0]", val === null || val === void 0 ? void 0 : val.value);
28516
- setFieldValue(path + ".articles[0].categoryOptions[0]", val);
28517
- },
28561
+ onChange: handleChangeCategory,
28518
28562
  placeholder: t("select_category")
28519
28563
  });
28520
28564
  }
@@ -28549,14 +28593,12 @@ var QuestionGroupBlock = function QuestionGroupBlock(_ref) {
28549
28593
  optionValue: field.value,
28550
28594
  options: categories,
28551
28595
  rest: {
28596
+ isClearable: true,
28552
28597
  isLoading: optionKey === path + ".articles[0].categories[1]" ? isLoadingCategories : false,
28553
28598
  onMenuOpen: handleOpenSubCategoryMenu,
28554
28599
  onMenuClose: onCloseCategoryMenu
28555
28600
  },
28556
- onChange: function onChange(val) {
28557
- setFieldValue(path + ".articles[0].categories[1]", val === null || val === void 0 ? void 0 : val.value);
28558
- setFieldValue(path + ".articles[0].categoryOptions[1]", val);
28559
- },
28601
+ onChange: handleChangeSubCategory,
28560
28602
  isDisabled: isDisabled || !((_data$articles$4 = data.articles[0]) !== null && _data$articles$4 !== void 0 && (_data$articles$4$cate = _data$articles$4.categories) !== null && _data$articles$4$cate !== void 0 && _data$articles$4$cate[0]),
28561
28603
  placeholder: t("select_category")
28562
28604
  });
@@ -28846,7 +28888,7 @@ var ChapterBlock = function ChapterBlock(_ref) {
28846
28888
  e.stopPropagation();
28847
28889
  onDelete("" + t("are_you_sure_you_want_to_delete_the_chapter", {
28848
28890
  chapter: title
28849
- }), title, path.replace(/\[(\d+)\]$/, ''), expandedIndex);
28891
+ }), title, path.replace(/\[(\d+)\]$/, ""), expandedIndex);
28850
28892
  };
28851
28893
  var pageNameError = _.get(errors, path + ".name");
28852
28894
  var pageFromError = _.get(errors, path + ".pageFrom");
@@ -29289,8 +29331,8 @@ var useTextbookOptions = function useTextbookOptions(subjectId, isMath, filter,
29289
29331
  var questionTypeFilters = getOptionFilter();
29290
29332
  return Promise.resolve(getQuestionTypesApi(isSuperAdmin, _extends({}, questionTypeFilters, {
29291
29333
  subjectId: subjectId,
29292
- parentCategorId: subCategoryId,
29293
- rootParentCategorId: categoryId,
29334
+ parentCategoryId: subCategoryId,
29335
+ rootParentCategoryId: categoryId,
29294
29336
  textSearch: (_inputRef$current7 = inputRef.current) === null || _inputRef$current7 === void 0 ? void 0 : _inputRef$current7.value
29295
29337
  }))).then(function (res) {
29296
29338
  setQuestionTypes(res.data.items.map(function (i) {
@@ -30084,19 +30126,35 @@ var TextbookOwnersTab = function TextbookOwnersTab(_ref) {
30084
30126
  }));
30085
30127
  };
30086
30128
 
30087
- var _reduceToMathArticles = function reduceToMathArticles(textbook, isMath, isInit) {
30088
- if (isInit === void 0) {
30089
- isInit = true;
30090
- }
30091
- var values = isInit ? _.cloneDeep(textbook) : textbook;
30092
- if (isInit) values.type = isMath;
30129
+ var _reduceToMathArticles = function reduceToMathArticles(textbook, isMath) {
30130
+ var values = isMath !== undefined ? _.cloneDeep(textbook) : textbook;
30131
+ if (isMath !== undefined) values.type = isMath;
30093
30132
  for (var key in values) {
30094
30133
  if (values.hasOwnProperty(key)) {
30095
30134
  if (key === "articles") {
30096
30135
  var _values$key;
30097
30136
  values[key] = (_values$key = values[key]) !== null && _values$key !== void 0 && _values$key.length ? [values[key][0]] : [DEFAULT_ARTICLE];
30098
30137
  } else if (typeof values[key] === "object" && values[key] !== null) {
30099
- _reduceToMathArticles(values[key], isMath, false);
30138
+ _reduceToMathArticles(values[key]);
30139
+ }
30140
+ }
30141
+ }
30142
+ return values;
30143
+ };
30144
+ var _resetAllCrategoriesAndQuestionTypesBySubject = function resetAllCrategoriesAndQuestionTypesBySubject(textbook, subject) {
30145
+ var values = subject ? _.cloneDeep(textbook) : textbook;
30146
+ if (subject) {
30147
+ values.subjectId = subject === null || subject === void 0 ? void 0 : subject.value;
30148
+ values.subject = subject;
30149
+ }
30150
+ for (var key in values) {
30151
+ if (values.hasOwnProperty(key)) {
30152
+ if (key === "categories" || key === "categoryOptions") {
30153
+ values[key] = [];
30154
+ } else if (key === "questionType" || key === "questionTypeId") {
30155
+ values[key] = null;
30156
+ } else if (typeof values[key] === "object" && values[key] !== null) {
30157
+ _resetAllCrategoriesAndQuestionTypesBySubject(values[key]);
30100
30158
  }
30101
30159
  }
30102
30160
  }
@@ -30225,8 +30283,7 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
30225
30283
  errors = formikProps.errors,
30226
30284
  dirty = formikProps.dirty,
30227
30285
  submitCount = formikProps.submitCount,
30228
- setValues = formikProps.setValues,
30229
- setFieldValue = formikProps.setFieldValue;
30286
+ setValues = formikProps.setValues;
30230
30287
  React.useEffect(function () {
30231
30288
  var handleBeforeUnload = function handleBeforeUnload(event) {
30232
30289
  var message = i18n.t("are_you_sure_you_want_to_quit_yours_changes_may_not_be_saved");
@@ -30244,8 +30301,8 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
30244
30301
  setValues(newValues);
30245
30302
  };
30246
30303
  var handleChangeSubject = function handleChangeSubject(val) {
30247
- setFieldValue("subject", val);
30248
- setFieldValue("subjectId", val === null || val === void 0 ? void 0 : val.value);
30304
+ var newValues = _resetAllCrategoriesAndQuestionTypesBySubject(values, val);
30305
+ setValues(newValues);
30249
30306
  };
30250
30307
  var inforErrors = errors.coverImage || errors.grade || errors.isbn || errors.preparedType || errors.publicationDate || errors.publisher;
30251
30308
  var contentsErrors = errors.chapters;
@@ -30330,9 +30387,6 @@ var PreparedTextbookForm = function PreparedTextbookForm(_ref) {
30330
30387
  },
30331
30388
  variant: "contained",
30332
30389
  onClick: function onClick() {
30333
- console.log({
30334
- errors: errors
30335
- });
30336
30390
  if (!_.isEmpty(errors)) {
30337
30391
  reactToastify.toast.error(i18n.t("please_fill_in_the_blank_fields"));
30338
30392
  }