mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-20 23:21:06 +02:00
refactor(dashboard): replace onboarding redirect with declarative setup gate
This commit is contained in:
parent
5efd4291bf
commit
dc582a7716
1 changed files with 53 additions and 91 deletions
|
|
@ -4,15 +4,9 @@ import { useAtomValue, useSetAtom } from "jotai";
|
||||||
import { useParams, usePathname, useRouter } from "next/navigation";
|
import { useParams, usePathname, useRouter } from "next/navigation";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import type React from "react";
|
import type React from "react";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect } from "react";
|
||||||
import { pendingUserImageDataUrlsAtom } from "@/atoms/chat/pending-user-images.atom";
|
import { pendingUserImageDataUrlsAtom } from "@/atoms/chat/pending-user-images.atom";
|
||||||
import { myAccessAtom } from "@/atoms/members/members-query.atoms";
|
import { llmSetupStatusAtomFamily } from "@/atoms/model-connections/model-connections-query.atoms";
|
||||||
import {
|
|
||||||
globalLlmConfigStatusAtom,
|
|
||||||
globalModelConnectionsAtom,
|
|
||||||
modelConnectionsAtom,
|
|
||||||
modelRolesAtom,
|
|
||||||
} from "@/atoms/model-connections/model-connections-query.atoms";
|
|
||||||
import { activeWorkspaceIdAtom } from "@/atoms/workspaces/workspace-query.atoms";
|
import { activeWorkspaceIdAtom } from "@/atoms/workspaces/workspace-query.atoms";
|
||||||
import { ConnectorIndicator } from "@/components/assistant-ui/connector-popup";
|
import { ConnectorIndicator } from "@/components/assistant-ui/connector-popup";
|
||||||
import { DocumentUploadDialogProvider } from "@/components/assistant-ui/document-upload-popup";
|
import { DocumentUploadDialogProvider } from "@/components/assistant-ui/document-upload-popup";
|
||||||
|
|
@ -22,7 +16,6 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/com
|
||||||
import { useFolderSync } from "@/hooks/use-folder-sync";
|
import { useFolderSync } from "@/hooks/use-folder-sync";
|
||||||
import { useGlobalLoadingEffect } from "@/hooks/use-global-loading";
|
import { useGlobalLoadingEffect } from "@/hooks/use-global-loading";
|
||||||
import { useElectronAPI } from "@/hooks/use-platform";
|
import { useElectronAPI } from "@/hooks/use-platform";
|
||||||
import { isLlmOnboardingComplete } from "@/lib/onboarding";
|
|
||||||
|
|
||||||
export function DashboardClientLayout({
|
export function DashboardClientLayout({
|
||||||
children,
|
children,
|
||||||
|
|
@ -39,85 +32,39 @@ export function DashboardClientLayout({
|
||||||
const setActiveWorkspaceIdState = useSetAtom(activeWorkspaceIdAtom);
|
const setActiveWorkspaceIdState = useSetAtom(activeWorkspaceIdAtom);
|
||||||
const setPendingUserImageUrls = useSetAtom(pendingUserImageDataUrlsAtom);
|
const setPendingUserImageUrls = useSetAtom(pendingUserImageDataUrlsAtom);
|
||||||
|
|
||||||
const { data: modelRoles = {}, isLoading: loading, error } = useAtomValue(modelRolesAtom);
|
// Single source of truth for the onboarding gate. Keyed by the route
|
||||||
const { data: globalConnections = [], isLoading: globalConfigsLoading } = useAtomValue(
|
// workspaceId so the verdict can never lag behind a workspace switch.
|
||||||
globalModelConnectionsAtom
|
const {
|
||||||
);
|
data: setupStatus,
|
||||||
const { data: modelConnections = [], isLoading: modelConnectionsLoading } =
|
isLoading: setupLoading,
|
||||||
useAtomValue(modelConnectionsAtom);
|
error: setupError,
|
||||||
const { data: globalConfigStatus, isLoading: globalConfigStatusLoading } =
|
} = useAtomValue(llmSetupStatusAtomFamily(Number(workspaceId)));
|
||||||
useAtomValue(globalLlmConfigStatusAtom);
|
|
||||||
|
|
||||||
const { data: access = null, isLoading: accessLoading } = useAtomValue(myAccessAtom);
|
|
||||||
const [hasCheckedOnboarding, setHasCheckedOnboarding] = useState(false);
|
|
||||||
|
|
||||||
const isOnboardingPage = pathname?.includes("/onboard");
|
const isOnboardingPage = pathname?.includes("/onboard");
|
||||||
const isOwner = access?.is_owner ?? false;
|
|
||||||
const isWorkspaceReady = activeWorkspaceId === workspaceId;
|
const isWorkspaceReady = activeWorkspaceId === workspaceId;
|
||||||
|
|
||||||
|
const needsSetup = setupStatus?.status === "needs_setup";
|
||||||
|
const isReady = setupStatus?.status === "ready";
|
||||||
|
const canConfigure = setupStatus?.can_configure ?? false;
|
||||||
|
|
||||||
|
// Redirect into onboarding (configurable members) or out of it (workspace
|
||||||
|
// became ready). Both directions live here; the pages themselves are dumb.
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isWorkspaceReady) return;
|
if (setupLoading || setupError) return;
|
||||||
setHasCheckedOnboarding(false);
|
if (needsSetup && canConfigure && !isOnboardingPage) {
|
||||||
}, [isWorkspaceReady]);
|
router.replace(`/dashboard/${workspaceId}/onboard`);
|
||||||
|
} else if (isReady && isOnboardingPage) {
|
||||||
useEffect(() => {
|
router.replace(`/dashboard/${workspaceId}/new-chat`);
|
||||||
if (isOnboardingPage) {
|
|
||||||
setHasCheckedOnboarding(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
isWorkspaceReady &&
|
|
||||||
!loading &&
|
|
||||||
!accessLoading &&
|
|
||||||
!globalConfigsLoading &&
|
|
||||||
!globalConfigStatusLoading &&
|
|
||||||
!modelConnectionsLoading &&
|
|
||||||
!hasCheckedOnboarding
|
|
||||||
) {
|
|
||||||
// Onboarding is only relevant when no operator-provided
|
|
||||||
// global_llm_config.yaml exists. When it does, workspaces inherit
|
|
||||||
// the global config and should never be forced into onboarding.
|
|
||||||
if (globalConfigStatus?.exists) {
|
|
||||||
setHasCheckedOnboarding(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const onboardingComplete = isLlmOnboardingComplete(
|
|
||||||
modelRoles.chat_model_id,
|
|
||||||
globalConnections,
|
|
||||||
modelConnections
|
|
||||||
);
|
|
||||||
|
|
||||||
if (onboardingComplete) {
|
|
||||||
setHasCheckedOnboarding(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isOwner) {
|
|
||||||
setHasCheckedOnboarding(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
router.push(`/dashboard/${workspaceId}/onboard`);
|
|
||||||
setHasCheckedOnboarding(true);
|
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
isWorkspaceReady,
|
setupLoading,
|
||||||
loading,
|
setupError,
|
||||||
accessLoading,
|
needsSetup,
|
||||||
globalConfigsLoading,
|
canConfigure,
|
||||||
globalConfigStatusLoading,
|
isReady,
|
||||||
globalConfigStatus,
|
|
||||||
modelConnectionsLoading,
|
|
||||||
modelRoles.chat_model_id,
|
|
||||||
globalConnections,
|
|
||||||
modelConnections,
|
|
||||||
isOnboardingPage,
|
isOnboardingPage,
|
||||||
isOwner,
|
|
||||||
router,
|
router,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
hasCheckedOnboarding,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const electronAPI = useElectronAPI();
|
const electronAPI = useElectronAPI();
|
||||||
|
|
@ -167,18 +114,16 @@ export function DashboardClientLayout({
|
||||||
}
|
}
|
||||||
}, [workspace_id, setActiveWorkspaceIdState, electronAPI]);
|
}, [workspace_id, setActiveWorkspaceIdState, electronAPI]);
|
||||||
|
|
||||||
// Determine if we should show loading
|
// Currently navigating between onboarding and the dashboard.
|
||||||
const shouldShowLoading =
|
const isRedirecting =
|
||||||
!hasCheckedOnboarding &&
|
!setupLoading &&
|
||||||
(!isWorkspaceReady ||
|
!setupError &&
|
||||||
loading ||
|
((needsSetup && canConfigure && !isOnboardingPage) || (isReady && isOnboardingPage));
|
||||||
accessLoading ||
|
|
||||||
globalConfigsLoading ||
|
// Block children until the workspace is synced and the setup verdict is in,
|
||||||
globalConfigStatusLoading ||
|
// so an unconfigured workspace never flashes the composer.
|
||||||
modelConnectionsLoading) &&
|
const shouldShowLoading = !setupError && (!isWorkspaceReady || setupLoading || isRedirecting);
|
||||||
!isOnboardingPage;
|
|
||||||
|
|
||||||
// Use global loading screen - spinner animation won't reset
|
|
||||||
useGlobalLoadingEffect(shouldShowLoading);
|
useGlobalLoadingEffect(shouldShowLoading);
|
||||||
|
|
||||||
// Wire desktop app file watcher -> single-file re-index API
|
// Wire desktop app file watcher -> single-file re-index API
|
||||||
|
|
@ -188,7 +133,7 @@ export function DashboardClientLayout({
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error && !hasCheckedOnboarding && !isOnboardingPage) {
|
if (setupError) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
<div className="flex flex-col items-center justify-center min-h-screen space-y-4">
|
||||||
<Card className="w-[400px] bg-background/60 backdrop-blur-sm border-destructive/20">
|
<Card className="w-[400px] bg-background/60 backdrop-blur-sm border-destructive/20">
|
||||||
|
|
@ -200,7 +145,7 @@ export function DashboardClientLayout({
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
{error instanceof Error ? error.message : String(error)}
|
{setupError instanceof Error ? setupError.message : String(setupError)}
|
||||||
</p>
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
@ -208,6 +153,23 @@ export function DashboardClientLayout({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Member without permission to connect a model in an unconfigured workspace.
|
||||||
|
if (needsSetup && !canConfigure) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center justify-center min-h-screen p-4">
|
||||||
|
<Card className="w-[440px] bg-background/60 backdrop-blur-sm">
|
||||||
|
<CardHeader className="pb-2">
|
||||||
|
<CardTitle className="text-xl font-medium">No model available</CardTitle>
|
||||||
|
<CardDescription>
|
||||||
|
A workspace admin needs to connect a language model before chat is available
|
||||||
|
here.
|
||||||
|
</CardDescription>
|
||||||
|
</CardHeader>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (isOnboardingPage) {
|
if (isOnboardingPage) {
|
||||||
return <>{children}</>;
|
return <>{children}</>;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue