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.
This commit is contained in:
Anish Sarkar 2026-06-07 17:53:18 +05:30
parent 39bc903eab
commit 901c72cdcc
3 changed files with 18 additions and 8 deletions

View file

@ -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);

View file

@ -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 () => {

View file

@ -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;
}