analytica-frontend-lib 1.1.92 → 1.1.94
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/BreadcrumbMenu/breadcrumbStore/index.d.mts +77 -0
- package/dist/BreadcrumbMenu/breadcrumbStore/index.d.ts +77 -0
- package/dist/BreadcrumbMenu/breadcrumbStore/index.js +146 -0
- package/dist/BreadcrumbMenu/breadcrumbStore/index.js.map +1 -0
- package/dist/BreadcrumbMenu/breadcrumbStore/index.mjs +120 -0
- package/dist/BreadcrumbMenu/breadcrumbStore/index.mjs.map +1 -0
- package/dist/BreadcrumbMenu/index.d.mts +31 -0
- package/dist/BreadcrumbMenu/index.d.ts +31 -0
- package/dist/BreadcrumbMenu/index.js +308 -0
- package/dist/BreadcrumbMenu/index.js.map +1 -0
- package/dist/BreadcrumbMenu/index.mjs +289 -0
- package/dist/BreadcrumbMenu/index.mjs.map +1 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.d.mts +48 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.d.ts +48 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.js +189 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.js.map +1 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.mjs +164 -0
- package/dist/BreadcrumbMenu/useBreadcrumbBuilder/index.mjs.map +1 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.d.mts +28 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.d.ts +28 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.js +43 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.js.map +1 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.mjs +18 -0
- package/dist/BreadcrumbMenu/useUrlParams/index.mjs.map +1 -0
- package/dist/index.css +3 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +185 -3
- package/dist/index.d.ts +185 -3
- package/dist/index.js +546 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +537 -6
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +3 -0
- package/dist/styles.css.map +1 -1
- package/package.json +2 -1
package/dist/index.mjs
CHANGED
|
@@ -9879,7 +9879,7 @@ var HeaderAlternative = forwardRef19(
|
|
|
9879
9879
|
);
|
|
9880
9880
|
|
|
9881
9881
|
// src/components/Auth/zustandAuthAdapter.ts
|
|
9882
|
-
function createZustandAuthAdapter(
|
|
9882
|
+
function createZustandAuthAdapter(useAuthStore2) {
|
|
9883
9883
|
return {
|
|
9884
9884
|
/**
|
|
9885
9885
|
* Check if the user is authenticated based on sessionInfo and tokens
|
|
@@ -9887,7 +9887,7 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9887
9887
|
* @returns {Promise<boolean>} Promise that resolves to authentication status
|
|
9888
9888
|
*/
|
|
9889
9889
|
checkAuth: async () => {
|
|
9890
|
-
const { sessionInfo, tokens } =
|
|
9890
|
+
const { sessionInfo, tokens } = useAuthStore2.getState();
|
|
9891
9891
|
return Boolean(sessionInfo && tokens);
|
|
9892
9892
|
},
|
|
9893
9893
|
/**
|
|
@@ -9895,26 +9895,26 @@ function createZustandAuthAdapter(useAuthStore) {
|
|
|
9895
9895
|
*
|
|
9896
9896
|
* @returns {unknown} Current user data from the store
|
|
9897
9897
|
*/
|
|
9898
|
-
getUser: () =>
|
|
9898
|
+
getUser: () => useAuthStore2.getState().user,
|
|
9899
9899
|
/**
|
|
9900
9900
|
* Get the current session information from the store
|
|
9901
9901
|
*
|
|
9902
9902
|
* @returns {unknown} Current session info from the store
|
|
9903
9903
|
*/
|
|
9904
|
-
getSessionInfo: () =>
|
|
9904
|
+
getSessionInfo: () => useAuthStore2.getState().sessionInfo,
|
|
9905
9905
|
/**
|
|
9906
9906
|
* Get the current authentication tokens from the store
|
|
9907
9907
|
*
|
|
9908
9908
|
* @returns {unknown} Current tokens from the store
|
|
9909
9909
|
*/
|
|
9910
|
-
getTokens: () =>
|
|
9910
|
+
getTokens: () => useAuthStore2.getState().tokens,
|
|
9911
9911
|
/**
|
|
9912
9912
|
* Sign out the user by calling the store's signOut function if available
|
|
9913
9913
|
*
|
|
9914
9914
|
* @returns {void}
|
|
9915
9915
|
*/
|
|
9916
9916
|
signOut: () => {
|
|
9917
|
-
const signOutFn =
|
|
9917
|
+
const signOutFn = useAuthStore2.getState().signOut;
|
|
9918
9918
|
if (typeof signOutFn === "function") signOutFn();
|
|
9919
9919
|
}
|
|
9920
9920
|
};
|
|
@@ -12485,6 +12485,528 @@ var QuizListResultByMateria = ({
|
|
|
12485
12485
|
] })
|
|
12486
12486
|
] });
|
|
12487
12487
|
};
|
|
12488
|
+
|
|
12489
|
+
// src/components/BreadcrumbMenu/BreadcrumbMenu.tsx
|
|
12490
|
+
import { useNavigate } from "react-router-dom";
|
|
12491
|
+
import { jsx as jsx53 } from "react/jsx-runtime";
|
|
12492
|
+
var BreadcrumbMenu = ({
|
|
12493
|
+
breadcrumbs,
|
|
12494
|
+
onBreadcrumbClick,
|
|
12495
|
+
className = "!px-0 py-4 flex-wrap w-full"
|
|
12496
|
+
}) => {
|
|
12497
|
+
const navigate = useNavigate();
|
|
12498
|
+
const handleClick = (breadcrumb, index) => {
|
|
12499
|
+
if (onBreadcrumbClick) {
|
|
12500
|
+
onBreadcrumbClick(breadcrumb, index);
|
|
12501
|
+
}
|
|
12502
|
+
navigate(breadcrumb.url);
|
|
12503
|
+
};
|
|
12504
|
+
return /* @__PURE__ */ jsx53(
|
|
12505
|
+
Menu,
|
|
12506
|
+
{
|
|
12507
|
+
value: `breadcrumb-${breadcrumbs.length - 1}`,
|
|
12508
|
+
defaultValue: "breadcrumb-0",
|
|
12509
|
+
variant: "breadcrumb",
|
|
12510
|
+
className,
|
|
12511
|
+
children: /* @__PURE__ */ jsx53(MenuContent, { className: "w-full flex flex-row flex-wrap gap-2 !px-0", children: breadcrumbs.map((breadcrumb, index) => {
|
|
12512
|
+
const isLast = index === breadcrumbs.length - 1;
|
|
12513
|
+
const hasSeparator = !isLast;
|
|
12514
|
+
return /* @__PURE__ */ jsx53(
|
|
12515
|
+
MenuItem,
|
|
12516
|
+
{
|
|
12517
|
+
variant: "breadcrumb",
|
|
12518
|
+
value: `breadcrumb-${index}`,
|
|
12519
|
+
className: "!p-0 whitespace-nowrap",
|
|
12520
|
+
onClick: () => handleClick(breadcrumb, index),
|
|
12521
|
+
separator: hasSeparator,
|
|
12522
|
+
children: breadcrumb.name
|
|
12523
|
+
},
|
|
12524
|
+
breadcrumb.id
|
|
12525
|
+
);
|
|
12526
|
+
}) })
|
|
12527
|
+
}
|
|
12528
|
+
);
|
|
12529
|
+
};
|
|
12530
|
+
|
|
12531
|
+
// src/components/BreadcrumbMenu/useBreadcrumbBuilder.ts
|
|
12532
|
+
import { useEffect as useEffect22 } from "react";
|
|
12533
|
+
|
|
12534
|
+
// src/components/BreadcrumbMenu/breadcrumbStore.ts
|
|
12535
|
+
import { create as create10 } from "zustand";
|
|
12536
|
+
var useBreadcrumbStore = create10((set, get) => ({
|
|
12537
|
+
breadcrumbs: {},
|
|
12538
|
+
setBreadcrumbs: (namespace, items) => {
|
|
12539
|
+
set((state) => ({
|
|
12540
|
+
breadcrumbs: {
|
|
12541
|
+
...state.breadcrumbs,
|
|
12542
|
+
[namespace]: items
|
|
12543
|
+
}
|
|
12544
|
+
}));
|
|
12545
|
+
},
|
|
12546
|
+
addBreadcrumb: (namespace, item) => {
|
|
12547
|
+
set((state) => {
|
|
12548
|
+
const current = state.breadcrumbs[namespace] || [];
|
|
12549
|
+
return {
|
|
12550
|
+
breadcrumbs: {
|
|
12551
|
+
...state.breadcrumbs,
|
|
12552
|
+
[namespace]: [...current, item]
|
|
12553
|
+
}
|
|
12554
|
+
};
|
|
12555
|
+
});
|
|
12556
|
+
},
|
|
12557
|
+
updateBreadcrumb: (namespace, itemId, updates) => {
|
|
12558
|
+
set((state) => {
|
|
12559
|
+
const current = state.breadcrumbs[namespace] || [];
|
|
12560
|
+
return {
|
|
12561
|
+
breadcrumbs: {
|
|
12562
|
+
...state.breadcrumbs,
|
|
12563
|
+
[namespace]: current.map(
|
|
12564
|
+
(item) => item.id === itemId ? { ...item, ...updates } : item
|
|
12565
|
+
)
|
|
12566
|
+
}
|
|
12567
|
+
};
|
|
12568
|
+
});
|
|
12569
|
+
},
|
|
12570
|
+
removeBreadcrumbFrom: (namespace, itemId) => {
|
|
12571
|
+
set((state) => {
|
|
12572
|
+
const current = state.breadcrumbs[namespace] || [];
|
|
12573
|
+
const index = current.findIndex((item) => item.id === itemId);
|
|
12574
|
+
if (index === -1) return state;
|
|
12575
|
+
return {
|
|
12576
|
+
breadcrumbs: {
|
|
12577
|
+
...state.breadcrumbs,
|
|
12578
|
+
[namespace]: current.slice(0, index)
|
|
12579
|
+
}
|
|
12580
|
+
};
|
|
12581
|
+
});
|
|
12582
|
+
},
|
|
12583
|
+
sliceBreadcrumbs: (namespace, index) => {
|
|
12584
|
+
set((state) => {
|
|
12585
|
+
const current = state.breadcrumbs[namespace] || [];
|
|
12586
|
+
return {
|
|
12587
|
+
breadcrumbs: {
|
|
12588
|
+
...state.breadcrumbs,
|
|
12589
|
+
[namespace]: current.slice(0, index + 1)
|
|
12590
|
+
}
|
|
12591
|
+
};
|
|
12592
|
+
});
|
|
12593
|
+
},
|
|
12594
|
+
clearBreadcrumbs: (namespace) => {
|
|
12595
|
+
set((state) => {
|
|
12596
|
+
const { [namespace]: _, ...rest } = state.breadcrumbs;
|
|
12597
|
+
return {
|
|
12598
|
+
breadcrumbs: rest
|
|
12599
|
+
};
|
|
12600
|
+
});
|
|
12601
|
+
},
|
|
12602
|
+
getBreadcrumbs: (namespace) => {
|
|
12603
|
+
return get().breadcrumbs[namespace] || [];
|
|
12604
|
+
}
|
|
12605
|
+
}));
|
|
12606
|
+
var useBreadcrumb = (namespace) => {
|
|
12607
|
+
const store = useBreadcrumbStore();
|
|
12608
|
+
const breadcrumbs = store.breadcrumbs[namespace] || [];
|
|
12609
|
+
return {
|
|
12610
|
+
breadcrumbs,
|
|
12611
|
+
/**
|
|
12612
|
+
* Define todos os breadcrumbs de uma vez
|
|
12613
|
+
*/
|
|
12614
|
+
setBreadcrumbs: (items) => {
|
|
12615
|
+
store.setBreadcrumbs(namespace, items);
|
|
12616
|
+
},
|
|
12617
|
+
/**
|
|
12618
|
+
* Adiciona um novo breadcrumb ao final
|
|
12619
|
+
*/
|
|
12620
|
+
addBreadcrumb: (item) => {
|
|
12621
|
+
store.addBreadcrumb(namespace, item);
|
|
12622
|
+
},
|
|
12623
|
+
/**
|
|
12624
|
+
* Atualiza um breadcrumb existente
|
|
12625
|
+
*/
|
|
12626
|
+
updateBreadcrumb: (itemId, updates) => {
|
|
12627
|
+
store.updateBreadcrumb(namespace, itemId, updates);
|
|
12628
|
+
},
|
|
12629
|
+
/**
|
|
12630
|
+
* Remove um breadcrumb e todos os seguintes
|
|
12631
|
+
*/
|
|
12632
|
+
removeBreadcrumbFrom: (itemId) => {
|
|
12633
|
+
store.removeBreadcrumbFrom(namespace, itemId);
|
|
12634
|
+
},
|
|
12635
|
+
/**
|
|
12636
|
+
* Mantém apenas os breadcrumbs até o índice especificado (inclusivo)
|
|
12637
|
+
*/
|
|
12638
|
+
sliceBreadcrumbs: (index) => {
|
|
12639
|
+
store.sliceBreadcrumbs(namespace, index);
|
|
12640
|
+
},
|
|
12641
|
+
/**
|
|
12642
|
+
* Limpa todos os breadcrumbs
|
|
12643
|
+
*/
|
|
12644
|
+
clearBreadcrumbs: () => {
|
|
12645
|
+
store.clearBreadcrumbs(namespace);
|
|
12646
|
+
}
|
|
12647
|
+
};
|
|
12648
|
+
};
|
|
12649
|
+
|
|
12650
|
+
// src/components/BreadcrumbMenu/useBreadcrumbBuilder.ts
|
|
12651
|
+
var isBreadcrumbWithData = (level) => {
|
|
12652
|
+
return "data" in level;
|
|
12653
|
+
};
|
|
12654
|
+
var useBreadcrumbBuilder = (config) => {
|
|
12655
|
+
const { namespace, root, levels } = config;
|
|
12656
|
+
const { breadcrumbs, setBreadcrumbs, sliceBreadcrumbs } = useBreadcrumb(namespace);
|
|
12657
|
+
const levelDependencies = levels.map(
|
|
12658
|
+
(level) => isBreadcrumbWithData(level) ? level.data : null
|
|
12659
|
+
);
|
|
12660
|
+
const levelUrlIds = levels.map((level) => level.urlId);
|
|
12661
|
+
useEffect22(() => {
|
|
12662
|
+
const newBreadcrumbs = [root];
|
|
12663
|
+
const previousIds = [];
|
|
12664
|
+
for (const level of levels) {
|
|
12665
|
+
const { urlId } = level;
|
|
12666
|
+
if (isBreadcrumbWithData(level)) {
|
|
12667
|
+
const { data, getId, getName, getUrl } = level;
|
|
12668
|
+
if (!data) break;
|
|
12669
|
+
const dataId = getId(data);
|
|
12670
|
+
if (urlId === void 0 || dataId !== urlId) break;
|
|
12671
|
+
newBreadcrumbs.push({
|
|
12672
|
+
id: dataId,
|
|
12673
|
+
name: getName(data),
|
|
12674
|
+
url: getUrl(data, previousIds)
|
|
12675
|
+
});
|
|
12676
|
+
previousIds.push(dataId);
|
|
12677
|
+
} else {
|
|
12678
|
+
const { breadcrumb } = level;
|
|
12679
|
+
if (urlId === void 0) break;
|
|
12680
|
+
newBreadcrumbs.push(breadcrumb);
|
|
12681
|
+
previousIds.push(breadcrumb.id);
|
|
12682
|
+
}
|
|
12683
|
+
}
|
|
12684
|
+
setBreadcrumbs(newBreadcrumbs);
|
|
12685
|
+
}, [namespace, ...levelDependencies, ...levelUrlIds, root.id]);
|
|
12686
|
+
return {
|
|
12687
|
+
breadcrumbs,
|
|
12688
|
+
sliceBreadcrumbs
|
|
12689
|
+
};
|
|
12690
|
+
};
|
|
12691
|
+
|
|
12692
|
+
// src/components/BreadcrumbMenu/useUrlParams.ts
|
|
12693
|
+
import { useMemo as useMemo7 } from "react";
|
|
12694
|
+
import { useLocation as useLocation3 } from "react-router-dom";
|
|
12695
|
+
var useUrlParams = (config) => {
|
|
12696
|
+
const location = useLocation3();
|
|
12697
|
+
return useMemo7(() => {
|
|
12698
|
+
const segments = location.pathname.split("/").filter(Boolean);
|
|
12699
|
+
const params = {};
|
|
12700
|
+
for (const [key, index] of Object.entries(config)) {
|
|
12701
|
+
params[key] = segments[index];
|
|
12702
|
+
}
|
|
12703
|
+
return params;
|
|
12704
|
+
}, [location.pathname, config]);
|
|
12705
|
+
};
|
|
12706
|
+
|
|
12707
|
+
// src/hooks/useAppInitialization.ts
|
|
12708
|
+
import { useMemo as useMemo8 } from "react";
|
|
12709
|
+
|
|
12710
|
+
// src/hooks/useInstitution.ts
|
|
12711
|
+
import { useEffect as useEffect23, useState as useState23 } from "react";
|
|
12712
|
+
function useInstitutionId() {
|
|
12713
|
+
const [institutionId, setInstitutionId] = useState23(() => {
|
|
12714
|
+
return document.querySelector('meta[name="institution-id"]')?.getAttribute("content") ?? null;
|
|
12715
|
+
});
|
|
12716
|
+
useEffect23(() => {
|
|
12717
|
+
const metaTag = document.querySelector('meta[name="institution-id"]');
|
|
12718
|
+
if (!metaTag) return;
|
|
12719
|
+
const observer = new MutationObserver(() => {
|
|
12720
|
+
const newValue = metaTag.getAttribute("content");
|
|
12721
|
+
setInstitutionId(newValue);
|
|
12722
|
+
});
|
|
12723
|
+
observer.observe(metaTag, {
|
|
12724
|
+
attributes: true,
|
|
12725
|
+
attributeFilter: ["content"]
|
|
12726
|
+
});
|
|
12727
|
+
return () => observer.disconnect();
|
|
12728
|
+
}, []);
|
|
12729
|
+
return institutionId;
|
|
12730
|
+
}
|
|
12731
|
+
|
|
12732
|
+
// src/store/appStore.ts
|
|
12733
|
+
import { create as create11 } from "zustand";
|
|
12734
|
+
import { createJSONStorage, persist as persist2 } from "zustand/middleware";
|
|
12735
|
+
var useAppStore = create11()(
|
|
12736
|
+
persist2(
|
|
12737
|
+
(set, get) => ({
|
|
12738
|
+
institutionId: null,
|
|
12739
|
+
initialized: false,
|
|
12740
|
+
/**
|
|
12741
|
+
* Set the institution ID
|
|
12742
|
+
* @param {string | null} institutionId - The institution ID from meta tag
|
|
12743
|
+
* @returns {void}
|
|
12744
|
+
*/
|
|
12745
|
+
setInstitutionId: (institutionId) => {
|
|
12746
|
+
set({ institutionId });
|
|
12747
|
+
},
|
|
12748
|
+
/**
|
|
12749
|
+
* Set the initialized state
|
|
12750
|
+
* @param {boolean} initialized - Whether the app has been initialized
|
|
12751
|
+
* @returns {void}
|
|
12752
|
+
*/
|
|
12753
|
+
setInitialized: (initialized) => {
|
|
12754
|
+
set({ initialized });
|
|
12755
|
+
},
|
|
12756
|
+
/**
|
|
12757
|
+
* Initialize the app by reading the institution ID from meta tag
|
|
12758
|
+
* @returns {void}
|
|
12759
|
+
*/
|
|
12760
|
+
initialize: (id) => {
|
|
12761
|
+
const { initialized } = get();
|
|
12762
|
+
if (initialized) {
|
|
12763
|
+
return;
|
|
12764
|
+
}
|
|
12765
|
+
set({
|
|
12766
|
+
institutionId: id,
|
|
12767
|
+
initialized: true
|
|
12768
|
+
});
|
|
12769
|
+
}
|
|
12770
|
+
}),
|
|
12771
|
+
{
|
|
12772
|
+
name: "@app-storage:analytica:v2" /* APP_STORAGE */,
|
|
12773
|
+
storage: createJSONStorage(() => localStorage)
|
|
12774
|
+
}
|
|
12775
|
+
)
|
|
12776
|
+
);
|
|
12777
|
+
|
|
12778
|
+
// src/store/authStore.ts
|
|
12779
|
+
import { create as create12 } from "zustand";
|
|
12780
|
+
import { createJSONStorage as createJSONStorage2, persist as persist3 } from "zustand/middleware";
|
|
12781
|
+
var useAuthStore = create12()(
|
|
12782
|
+
persist3(
|
|
12783
|
+
(set, get) => ({
|
|
12784
|
+
user: null,
|
|
12785
|
+
tokens: null,
|
|
12786
|
+
isAuthenticated: false,
|
|
12787
|
+
profiles: [],
|
|
12788
|
+
selectedProfile: null,
|
|
12789
|
+
sessionInfo: null,
|
|
12790
|
+
/**
|
|
12791
|
+
* Set the current user
|
|
12792
|
+
* @param {User | null} user - The user object or null to clear
|
|
12793
|
+
* @returns {void}
|
|
12794
|
+
*/
|
|
12795
|
+
setUser: (user) => {
|
|
12796
|
+
set({ user, isAuthenticated: !!user });
|
|
12797
|
+
},
|
|
12798
|
+
/**
|
|
12799
|
+
* Set the authentication tokens
|
|
12800
|
+
* @param {AuthTokens | null} tokens - The authentication tokens or null to clear
|
|
12801
|
+
* @returns {void}
|
|
12802
|
+
*/
|
|
12803
|
+
setTokens: (tokens) => {
|
|
12804
|
+
set({ tokens });
|
|
12805
|
+
},
|
|
12806
|
+
/**
|
|
12807
|
+
* Set user profiles
|
|
12808
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12809
|
+
* @returns {void}
|
|
12810
|
+
*/
|
|
12811
|
+
setProfiles: (profiles) => {
|
|
12812
|
+
set({ profiles });
|
|
12813
|
+
},
|
|
12814
|
+
/**
|
|
12815
|
+
* Set the selected profile
|
|
12816
|
+
* @param {UserProfile | null} profile - The selected profile or null to clear
|
|
12817
|
+
* @returns {void}
|
|
12818
|
+
*/
|
|
12819
|
+
setSelectedProfile: (profile) => {
|
|
12820
|
+
set({ selectedProfile: profile });
|
|
12821
|
+
},
|
|
12822
|
+
/**
|
|
12823
|
+
* Set the session info
|
|
12824
|
+
* @param {SessionInfo | null} sessionInfo - The session info or null to clear
|
|
12825
|
+
* @returns {void}
|
|
12826
|
+
*/
|
|
12827
|
+
setSessionInfo: (sessionInfo) => {
|
|
12828
|
+
set({ sessionInfo });
|
|
12829
|
+
},
|
|
12830
|
+
/**
|
|
12831
|
+
* Sign in user with complete auth data
|
|
12832
|
+
* @param {User} user - The user object
|
|
12833
|
+
* @param {AuthTokens} tokens - The authentication tokens
|
|
12834
|
+
* @param {UserProfile[]} profiles - Array of user profiles
|
|
12835
|
+
* @returns {void}
|
|
12836
|
+
*/
|
|
12837
|
+
signIn: (user, tokens, profiles) => {
|
|
12838
|
+
set({
|
|
12839
|
+
user,
|
|
12840
|
+
tokens,
|
|
12841
|
+
profiles,
|
|
12842
|
+
isAuthenticated: true
|
|
12843
|
+
});
|
|
12844
|
+
},
|
|
12845
|
+
/**
|
|
12846
|
+
* Sign out user and clear all auth data
|
|
12847
|
+
* @returns {void}
|
|
12848
|
+
*/
|
|
12849
|
+
signOut: () => {
|
|
12850
|
+
set({
|
|
12851
|
+
user: null,
|
|
12852
|
+
tokens: null,
|
|
12853
|
+
isAuthenticated: false,
|
|
12854
|
+
profiles: [],
|
|
12855
|
+
selectedProfile: null,
|
|
12856
|
+
sessionInfo: null
|
|
12857
|
+
});
|
|
12858
|
+
},
|
|
12859
|
+
/**
|
|
12860
|
+
* Update user session data (after login completion)
|
|
12861
|
+
* @param {Partial<User>} sessionData - Partial user data to update
|
|
12862
|
+
* @returns {void}
|
|
12863
|
+
*/
|
|
12864
|
+
updateUserSession: (sessionData) => {
|
|
12865
|
+
const { user } = get();
|
|
12866
|
+
if (user) {
|
|
12867
|
+
const updatedUser = { ...user, ...sessionData };
|
|
12868
|
+
set({ user: updatedUser });
|
|
12869
|
+
}
|
|
12870
|
+
}
|
|
12871
|
+
}),
|
|
12872
|
+
{
|
|
12873
|
+
name: "@auth-storage:analytica:v2" /* AUTH_STORAGE */,
|
|
12874
|
+
storage: createJSONStorage2(() => localStorage)
|
|
12875
|
+
}
|
|
12876
|
+
)
|
|
12877
|
+
);
|
|
12878
|
+
|
|
12879
|
+
// src/hooks/useAppInitialization.ts
|
|
12880
|
+
function useAppInitialization() {
|
|
12881
|
+
const getInstitutionId = useInstitutionId();
|
|
12882
|
+
const { initialize, initialized, institutionId } = useAppStore();
|
|
12883
|
+
const authFunctions = useMemo8(
|
|
12884
|
+
() => ({
|
|
12885
|
+
checkAuth: async () => {
|
|
12886
|
+
const { sessionInfo, tokens } = useAuthStore.getState();
|
|
12887
|
+
return Boolean(sessionInfo && tokens);
|
|
12888
|
+
},
|
|
12889
|
+
signOut: () => {
|
|
12890
|
+
const { signOut } = useAuthStore.getState();
|
|
12891
|
+
signOut();
|
|
12892
|
+
},
|
|
12893
|
+
getUser: () => {
|
|
12894
|
+
const { user } = useAuthStore.getState();
|
|
12895
|
+
return user;
|
|
12896
|
+
},
|
|
12897
|
+
getSessionInfo: () => {
|
|
12898
|
+
const { sessionInfo } = useAuthStore.getState();
|
|
12899
|
+
return sessionInfo;
|
|
12900
|
+
},
|
|
12901
|
+
getTokens: () => {
|
|
12902
|
+
const { tokens } = useAuthStore.getState();
|
|
12903
|
+
return tokens;
|
|
12904
|
+
}
|
|
12905
|
+
}),
|
|
12906
|
+
[]
|
|
12907
|
+
);
|
|
12908
|
+
return {
|
|
12909
|
+
// Estado da inicialização
|
|
12910
|
+
getInstitutionId,
|
|
12911
|
+
initialize,
|
|
12912
|
+
initialized,
|
|
12913
|
+
institutionId,
|
|
12914
|
+
// Funções de autenticação
|
|
12915
|
+
authFunctions
|
|
12916
|
+
};
|
|
12917
|
+
}
|
|
12918
|
+
|
|
12919
|
+
// src/hooks/useAppContent.ts
|
|
12920
|
+
import { useCallback as useCallback7, useEffect as useEffect24, useMemo as useMemo9 } from "react";
|
|
12921
|
+
import { useNavigate as useNavigate2 } from "react-router-dom";
|
|
12922
|
+
function useAppContent(config) {
|
|
12923
|
+
const navigate = useNavigate2();
|
|
12924
|
+
const { setTokens, setSessionInfo, setSelectedProfile } = useAuthStore();
|
|
12925
|
+
const {
|
|
12926
|
+
api,
|
|
12927
|
+
getInstitutionId,
|
|
12928
|
+
initialize,
|
|
12929
|
+
initialized,
|
|
12930
|
+
endpoint = "/auth/session-info",
|
|
12931
|
+
maxRetries = 1,
|
|
12932
|
+
retryDelay = 2e3,
|
|
12933
|
+
onClearParamsFromURL,
|
|
12934
|
+
onError,
|
|
12935
|
+
onNotFoundNavigation
|
|
12936
|
+
} = config;
|
|
12937
|
+
const apiConfig = useApiConfig(api);
|
|
12938
|
+
useTheme();
|
|
12939
|
+
const handleNotFoundNavigation = () => {
|
|
12940
|
+
if (onNotFoundNavigation) {
|
|
12941
|
+
onNotFoundNavigation();
|
|
12942
|
+
} else {
|
|
12943
|
+
navigate("/painel");
|
|
12944
|
+
}
|
|
12945
|
+
};
|
|
12946
|
+
const handleSetSelectedProfile = useCallback7(
|
|
12947
|
+
(profile) => {
|
|
12948
|
+
setSelectedProfile(profile);
|
|
12949
|
+
},
|
|
12950
|
+
[setSelectedProfile]
|
|
12951
|
+
);
|
|
12952
|
+
const handleClearParamsFromURL = useCallback7(() => {
|
|
12953
|
+
if (onClearParamsFromURL) {
|
|
12954
|
+
onClearParamsFromURL();
|
|
12955
|
+
} else {
|
|
12956
|
+
globalThis.location.replace("/painel");
|
|
12957
|
+
}
|
|
12958
|
+
}, [onClearParamsFromURL]);
|
|
12959
|
+
const handleError = useCallback7(
|
|
12960
|
+
(error) => {
|
|
12961
|
+
if (onError) {
|
|
12962
|
+
onError(error);
|
|
12963
|
+
} else {
|
|
12964
|
+
console.error("Erro ao obter informa\xE7\xF5es da sess\xE3o:", error);
|
|
12965
|
+
navigate("/", { replace: true });
|
|
12966
|
+
}
|
|
12967
|
+
},
|
|
12968
|
+
[navigate, onError]
|
|
12969
|
+
);
|
|
12970
|
+
const urlAuthConfig = useMemo9(
|
|
12971
|
+
() => ({
|
|
12972
|
+
setTokens,
|
|
12973
|
+
setSessionInfo,
|
|
12974
|
+
setSelectedProfile: handleSetSelectedProfile,
|
|
12975
|
+
api: apiConfig,
|
|
12976
|
+
endpoint,
|
|
12977
|
+
clearParamsFromURL: handleClearParamsFromURL,
|
|
12978
|
+
maxRetries,
|
|
12979
|
+
retryDelay,
|
|
12980
|
+
onError: handleError
|
|
12981
|
+
}),
|
|
12982
|
+
[
|
|
12983
|
+
setTokens,
|
|
12984
|
+
setSessionInfo,
|
|
12985
|
+
handleSetSelectedProfile,
|
|
12986
|
+
apiConfig,
|
|
12987
|
+
endpoint,
|
|
12988
|
+
handleClearParamsFromURL,
|
|
12989
|
+
maxRetries,
|
|
12990
|
+
retryDelay,
|
|
12991
|
+
handleError
|
|
12992
|
+
]
|
|
12993
|
+
);
|
|
12994
|
+
useUrlAuthentication(urlAuthConfig);
|
|
12995
|
+
const { sessionInfo } = useAuth();
|
|
12996
|
+
const institutionIdToUse = useMemo9(() => {
|
|
12997
|
+
return sessionInfo?.institutionId || getInstitutionId;
|
|
12998
|
+
}, [sessionInfo?.institutionId, getInstitutionId]);
|
|
12999
|
+
useEffect24(() => {
|
|
13000
|
+
if (institutionIdToUse && !initialized) {
|
|
13001
|
+
initialize(institutionIdToUse);
|
|
13002
|
+
}
|
|
13003
|
+
}, [institutionIdToUse, initialize, initialized]);
|
|
13004
|
+
return {
|
|
13005
|
+
handleNotFoundNavigation,
|
|
13006
|
+
urlAuthConfig,
|
|
13007
|
+
institutionIdToUse
|
|
13008
|
+
};
|
|
13009
|
+
}
|
|
12488
13010
|
export {
|
|
12489
13011
|
ANSWER_STATUS,
|
|
12490
13012
|
Alert_default as Alert,
|
|
@@ -12492,6 +13014,7 @@ export {
|
|
|
12492
13014
|
AlternativesList,
|
|
12493
13015
|
AuthProvider,
|
|
12494
13016
|
Badge_default as Badge,
|
|
13017
|
+
BreadcrumbMenu,
|
|
12495
13018
|
Button_default as Button,
|
|
12496
13019
|
Calendar_default as Calendar,
|
|
12497
13020
|
CardAccordation,
|
|
@@ -12611,8 +13134,15 @@ export {
|
|
|
12611
13134
|
getSubjectName,
|
|
12612
13135
|
syncDropdownState,
|
|
12613
13136
|
useApiConfig,
|
|
13137
|
+
useAppContent,
|
|
13138
|
+
useAppInitialization,
|
|
13139
|
+
useAppStore,
|
|
12614
13140
|
useAuth,
|
|
12615
13141
|
useAuthGuard,
|
|
13142
|
+
useAuthStore,
|
|
13143
|
+
useBreadcrumb,
|
|
13144
|
+
useBreadcrumbBuilder,
|
|
13145
|
+
useInstitutionId,
|
|
12616
13146
|
useMobile,
|
|
12617
13147
|
useQuizStore,
|
|
12618
13148
|
useRouteAuth,
|
|
@@ -12620,6 +13150,7 @@ export {
|
|
|
12620
13150
|
useThemeStore,
|
|
12621
13151
|
ToastStore_default as useToastStore,
|
|
12622
13152
|
useUrlAuthentication,
|
|
13153
|
+
useUrlParams,
|
|
12623
13154
|
withAuth
|
|
12624
13155
|
};
|
|
12625
13156
|
//# sourceMappingURL=index.mjs.map
|