analytica-frontend-lib 1.3.98 → 1.3.99

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.
package/dist/index.js CHANGED
@@ -20852,7 +20852,7 @@ var CreateActivity = ({
20852
20852
  const saveDraft = (0, import_react55.useCallback)(
20853
20853
  async (typeOverride, customTitle) => {
20854
20854
  if (!validateSaveConditions()) {
20855
- return draftId || void 0;
20855
+ return typeOverride ? void 0 : draftId || void 0;
20856
20856
  }
20857
20857
  setIsSaving(true);
20858
20858
  try {
@@ -20918,12 +20918,21 @@ var CreateActivity = ({
20918
20918
  setIsSavingModel(true);
20919
20919
  try {
20920
20920
  setIsSaveModelModalOpen(false);
20921
- await saveDraft("MODELO" /* MODELO */, title);
20921
+ const savedId = await saveDraft("MODELO" /* MODELO */, title);
20922
+ if (savedId) {
20923
+ addToast({
20924
+ title: "Modelo salvo com sucesso",
20925
+ description: "O modelo da atividade est\xE1 dispon\xEDvel para reutiliza\xE7\xE3o.",
20926
+ variant: "solid",
20927
+ action: "success",
20928
+ position: "top-right"
20929
+ });
20930
+ }
20922
20931
  } finally {
20923
20932
  setIsSavingModel(false);
20924
20933
  }
20925
20934
  },
20926
- [saveDraft]
20935
+ [saveDraft, addToast]
20927
20936
  );
20928
20937
  const getRecommendedClassEndpoint = (0, import_react55.useCallback)(
20929
20938
  (lessonDraftId) => {
@@ -24169,6 +24178,8 @@ var RecommendedLessonCreate = ({
24169
24178
  const [lastSavedAt, setLastSavedAt] = (0, import_react65.useState)(null);
24170
24179
  const [isSaving, setIsSaving] = (0, import_react65.useState)(false);
24171
24180
  const [isSendModalOpen, setIsSendModalOpen] = (0, import_react65.useState)(false);
24181
+ const [isSaveModelModalOpen, setIsSaveModelModalOpen] = (0, import_react65.useState)(false);
24182
+ const [isSavingModel, setIsSavingModel] = (0, import_react65.useState)(false);
24172
24183
  const [categories, setCategories] = (0, import_react65.useState)([]);
24173
24184
  const [isSendingLesson, setIsSendingLesson] = (0, import_react65.useState)(false);
24174
24185
  const hasFirstSaveBeenDone = (0, import_react65.useRef)(false);
@@ -24638,50 +24649,95 @@ var RecommendedLessonCreate = ({
24638
24649
  },
24639
24650
  [lessons, appliedFilters, onSaveModel, setSearchParams]
24640
24651
  );
24641
- const saveDraft = (0, import_react65.useCallback)(async () => {
24642
- if (!validateSaveConditions()) {
24643
- return;
24644
- }
24645
- setIsSaving(true);
24646
- try {
24647
- const payload = createDraftPayload();
24648
- if (draftId) {
24649
- await updateExistingDraft(payload);
24650
- return;
24652
+ const saveDraft = (0, import_react65.useCallback)(
24653
+ async (typeOverride, customTitle) => {
24654
+ if (!validateSaveConditions()) {
24655
+ return typeOverride ? void 0 : draftId || void 0;
24651
24656
  }
24652
- const response = await apiClient.post(
24653
- "/recommended-class/drafts",
24654
- payload
24655
- );
24656
- hasFirstSaveBeenDone.current = true;
24657
- const savedDraft = extractDraftFromResponse(response);
24658
- updateStateAfterSave(savedDraft, response?.data, true);
24659
- } catch (error) {
24660
- console.error("Error saving draft:", error);
24661
- const errorMessage = error instanceof Error ? error.message : "Ocorreu um erro ao salvar o rascunho. Tente novamente.";
24662
- addToast({
24663
- title: "Erro ao salvar rascunho",
24664
- description: errorMessage,
24665
- variant: "solid",
24666
- action: "warning",
24667
- position: "top-right"
24668
- });
24669
- } finally {
24670
- setIsSaving(false);
24671
- }
24672
- }, [
24673
- validateSaveConditions,
24674
- createDraftPayload,
24675
- draftId,
24676
- updateExistingDraft,
24677
- apiClient,
24678
- extractDraftFromResponse,
24679
- updateStateAfterSave,
24680
- addToast
24681
- ]);
24682
- const handleSaveModel = (0, import_react65.useCallback)(async () => {
24683
- setDraftType("MODELO" /* MODELO */);
24657
+ setIsSaving(true);
24658
+ try {
24659
+ let payload = createDraftPayload();
24660
+ if (typeOverride) {
24661
+ const subjectId = appliedFilters?.subjectIds?.[0];
24662
+ if (!subjectId) {
24663
+ throw new Error("Subject ID n\xE3o encontrado");
24664
+ }
24665
+ const trimmedCustomTitle = customTitle?.trim();
24666
+ const title = trimmedCustomTitle && trimmedCustomTitle.length > 0 ? trimmedCustomTitle : generateTitle2(typeOverride, subjectId, knowledgeAreas, lessons);
24667
+ payload = {
24668
+ ...payload,
24669
+ type: typeOverride,
24670
+ title
24671
+ };
24672
+ }
24673
+ if (draftId) {
24674
+ await updateExistingDraft(payload);
24675
+ return draftId;
24676
+ }
24677
+ const response = await apiClient.post(
24678
+ "/recommended-class/drafts",
24679
+ payload
24680
+ );
24681
+ hasFirstSaveBeenDone.current = true;
24682
+ const savedDraft = extractDraftFromResponse(response);
24683
+ updateStateAfterSave(savedDraft, response?.data, true);
24684
+ return savedDraft.id;
24685
+ } catch (error) {
24686
+ console.error("Error saving draft:", error);
24687
+ const errorMessage = error instanceof Error ? error.message : "Ocorreu um erro ao salvar o rascunho. Tente novamente.";
24688
+ addToast({
24689
+ title: "Erro ao salvar rascunho",
24690
+ description: errorMessage,
24691
+ variant: "solid",
24692
+ action: "warning",
24693
+ position: "top-right"
24694
+ });
24695
+ return void 0;
24696
+ } finally {
24697
+ setIsSaving(false);
24698
+ }
24699
+ },
24700
+ [
24701
+ validateSaveConditions,
24702
+ createDraftPayload,
24703
+ draftId,
24704
+ updateExistingDraft,
24705
+ apiClient,
24706
+ extractDraftFromResponse,
24707
+ updateStateAfterSave,
24708
+ addToast,
24709
+ appliedFilters,
24710
+ knowledgeAreas,
24711
+ lessons
24712
+ ]
24713
+ );
24714
+ const handleSaveModel = (0, import_react65.useCallback)(() => {
24715
+ setIsSaveModelModalOpen(true);
24684
24716
  }, []);
24717
+ const handleConfirmSaveModel = (0, import_react65.useCallback)(
24718
+ async (title) => {
24719
+ setIsSavingModel(true);
24720
+ try {
24721
+ setIsSaveModelModalOpen(false);
24722
+ const savedId = await saveDraft(
24723
+ "MODELO" /* MODELO */,
24724
+ title
24725
+ );
24726
+ if (savedId) {
24727
+ addToast({
24728
+ title: "Modelo salvo com sucesso",
24729
+ description: "O modelo da aula est\xE1 dispon\xEDvel para reutiliza\xE7\xE3o.",
24730
+ variant: "solid",
24731
+ action: "success",
24732
+ position: "top-right"
24733
+ });
24734
+ }
24735
+ } finally {
24736
+ setIsSavingModel(false);
24737
+ }
24738
+ },
24739
+ [saveDraft, addToast]
24740
+ );
24685
24741
  (0, import_react65.useEffect)(() => {
24686
24742
  if (recommendedLesson?.selectedLessons && recommendedLesson.selectedLessons.length > 0) {
24687
24743
  setLoadingInitialLessons(true);
@@ -24755,14 +24811,6 @@ var RecommendedLessonCreate = ({
24755
24811
  }
24756
24812
  };
24757
24813
  }, [lessons, appliedFilters, draftType, loadingInitialLessons]);
24758
- (0, import_react65.useEffect)(() => {
24759
- if (draftType === "MODELO" /* MODELO */ && hasFirstSaveBeenDone.current) {
24760
- if (saveTimeoutRef.current) {
24761
- clearTimeout(saveTimeoutRef.current);
24762
- }
24763
- saveDraftRef.current();
24764
- }
24765
- }, [draftType]);
24766
24814
  const handleAddLesson = (0, import_react65.useCallback)((lesson) => {
24767
24815
  setLessons((prev) => {
24768
24816
  if (prev.some((l) => l.id === lesson.id)) {
@@ -25061,6 +25109,15 @@ var RecommendedLessonCreate = ({
25061
25109
  ) })
25062
25110
  ] })
25063
25111
  ),
25112
+ /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
25113
+ SaveActivityModelModal,
25114
+ {
25115
+ isOpen: isSaveModelModalOpen,
25116
+ onClose: () => setIsSaveModelModalOpen(false),
25117
+ onConfirm: handleConfirmSaveModel,
25118
+ isLoading: isSavingModel
25119
+ }
25120
+ ),
25064
25121
  /* @__PURE__ */ (0, import_jsx_runtime107.jsx)(
25065
25122
  SendLessonModal_default,
25066
25123
  {