From 901c72cdcc15133f91752230ceb0d24ede97ad07 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Sun, 7 Jun 2026 17:53:18 +0530 Subject: [PATCH] feat(onboarding): implement onboarding completion check utility - Added a new utility function `isLlmOnboardingComplete` to determine if the onboarding process is complete based on the agent LLM ID and the presence of global configurations. - Updated the onboarding logic in the `OnboardPage` and `DashboardClientLayout` components to utilize the new utility function for improved readability and maintainability. --- .../dashboard/[search_space_id]/client-layout.tsx | 6 +++--- .../app/dashboard/[search_space_id]/onboard/page.tsx | 12 +++++++----- surfsense_web/lib/onboarding.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 surfsense_web/lib/onboarding.ts diff --git a/surfsense_web/app/dashboard/[search_space_id]/client-layout.tsx b/surfsense_web/app/dashboard/[search_space_id]/client-layout.tsx index 7c9fcb1a0..3a41b5998 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/client-layout.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/client-layout.tsx @@ -21,6 +21,7 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com import { useFolderSync } from "@/hooks/use-folder-sync"; import { useGlobalLoadingEffect } from "@/hooks/use-global-loading"; import { useElectronAPI } from "@/hooks/use-platform"; +import { isLlmOnboardingComplete } from "@/lib/onboarding"; export function DashboardClientLayout({ children, @@ -47,9 +48,8 @@ export function DashboardClientLayout({ const { mutateAsync: updatePreferences } = useAtomValue(updateLLMPreferencesMutationAtom); const isOnboardingComplete = useCallback(() => { - // Check that the Agent LLM ID is set, including 0 for Auto mode. - return preferences.agent_llm_id !== null && preferences.agent_llm_id !== undefined; - }, [preferences.agent_llm_id]); + return isLlmOnboardingComplete(preferences.agent_llm_id, globalConfigs.length > 0); + }, [preferences.agent_llm_id, globalConfigs.length]); const { data: access = null, isLoading: accessLoading } = useAtomValue(myAccessAtom); const [hasCheckedOnboarding, setHasCheckedOnboarding] = useState(false); diff --git a/surfsense_web/app/dashboard/[search_space_id]/onboard/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/onboard/page.tsx index 6c1393a23..de5c961e8 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/onboard/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/onboard/page.tsx @@ -18,6 +18,7 @@ import { Button } from "@/components/ui/button"; import { Spinner } from "@/components/ui/spinner"; import { useGlobalLoadingEffect } from "@/hooks/use-global-loading"; import { getBearerToken, redirectToLogin } from "@/lib/auth-utils"; +import { isLlmOnboardingComplete } from "@/lib/onboarding"; export default function OnboardPage() { const router = useRouter(); @@ -52,15 +53,16 @@ export default function OnboardPage() { } }, []); - // Check if onboarding is already complete (including 0 for Auto mode) - const isOnboardingComplete = - preferences.agent_llm_id !== null && preferences.agent_llm_id !== undefined; + const isOnboardingComplete = isLlmOnboardingComplete( + preferences.agent_llm_id, + globalConfigs.length > 0 + ); useEffect(() => { - if (!preferencesLoading && isOnboardingComplete) { + if (!preferencesLoading && globalConfigsLoaded && isOnboardingComplete) { router.push(`/dashboard/${searchSpaceId}/new-chat`); } - }, [preferencesLoading, isOnboardingComplete, router, searchSpaceId]); + }, [preferencesLoading, globalConfigsLoaded, isOnboardingComplete, router, searchSpaceId]); useEffect(() => { const autoConfigureWithGlobal = async () => { diff --git a/surfsense_web/lib/onboarding.ts b/surfsense_web/lib/onboarding.ts new file mode 100644 index 000000000..b87f822a0 --- /dev/null +++ b/surfsense_web/lib/onboarding.ts @@ -0,0 +1,8 @@ +export function isLlmOnboardingComplete( + agentLlmId: number | null | undefined, + hasGlobalConfigs: boolean +): boolean { + if (agentLlmId === null || agentLlmId === undefined) return false; + if (agentLlmId === 0) return hasGlobalConfigs; + return true; +}