diff --git a/AdminPanel/client/src/components/AuthWrapper/AuthWrapper.js b/AdminPanel/client/src/components/AuthWrapper/AuthWrapper.js index 8d716516..ec254143 100644 --- a/AdminPanel/client/src/components/AuthWrapper/AuthWrapper.js +++ b/AdminPanel/client/src/components/AuthWrapper/AuthWrapper.js @@ -1,6 +1,5 @@ import {useEffect, useState} from 'react'; import {useDispatch, useSelector} from 'react-redux'; -import {useLocation, useNavigate} from 'react-router-dom'; import {fetchUser, selectUser, selectUserLoading, selectIsAuthenticated} from '../../store/slices/userSlice'; import {checkSetupRequired} from '../../api'; import Spinner from '../../assets/Spinner.svg'; @@ -10,8 +9,6 @@ import ServerUnavailable from '../ServerUnavailable/ServerUnavailable'; export default function AuthWrapper({children}) { const dispatch = useDispatch(); - const location = useLocation(); - const navigate = useNavigate(); const user = useSelector(selectUser); const loading = useSelector(selectUserLoading); const isAuthenticated = useSelector(selectIsAuthenticated); @@ -20,24 +17,6 @@ export default function AuthWrapper({children}) { const [checkingSetup, setCheckingSetup] = useState(true); const [serverUnavailable, setServerUnavailable] = useState(false); - // Save intended URL for redirect after setup/login - useEffect(() => { - if (!isAuthenticated && location.pathname !== '/admin/setup' && location.pathname !== '/admin/login') { - sessionStorage.setItem('redirectAfterAuth', location.pathname + location.search); - } - }, [location, isAuthenticated]); - - // Redirect after successful authentication - useEffect(() => { - if (isAuthenticated && user) { - const redirectUrl = sessionStorage.getItem('redirectAfterAuth'); - if (redirectUrl) { - sessionStorage.removeItem('redirectAfterAuth'); - navigate(redirectUrl, {replace: true}); - } - } - }, [isAuthenticated, user, navigate]); - useEffect(() => { const checkSetup = async () => { try { diff --git a/AdminPanel/client/src/pages/AiIntegration/ai/scripts/engine/providers/base.js b/AdminPanel/client/src/pages/AiIntegration/ai/scripts/engine/providers/base.js index 06b6fffd..df6a80b3 100644 --- a/AdminPanel/client/src/pages/AiIntegration/ai/scripts/engine/providers/base.js +++ b/AdminPanel/client/src/pages/AiIntegration/ai/scripts/engine/providers/base.js @@ -194,6 +194,8 @@ } AI.onLoadInternalProviders(); + if (Asc.plugin.sendEvent) + Asc.plugin.sendEvent("ai_onLoadInternalProviders"); }; AI.InternalCustomProvidersSources = {}; diff --git a/AdminPanel/client/src/pages/AiIntegration/hooks/useAiPlugin.js b/AdminPanel/client/src/pages/AiIntegration/hooks/useAiPlugin.js index 88d11f3c..03787324 100644 --- a/AdminPanel/client/src/pages/AiIntegration/hooks/useAiPlugin.js +++ b/AdminPanel/client/src/pages/AiIntegration/hooks/useAiPlugin.js @@ -1,7 +1,13 @@ import {useState, useEffect, useCallback} from 'react'; import {useSelector, useDispatch} from 'react-redux'; import {selectConfig, saveConfig} from '../../../store/slices/configSlice'; -import {registerShowWindowCallback, registerCloseWindowCallback, registerSaveCallback, initAISettings} from '../js/plugins-sdk'; +import { + registerShowWindowCallback, + registerCloseWindowCallback, + registerSaveCallback, + registerLoadInternalProvidersCallback, + initAISettings +} from '../js/plugins-sdk'; /** * Custom hook for managing complete AI plugin functionality @@ -11,6 +17,7 @@ import {registerShowWindowCallback, registerCloseWindowCallback, registerSaveCal */ const useAiPlugin = statisticsData => { const [pluginWindows, setPluginWindows] = useState([]); + const [internalProvidersLoaded, setInternalProvidersLoaded] = useState(false); const dispatch = useDispatch(); const config = useSelector(selectConfig); @@ -121,16 +128,22 @@ const useAiPlugin = statisticsData => { } }; + const handleLoadInternalProviders = () => { + setInternalProvidersLoaded(true); + }; + // Register all callbacks with SDK registerShowWindowCallback(handleShowWindow); registerCloseWindowCallback(handleCloseWindow); registerSaveCallback(handleSave); + registerLoadInternalProvidersCallback(handleLoadInternalProviders); // Cleanup: unregister all callbacks return () => { registerShowWindowCallback(null); registerCloseWindowCallback(null); registerSaveCallback(null); + registerLoadInternalProvidersCallback(null); }; }, [config, dispatch]); @@ -139,7 +152,8 @@ const useAiPlugin = statisticsData => { return { pluginWindows, currentWindow, - handleIframeLoad + handleIframeLoad, + internalProvidersLoaded }; }; diff --git a/AdminPanel/client/src/pages/AiIntegration/index.js b/AdminPanel/client/src/pages/AiIntegration/index.js index 903a68e0..931bb89c 100644 --- a/AdminPanel/client/src/pages/AiIntegration/index.js +++ b/AdminPanel/client/src/pages/AiIntegration/index.js @@ -23,7 +23,7 @@ export default function AiIntegration() { }); // Use custom hook for complete AI plugin functionality - const {currentWindow, handleIframeLoad} = useAiPlugin(data); + const {currentWindow, handleIframeLoad, internalProvidersLoaded} = useAiPlugin(data); // Constants const AI_IFRAME_SRC = `ai/index.html`; @@ -58,7 +58,8 @@ export default function AiIntegration() { return (