@@ -2,48 +2,45 @@ import { useEffect, useState } from "react";
22import { Navigate } from "react-router-dom" ;
33import { apiClient } from "../shared/api-client" ;
44import { setOnboardingRuntimeState } from "../shared/store/onboarding-runtime-store.ts" ;
5- import { getOnboardingProgress , useWizardStore } from "../shared/store/wizard-store" ;
5+ import { getOnboardingProgress , isOnboardingComplete , useWizardStore } from "../shared/store/wizard-store" ;
66
7- type CheckState = "loading" | "has-openclaw " | "no-openclaw " | "error" ;
7+ type CheckState = "loading" | "installed" | "resume-onboarding " | "start-onboarding " | "error" ;
88
99export function StartupGuard ( ) {
1010 const [ state , setState ] = useState < CheckState > ( "loading" ) ;
11- const [ hasProgress , setHasProgress ] = useState ( false ) ;
11+ const [ targetStep , setTargetStep ] = useState ( "welcome" ) ;
1212
1313 useEffect ( ( ) => {
1414 let cancelled = false ;
1515
16- const progress = getOnboardingProgress ( ) ;
17- if ( progress ) {
18- useWizardStore . getState ( ) . goToStep ( progress . lastStepId ) ;
19- setHasProgress ( true ) ;
20- setOnboardingRuntimeState ( {
21- startupCheck : "unknown" ,
22- hasOpenClaw : false ,
23- selectedTemplateId : null ,
24- initializedAssistantAt : null ,
25- assistantName : null ,
26- assistantWorkspacePath : null ,
27- } ) ;
28- setState ( "no-openclaw" ) ;
29- return ( ) => {
30- cancelled = true ;
31- } ;
32- }
33-
3416 apiClient
3517 . get < { hasOpenClaw : boolean } > ( "/openclaw/check-environment" )
3618 . then ( ( res ) => {
3719 if ( cancelled ) return ;
20+
21+ const progress = getOnboardingProgress ( ) ;
22+ const completed = isOnboardingComplete ( ) ;
23+ const nextStep = progress ?. lastStepId ?? "welcome" ;
24+
3825 setOnboardingRuntimeState ( {
3926 startupCheck : "ready" ,
4027 hasOpenClaw : res . hasOpenClaw ,
4128 selectedTemplateId : null ,
4229 initializedAssistantAt : null ,
4330 assistantName : null ,
4431 assistantWorkspacePath : null ,
32+ createdBotId : null ,
33+ createdBotName : null ,
4534 } ) ;
46- setState ( res . hasOpenClaw ? "has-openclaw" : "no-openclaw" ) ;
35+
36+ if ( res . hasOpenClaw ) {
37+ setState ( "installed" ) ;
38+ return ;
39+ }
40+
41+ useWizardStore . getState ( ) . goToStep ( nextStep ) ;
42+ setTargetStep ( nextStep ) ;
43+ setState ( progress || completed ? "resume-onboarding" : "start-onboarding" ) ;
4744 } )
4845 . catch ( ( ) => {
4946 if ( cancelled ) return ;
@@ -54,6 +51,8 @@ export function StartupGuard() {
5451 initializedAssistantAt : null ,
5552 assistantName : null ,
5653 assistantWorkspacePath : null ,
54+ createdBotId : null ,
55+ createdBotName : null ,
5756 } ) ;
5857 setState ( "error" ) ;
5958 } ) ;
@@ -108,16 +107,19 @@ export function StartupGuard() {
108107 ) ;
109108 }
110109
111- if ( state === "no-openclaw" || state === "has-openclaw" || state === "error" ) {
112- if ( ! hasProgress ) {
113- useWizardStore . getState ( ) . goToStep ( "welcome" ) ;
114- return < Navigate to = "/onboarding/welcome" replace /> ;
115- }
116- const progress = getOnboardingProgress ( ) ;
117- const targetStep = progress ?. lastStepId ?? "welcome" ;
110+ if ( state === "installed" ) {
111+ return < Navigate to = "/bots" replace /> ;
112+ }
113+
114+ if ( state === "resume-onboarding" ) {
118115 return < Navigate to = { `/onboarding/${ targetStep } ` } replace /> ;
119116 }
120117
118+ if ( state === "start-onboarding" ) {
119+ useWizardStore . getState ( ) . goToStep ( "welcome" ) ;
120+ return < Navigate to = "/onboarding/welcome" replace /> ;
121+ }
122+
121123 if ( state === "error" ) {
122124 useWizardStore . getState ( ) . goToStep ( "welcome" ) ;
123125 return < Navigate to = "/onboarding/welcome" replace /> ;
0 commit comments