mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
refactor(onboard): drive page from server setup status
This commit is contained in:
parent
dc582a7716
commit
13a7491cdd
1 changed files with 8 additions and 42 deletions
|
|
@ -2,66 +2,32 @@
|
|||
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useParams, useRouter } from "next/navigation";
|
||||
import { useEffect, useMemo } from "react";
|
||||
import { useEffect } from "react";
|
||||
import {
|
||||
globalLlmConfigStatusAtom,
|
||||
globalModelConnectionsAtom,
|
||||
llmSetupStatusAtomFamily,
|
||||
modelConnectionsAtom,
|
||||
modelRolesAtom,
|
||||
} from "@/atoms/model-connections/model-connections-query.atoms";
|
||||
import { Logo } from "@/components/Logo";
|
||||
import { ModelProviderConnectionsPanel } from "@/components/settings/model-connections/model-provider-connections-panel";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useGlobalLoadingEffect } from "@/hooks/use-global-loading";
|
||||
import { useSession } from "@/hooks/use-session";
|
||||
import { redirectToLogin } from "@/lib/auth-utils";
|
||||
import { hasEnabledChatModel, isLlmOnboardingComplete } from "@/lib/onboarding";
|
||||
|
||||
export default function OnboardPage() {
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const workspaceId = Number(params.workspace_id);
|
||||
const session = useSession();
|
||||
const { data: globalConnections = [], isLoading: globalLoading } = useAtomValue(
|
||||
globalModelConnectionsAtom
|
||||
);
|
||||
const { data: connections = [] } = useAtomValue(modelConnectionsAtom);
|
||||
const { data: roles = {}, isLoading: rolesLoading } = useAtomValue(modelRolesAtom);
|
||||
const { data: globalConfigStatus, isLoading: globalConfigStatusLoading } =
|
||||
useAtomValue(globalLlmConfigStatusAtom);
|
||||
const { data: setupStatus } = useAtomValue(llmSetupStatusAtomFamily(workspaceId));
|
||||
|
||||
useEffect(() => {
|
||||
if (session.status === "unauthenticated") redirectToLogin();
|
||||
}, [session.status]);
|
||||
|
||||
const hasUsableChatModel = useMemo(
|
||||
() => hasEnabledChatModel([...globalConnections, ...connections]),
|
||||
[globalConnections, connections]
|
||||
);
|
||||
|
||||
const onboardingComplete = isLlmOnboardingComplete(
|
||||
roles.chat_model_id,
|
||||
globalConnections,
|
||||
connections
|
||||
);
|
||||
|
||||
const isLoading =
|
||||
session.status === "loading" || globalLoading || rolesLoading || globalConfigStatusLoading;
|
||||
|
||||
// Onboarding only applies when no global_llm_config.yaml exists. If a global
|
||||
// config is present (or onboarding is already complete), leave this page.
|
||||
const shouldLeaveOnboarding =
|
||||
!isLoading && (Boolean(globalConfigStatus?.exists) || onboardingComplete);
|
||||
|
||||
useEffect(() => {
|
||||
if (shouldLeaveOnboarding) {
|
||||
router.replace(`/dashboard/${workspaceId}/new-chat`);
|
||||
}
|
||||
}, [shouldLeaveOnboarding, router, workspaceId]);
|
||||
|
||||
useGlobalLoadingEffect(isLoading || shouldLeaveOnboarding);
|
||||
|
||||
if (isLoading || shouldLeaveOnboarding) return null;
|
||||
// Leaving onboarding is the layout gate's job; here we only enable the
|
||||
// explicit CTA once the workspace can chat.
|
||||
const isReady = setupStatus?.status === "ready";
|
||||
|
||||
return (
|
||||
<div className="flex min-h-screen select-none flex-col items-center justify-center bg-main-panel p-4">
|
||||
|
|
@ -80,8 +46,8 @@ export default function OnboardPage() {
|
|||
footerAction={
|
||||
<Button
|
||||
className="min-w-[112px]"
|
||||
disabled={!onboardingComplete || !hasUsableChatModel}
|
||||
onClick={() => router.push(`/dashboard/${workspaceId}/new-chat`)}
|
||||
disabled={!isReady}
|
||||
onClick={() => router.replace(`/dashboard/${workspaceId}/new-chat`)}
|
||||
>
|
||||
Start
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue