analytica-frontend-lib 1.1.91 → 1.1.93

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.mjs CHANGED
@@ -8331,7 +8331,6 @@ var DownloadButton = ({
8331
8331
  await new Promise((resolve) => setTimeout(resolve, 200));
8332
8332
  }
8333
8333
  } catch (error) {
8334
- console.error(`Erro ao baixar ${item.label}:`, error);
8335
8334
  onDownloadError?.(
8336
8335
  item.type,
8337
8336
  error instanceof Error ? error : new Error(`Falha ao baixar ${item.label}`)
@@ -9880,7 +9879,7 @@ var HeaderAlternative = forwardRef19(
9880
9879
  );
9881
9880
 
9882
9881
  // src/components/Auth/zustandAuthAdapter.ts
9883
- function createZustandAuthAdapter(useAuthStore) {
9882
+ function createZustandAuthAdapter(useAuthStore2) {
9884
9883
  return {
9885
9884
  /**
9886
9885
  * Check if the user is authenticated based on sessionInfo and tokens
@@ -9888,7 +9887,7 @@ function createZustandAuthAdapter(useAuthStore) {
9888
9887
  * @returns {Promise<boolean>} Promise that resolves to authentication status
9889
9888
  */
9890
9889
  checkAuth: async () => {
9891
- const { sessionInfo, tokens } = useAuthStore.getState();
9890
+ const { sessionInfo, tokens } = useAuthStore2.getState();
9892
9891
  return Boolean(sessionInfo && tokens);
9893
9892
  },
9894
9893
  /**
@@ -9896,26 +9895,26 @@ function createZustandAuthAdapter(useAuthStore) {
9896
9895
  *
9897
9896
  * @returns {unknown} Current user data from the store
9898
9897
  */
9899
- getUser: () => useAuthStore.getState().user,
9898
+ getUser: () => useAuthStore2.getState().user,
9900
9899
  /**
9901
9900
  * Get the current session information from the store
9902
9901
  *
9903
9902
  * @returns {unknown} Current session info from the store
9904
9903
  */
9905
- getSessionInfo: () => useAuthStore.getState().sessionInfo,
9904
+ getSessionInfo: () => useAuthStore2.getState().sessionInfo,
9906
9905
  /**
9907
9906
  * Get the current authentication tokens from the store
9908
9907
  *
9909
9908
  * @returns {unknown} Current tokens from the store
9910
9909
  */
9911
- getTokens: () => useAuthStore.getState().tokens,
9910
+ getTokens: () => useAuthStore2.getState().tokens,
9912
9911
  /**
9913
9912
  * Sign out the user by calling the store's signOut function if available
9914
9913
  *
9915
9914
  * @returns {void}
9916
9915
  */
9917
9916
  signOut: () => {
9918
- const signOutFn = useAuthStore.getState().signOut;
9917
+ const signOutFn = useAuthStore2.getState().signOut;
9919
9918
  if (typeof signOutFn === "function") signOutFn();
9920
9919
  }
9921
9920
  };
@@ -10215,7 +10214,6 @@ var useQuizStore = create9()(
10215
10214
  const activityId = quiz.id;
10216
10215
  const userId = get().getUserId();
10217
10216
  if (!userId || userId === "") {
10218
- console.warn("selectAnswer called before userId is set");
10219
10217
  return;
10220
10218
  }
10221
10219
  const question = quiz.questions.find((q) => q.id === questionId);
@@ -10249,7 +10247,6 @@ var useQuizStore = create9()(
10249
10247
  const activityId = quiz.id;
10250
10248
  const userId = get().getUserId();
10251
10249
  if (!userId || userId === "") {
10252
- console.warn("selectMultipleAnswer called before userId is set");
10253
10250
  return;
10254
10251
  }
10255
10252
  const question = quiz.questions.find((q) => q.id === questionId);
@@ -10284,16 +10281,10 @@ var useQuizStore = create9()(
10284
10281
  const activityId = quiz.id;
10285
10282
  const userId = get().getUserId();
10286
10283
  if (!userId || userId === "") {
10287
- console.warn(
10288
- "selectDissertativeAnswer called before userId is set"
10289
- );
10290
10284
  return;
10291
10285
  }
10292
10286
  const question = quiz.questions.find((q) => q.id === questionId);
10293
10287
  if (!question || question.questionType !== "DISSERTATIVA" /* DISSERTATIVA */) {
10294
- console.warn(
10295
- "selectDissertativeAnswer called for non-dissertative question"
10296
- );
10297
10288
  return;
10298
10289
  }
10299
10290
  const existingAnswerIndex = userAnswers.findIndex(
@@ -10327,7 +10318,6 @@ var useQuizStore = create9()(
10327
10318
  const activityId = quiz.id;
10328
10319
  const userId = get().getUserId();
10329
10320
  if (!userId || userId === "") {
10330
- console.warn("skipQuestion called before userId is set");
10331
10321
  return;
10332
10322
  }
10333
10323
  const existingAnswerIndex = userAnswers.findIndex(
@@ -10360,7 +10350,6 @@ var useQuizStore = create9()(
10360
10350
  const activityId = quiz.id;
10361
10351
  const userId = get().getUserId();
10362
10352
  if (!userId || userId === "") {
10363
- console.warn("addUserAnswer called before userId is set");
10364
10353
  return;
10365
10354
  }
10366
10355
  const question = quiz.questions.find((q) => q.id === questionId);
@@ -10588,9 +10577,6 @@ var useQuizStore = create9()(
10588
10577
  );
10589
10578
  }
10590
10579
  if (questionIndex === -1) {
10591
- console.warn(
10592
- `Question with id "${question.id}" not found in active quiz`
10593
- );
10594
10580
  return;
10595
10581
  }
10596
10582
  set({ currentQuestionIndex: questionIndex });
@@ -11955,34 +11941,16 @@ var QuizFooter = forwardRef21(
11955
11941
  children: "Avan\xE7ar"
11956
11942
  }
11957
11943
  )
11958
- ] }) : /* @__PURE__ */ jsxs37("div", { className: "flex flex-row items-center justify-between w-full", children: [
11959
- /* @__PURE__ */ jsx51("span", { children: quiz?.canRetry && /* @__PURE__ */ jsx51(
11960
- Button_default,
11961
- {
11962
- variant: "link",
11963
- action: "primary",
11964
- size: "medium",
11965
- onClick: () => openModal("modalResolution"),
11966
- children: "Ver Resolu\xE7\xE3o"
11967
- }
11968
- ) }),
11969
- /* @__PURE__ */ jsx51(
11970
- Button_default,
11971
- {
11972
- variant: "solid",
11973
- action: "primary",
11974
- size: "medium",
11975
- onClick: () => {
11976
- if (quiz?.canRetry) {
11977
- onRepeat?.();
11978
- } else {
11979
- openModal("modalResolution");
11980
- }
11981
- },
11982
- children: quiz?.canRetry ? `Repetir ${getTypeLabel(quiz.type)}` : "Ver Resolu\xE7\xE3o"
11983
- }
11984
- )
11985
- ] })
11944
+ ] }) : /* @__PURE__ */ jsx51("div", { className: "flex flex-row items-center justify-center w-full", children: /* @__PURE__ */ jsx51(
11945
+ Button_default,
11946
+ {
11947
+ variant: "link",
11948
+ action: "primary",
11949
+ size: "medium",
11950
+ onClick: () => openModal("modalResolution"),
11951
+ children: "Ver resolu\xE7\xE3o"
11952
+ }
11953
+ ) })
11986
11954
  }
11987
11955
  ),
11988
11956
  /* @__PURE__ */ jsx51(
@@ -12261,17 +12229,32 @@ var QuizHeaderResult = forwardRef22(
12261
12229
  );
12262
12230
  }
12263
12231
  );
12264
- var QuizResultHeaderTitle = forwardRef22(({ className, showBadge = true, ...props }, ref) => {
12232
+ var QuizResultHeaderTitle = forwardRef22(({ className, showBadge = true, onRepeat, canRetry, ...props }, ref) => {
12265
12233
  const { quiz } = useQuizStore();
12266
12234
  return /* @__PURE__ */ jsxs38(
12267
12235
  "div",
12268
12236
  {
12269
12237
  ref,
12270
- className: cn("flex flex-row pt-4 justify-between", className),
12238
+ className: cn(
12239
+ "flex flex-row pt-4 justify-between items-center",
12240
+ className
12241
+ ),
12271
12242
  ...props,
12272
12243
  children: [
12273
12244
  /* @__PURE__ */ jsx52("p", { className: "text-text-950 font-bold text-2xl", children: "Resultado" }),
12274
- showBadge && /* @__PURE__ */ jsx52(QuizBadge, { subtype: quiz?.subtype || void 0 })
12245
+ /* @__PURE__ */ jsxs38("div", { className: "flex flex-row gap-3 items-center", children: [
12246
+ canRetry && onRepeat && /* @__PURE__ */ jsx52(
12247
+ Button_default,
12248
+ {
12249
+ variant: "solid",
12250
+ action: "primary",
12251
+ size: "medium",
12252
+ onClick: onRepeat,
12253
+ children: "Repetir question\xE1rio"
12254
+ }
12255
+ ),
12256
+ showBadge && /* @__PURE__ */ jsx52(QuizBadge, { subtype: quiz?.subtype || void 0 })
12257
+ ] })
12275
12258
  ]
12276
12259
  }
12277
12260
  );
@@ -12463,14 +12446,15 @@ var QuizListResult = forwardRef22(({ className, onSubjectClick, ...props }, ref)
12463
12446
  });
12464
12447
  var QuizListResultByMateria = ({
12465
12448
  subject,
12466
- onQuestionClick
12449
+ onQuestionClick,
12450
+ subjectName
12467
12451
  }) => {
12468
12452
  const { getQuestionsGroupedBySubject, getQuestionIndex } = useQuizStore();
12469
12453
  const groupedQuestions = getQuestionsGroupedBySubject();
12470
12454
  const answeredQuestions = groupedQuestions[subject] || [];
12471
12455
  const formattedQuestions = subject == "all" ? Object.values(groupedQuestions).flat() : answeredQuestions;
12472
12456
  return /* @__PURE__ */ jsxs38("div", { className: "flex flex-col", children: [
12473
- /* @__PURE__ */ jsx52("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx52("p", { className: "text-text-950 font-bold text-2xl", children: answeredQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name ?? "Sem mat\xE9ria" }) }),
12457
+ /* @__PURE__ */ jsx52("div", { className: "flex flex-row pt-4 justify-between", children: /* @__PURE__ */ jsx52("p", { className: "text-text-950 font-bold text-2xl", children: subjectName || formattedQuestions?.[0]?.knowledgeMatrix?.[0]?.subject?.name || "Sem mat\xE9ria" }) }),
12474
12458
  /* @__PURE__ */ jsxs38("section", { className: "flex flex-col ", children: [
12475
12459
  /* @__PURE__ */ jsx52("p", { className: "pt-6 pb-4 text-text-950 font-bold text-lg", children: "Resultado das quest\xF5es" }),
12476
12460
  /* @__PURE__ */ jsx52("ul", { className: "flex flex-col gap-2 pt-4", children: formattedQuestions.map((question) => {
@@ -12501,6 +12485,310 @@ var QuizListResultByMateria = ({
12501
12485
  ] })
12502
12486
  ] });
12503
12487
  };
12488
+
12489
+ // src/hooks/useAppInitialization.ts
12490
+ import { useMemo as useMemo7 } from "react";
12491
+
12492
+ // src/hooks/useInstitution.ts
12493
+ import { useEffect as useEffect22, useState as useState23 } from "react";
12494
+ function useInstitutionId() {
12495
+ const [institutionId, setInstitutionId] = useState23(() => {
12496
+ return document.querySelector('meta[name="institution-id"]')?.getAttribute("content") ?? null;
12497
+ });
12498
+ useEffect22(() => {
12499
+ const metaTag = document.querySelector('meta[name="institution-id"]');
12500
+ if (!metaTag) return;
12501
+ const observer = new MutationObserver(() => {
12502
+ const newValue = metaTag.getAttribute("content");
12503
+ setInstitutionId(newValue);
12504
+ });
12505
+ observer.observe(metaTag, {
12506
+ attributes: true,
12507
+ attributeFilter: ["content"]
12508
+ });
12509
+ return () => observer.disconnect();
12510
+ }, []);
12511
+ return institutionId;
12512
+ }
12513
+
12514
+ // src/store/appStore.ts
12515
+ import { create as create10 } from "zustand";
12516
+ import { createJSONStorage, persist as persist2 } from "zustand/middleware";
12517
+ var useAppStore = create10()(
12518
+ persist2(
12519
+ (set, get) => ({
12520
+ institutionId: null,
12521
+ initialized: false,
12522
+ /**
12523
+ * Set the institution ID
12524
+ * @param {string | null} institutionId - The institution ID from meta tag
12525
+ * @returns {void}
12526
+ */
12527
+ setInstitutionId: (institutionId) => {
12528
+ set({ institutionId });
12529
+ },
12530
+ /**
12531
+ * Set the initialized state
12532
+ * @param {boolean} initialized - Whether the app has been initialized
12533
+ * @returns {void}
12534
+ */
12535
+ setInitialized: (initialized) => {
12536
+ set({ initialized });
12537
+ },
12538
+ /**
12539
+ * Initialize the app by reading the institution ID from meta tag
12540
+ * @returns {void}
12541
+ */
12542
+ initialize: (id) => {
12543
+ const { initialized } = get();
12544
+ if (initialized) {
12545
+ return;
12546
+ }
12547
+ set({
12548
+ institutionId: id,
12549
+ initialized: true
12550
+ });
12551
+ }
12552
+ }),
12553
+ {
12554
+ name: "@app-storage:analytica:v2" /* APP_STORAGE */,
12555
+ storage: createJSONStorage(() => localStorage)
12556
+ }
12557
+ )
12558
+ );
12559
+
12560
+ // src/store/authStore.ts
12561
+ import { create as create11 } from "zustand";
12562
+ import { createJSONStorage as createJSONStorage2, persist as persist3 } from "zustand/middleware";
12563
+ var useAuthStore = create11()(
12564
+ persist3(
12565
+ (set, get) => ({
12566
+ user: null,
12567
+ tokens: null,
12568
+ isAuthenticated: false,
12569
+ profiles: [],
12570
+ selectedProfile: null,
12571
+ sessionInfo: null,
12572
+ /**
12573
+ * Set the current user
12574
+ * @param {User | null} user - The user object or null to clear
12575
+ * @returns {void}
12576
+ */
12577
+ setUser: (user) => {
12578
+ set({ user, isAuthenticated: !!user });
12579
+ },
12580
+ /**
12581
+ * Set the authentication tokens
12582
+ * @param {AuthTokens | null} tokens - The authentication tokens or null to clear
12583
+ * @returns {void}
12584
+ */
12585
+ setTokens: (tokens) => {
12586
+ set({ tokens });
12587
+ },
12588
+ /**
12589
+ * Set user profiles
12590
+ * @param {UserProfile[]} profiles - Array of user profiles
12591
+ * @returns {void}
12592
+ */
12593
+ setProfiles: (profiles) => {
12594
+ set({ profiles });
12595
+ },
12596
+ /**
12597
+ * Set the selected profile
12598
+ * @param {UserProfile | null} profile - The selected profile or null to clear
12599
+ * @returns {void}
12600
+ */
12601
+ setSelectedProfile: (profile) => {
12602
+ set({ selectedProfile: profile });
12603
+ },
12604
+ /**
12605
+ * Set the session info
12606
+ * @param {SessionInfo | null} sessionInfo - The session info or null to clear
12607
+ * @returns {void}
12608
+ */
12609
+ setSessionInfo: (sessionInfo) => {
12610
+ set({ sessionInfo });
12611
+ },
12612
+ /**
12613
+ * Sign in user with complete auth data
12614
+ * @param {User} user - The user object
12615
+ * @param {AuthTokens} tokens - The authentication tokens
12616
+ * @param {UserProfile[]} profiles - Array of user profiles
12617
+ * @returns {void}
12618
+ */
12619
+ signIn: (user, tokens, profiles) => {
12620
+ set({
12621
+ user,
12622
+ tokens,
12623
+ profiles,
12624
+ isAuthenticated: true
12625
+ });
12626
+ },
12627
+ /**
12628
+ * Sign out user and clear all auth data
12629
+ * @returns {void}
12630
+ */
12631
+ signOut: () => {
12632
+ set({
12633
+ user: null,
12634
+ tokens: null,
12635
+ isAuthenticated: false,
12636
+ profiles: [],
12637
+ selectedProfile: null,
12638
+ sessionInfo: null
12639
+ });
12640
+ },
12641
+ /**
12642
+ * Update user session data (after login completion)
12643
+ * @param {Partial<User>} sessionData - Partial user data to update
12644
+ * @returns {void}
12645
+ */
12646
+ updateUserSession: (sessionData) => {
12647
+ const { user } = get();
12648
+ if (user) {
12649
+ const updatedUser = { ...user, ...sessionData };
12650
+ set({ user: updatedUser });
12651
+ }
12652
+ }
12653
+ }),
12654
+ {
12655
+ name: "@auth-storage:analytica:v2" /* AUTH_STORAGE */,
12656
+ storage: createJSONStorage2(() => localStorage)
12657
+ }
12658
+ )
12659
+ );
12660
+
12661
+ // src/hooks/useAppInitialization.ts
12662
+ function useAppInitialization() {
12663
+ const getInstitutionId = useInstitutionId();
12664
+ const { initialize, initialized, institutionId } = useAppStore();
12665
+ const authFunctions = useMemo7(
12666
+ () => ({
12667
+ checkAuth: async () => {
12668
+ const { sessionInfo, tokens } = useAuthStore.getState();
12669
+ return Boolean(sessionInfo && tokens);
12670
+ },
12671
+ signOut: () => {
12672
+ const { signOut } = useAuthStore.getState();
12673
+ signOut();
12674
+ },
12675
+ getUser: () => {
12676
+ const { user } = useAuthStore.getState();
12677
+ return user;
12678
+ },
12679
+ getSessionInfo: () => {
12680
+ const { sessionInfo } = useAuthStore.getState();
12681
+ return sessionInfo;
12682
+ },
12683
+ getTokens: () => {
12684
+ const { tokens } = useAuthStore.getState();
12685
+ return tokens;
12686
+ }
12687
+ }),
12688
+ []
12689
+ );
12690
+ return {
12691
+ // Estado da inicialização
12692
+ getInstitutionId,
12693
+ initialize,
12694
+ initialized,
12695
+ institutionId,
12696
+ // Funções de autenticação
12697
+ authFunctions
12698
+ };
12699
+ }
12700
+
12701
+ // src/hooks/useAppContent.ts
12702
+ import { useCallback as useCallback7, useEffect as useEffect23, useMemo as useMemo8 } from "react";
12703
+ import { useNavigate } from "react-router-dom";
12704
+ function useAppContent(config) {
12705
+ const navigate = useNavigate();
12706
+ const { setTokens, setSessionInfo, setSelectedProfile } = useAuthStore();
12707
+ const {
12708
+ api,
12709
+ getInstitutionId,
12710
+ initialize,
12711
+ initialized,
12712
+ endpoint = "/auth/session-info",
12713
+ maxRetries = 1,
12714
+ retryDelay = 2e3,
12715
+ onClearParamsFromURL,
12716
+ onError,
12717
+ onNotFoundNavigation
12718
+ } = config;
12719
+ const apiConfig = useApiConfig(api);
12720
+ useTheme();
12721
+ const handleNotFoundNavigation = () => {
12722
+ if (onNotFoundNavigation) {
12723
+ onNotFoundNavigation();
12724
+ } else {
12725
+ navigate("/painel");
12726
+ }
12727
+ };
12728
+ const handleSetSelectedProfile = useCallback7(
12729
+ (profile) => {
12730
+ setSelectedProfile(profile);
12731
+ },
12732
+ [setSelectedProfile]
12733
+ );
12734
+ const handleClearParamsFromURL = useCallback7(() => {
12735
+ if (onClearParamsFromURL) {
12736
+ onClearParamsFromURL();
12737
+ } else {
12738
+ globalThis.location.replace("/painel");
12739
+ }
12740
+ }, [onClearParamsFromURL]);
12741
+ const handleError = useCallback7(
12742
+ (error) => {
12743
+ if (onError) {
12744
+ onError(error);
12745
+ } else {
12746
+ console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
12747
+ navigate("/", { replace: true });
12748
+ }
12749
+ },
12750
+ [navigate, onError]
12751
+ );
12752
+ const urlAuthConfig = useMemo8(
12753
+ () => ({
12754
+ setTokens,
12755
+ setSessionInfo,
12756
+ setSelectedProfile: handleSetSelectedProfile,
12757
+ api: apiConfig,
12758
+ endpoint,
12759
+ clearParamsFromURL: handleClearParamsFromURL,
12760
+ maxRetries,
12761
+ retryDelay,
12762
+ onError: handleError
12763
+ }),
12764
+ [
12765
+ setTokens,
12766
+ setSessionInfo,
12767
+ handleSetSelectedProfile,
12768
+ apiConfig,
12769
+ endpoint,
12770
+ handleClearParamsFromURL,
12771
+ maxRetries,
12772
+ retryDelay,
12773
+ handleError
12774
+ ]
12775
+ );
12776
+ useUrlAuthentication(urlAuthConfig);
12777
+ const { sessionInfo } = useAuth();
12778
+ const institutionIdToUse = useMemo8(() => {
12779
+ return sessionInfo?.institutionId || getInstitutionId;
12780
+ }, [sessionInfo?.institutionId, getInstitutionId]);
12781
+ useEffect23(() => {
12782
+ if (institutionIdToUse && !initialized) {
12783
+ initialize(institutionIdToUse);
12784
+ }
12785
+ }, [institutionIdToUse, initialize, initialized]);
12786
+ return {
12787
+ handleNotFoundNavigation,
12788
+ urlAuthConfig,
12789
+ institutionIdToUse
12790
+ };
12791
+ }
12504
12792
  export {
12505
12793
  ANSWER_STATUS,
12506
12794
  Alert_default as Alert,
@@ -12627,8 +12915,13 @@ export {
12627
12915
  getSubjectName,
12628
12916
  syncDropdownState,
12629
12917
  useApiConfig,
12918
+ useAppContent,
12919
+ useAppInitialization,
12920
+ useAppStore,
12630
12921
  useAuth,
12631
12922
  useAuthGuard,
12923
+ useAuthStore,
12924
+ useInstitutionId,
12632
12925
  useMobile,
12633
12926
  useQuizStore,
12634
12927
  useRouteAuth,