fix(onboarding): properly resolve onboarding state, remove redirect trap in step-defaults, block waiting flash

This commit is contained in:
Théo LAGACHE
2026-06-19 13:26:47 +02:00
parent a140492688
commit 4f58488c66
3 changed files with 142 additions and 90 deletions
+17 -17
View File
@@ -118,6 +118,21 @@ export async function resolveOnboardingState(): Promise<ResolvedOnboardingState>
: {}),
};
if (project) {
meta.resumeStepId = "finish";
return { stepId: "finish", flowData: fullData };
}
if (agents && agents.length > 0) {
const firstAgent = agents[0];
const agentConnected = firstAgent?.lastContact
? Date.now() - new Date(firstAgent.lastContact).getTime() < 60_000
: false;
const stepId = agentConnected ? "project-create" : "agent-key";
meta.resumeStepId = stepId;
return { stepId, flowData: fullData };
}
if (notifiers.length === 0) {
meta.resumeStepId = "notifier";
return { stepId: "notifier", flowData: fullData };
@@ -128,21 +143,6 @@ export async function resolveOnboardingState(): Promise<ResolvedOnboardingState>
return { stepId: "storage", flowData: fullData };
}
if (!agents || agents.length === 0) {
meta.resumeStepId = "agent-create";
return { stepId: "agent-create", flowData: fullData };
}
if (!project) {
const firstAgent = agents[0];
const agentConnected = firstAgent?.lastContact
? Date.now() - new Date(firstAgent.lastContact).getTime() < 60_000
: false;
const stepId = agentConnected ? "project-create" : "agent-create";
meta.resumeStepId = stepId;
return { stepId, flowData: fullData };
}
meta.resumeStepId = "finish";
return { stepId: "finish", flowData: fullData };
meta.resumeStepId = "agent-create";
return { stepId: "agent-create", flowData: fullData };
}
@@ -17,9 +17,9 @@ export const StepAgentWaiting = () => {
}
}, [data?.connected, next]);
// Don't render until the first fetch completes if the agent is already
// connected, next() fires before the spinner is ever displayed.
if (isLoading) return null;
// Don't render until the first fetch completes, or if the agent is already
// connected (next() fires before the spinner is ever displayed).
if (isLoading || data?.connected) return null;
return (
<div className="flex flex-col items-center justify-center gap-4 h-full text-center">
+122 -70
View File
@@ -4,83 +4,135 @@ import { useState, useEffect, useRef } from "react";
import { useOnboarding } from "@onboardjs/react";
import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { OnboardingChannel, OnboardingDefaultsData } from "@/features/onboarding/types";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
OnboardingChannel,
OnboardingDefaultsData,
} from "@/features/onboarding/types";
import { updateNotificationSettingsAction } from "@/features/settings/notification.action";
import { updateStorageSettingsAction } from "@/features/settings/storage.action";
export const StepDefaults = () => {
const { next, updateContext, state } = useOnboarding();
const notifiers = (state?.context.flowData.notifiers ?? []) as OnboardingChannel[];
const storages = (state?.context.flowData.storages ?? []) as OnboardingChannel[];
const existingDefaults = (state?.context.flowData.defaults ?? {}) as OnboardingDefaultsData;
const [notifierId, setNotifierId] = useState<string | undefined>(existingDefaults.notifierId);
const [storageId, setStorageId] = useState<string | undefined>(existingDefaults.storageId);
const { next, updateContext, state } = useOnboarding();
const notifiers = (state?.context.flowData.notifiers ??
[]) as OnboardingChannel[];
const storages = (state?.context.flowData.storages ??
[]) as OnboardingChannel[];
const existingDefaults = (state?.context.flowData.defaults ??
{}) as OnboardingDefaultsData;
const [notifierId, setNotifierId] = useState<string | undefined>(
existingDefaults.notifierId,
);
const [storageId, setStorageId] = useState<string | undefined>(
existingDefaults.storageId,
);
const skipped = useRef(false);
useEffect(() => {
if (!skipped.current && notifiers.length === 0 && storages.length === 0) {
skipped.current = true;
next();
}
}, []);
const selectNotifier = async (value: string) => {
setNotifierId(value);
await updateNotificationSettingsAction({ name: "system", data: { notificationChannelId: value } });
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId: value, storageId } } });
};
const selectNotifier = async (value: string) => {
setNotifierId(value);
await updateNotificationSettingsAction({
name: "system",
data: { notificationChannelId: value },
});
await updateContext({
flowData: {
...state?.context.flowData,
defaults: { notifierId: value, storageId },
},
});
};
const selectStorage = async (value: string) => {
setStorageId(value);
await updateStorageSettingsAction({ name: "system", data: { storageChannelId: value, encryption: false } });
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId, storageId: value } } });
};
const selectStorage = async (value: string) => {
setStorageId(value);
await updateStorageSettingsAction({
name: "system",
data: { storageChannelId: value, encryption: false },
});
await updateContext({
flowData: {
...state?.context.flowData,
defaults: { notifierId, storageId: value },
},
});
};
const onContinue = async () => {
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId, storageId } } });
await next();
};
const onContinue = async () => {
await updateContext({
flowData: {
...state?.context.flowData,
defaults: { notifierId, storageId },
},
});
await next();
};
return (
<div className="flex flex-col gap-4">
<div>
<h1 className="text-2xl font-semibold">Set your defaults</h1>
<p className="text-sm text-muted-foreground mt-1">Optional choose the default notifier and storage for new agents.</p>
</div>
<div className="flex flex-col gap-2">
<Label>Default notifier</Label>
<Select value={notifierId} onValueChange={selectNotifier} disabled={notifiers.length === 0}>
<SelectTrigger>
<SelectValue placeholder={notifiers.length === 0 ? "No notifier connected" : "Choose a notifier"} />
</SelectTrigger>
<SelectContent>
{notifiers.map((n) => (
<SelectItem key={n.id} value={n.id}>
{n.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="flex flex-col gap-2">
<Label>Default storage</Label>
<Select value={storageId} onValueChange={selectStorage} disabled={storages.length === 0}>
<SelectTrigger>
<SelectValue placeholder={storages.length === 0 ? "No storage connected" : "Choose a storage"} />
</SelectTrigger>
<SelectContent>
{storages.map((s) => (
<SelectItem key={s.id} value={s.id}>
{s.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button type="button" onClick={onContinue}>
Continue
</Button>
</div>
);
return (
<div className="flex flex-col gap-4">
<div>
<h1 className="text-2xl font-semibold">Set your defaults</h1>
<p className="text-sm text-muted-foreground mt-1">
Optional choose the default notifier and storage for new agents.
</p>
</div>
<div className="flex flex-col gap-2">
<Label>Default notifier</Label>
<Select
value={notifierId}
onValueChange={selectNotifier}
disabled={notifiers.length === 0}
>
<SelectTrigger>
<SelectValue
placeholder={
notifiers.length === 0
? "No notifier connected"
: "Choose a notifier"
}
/>
</SelectTrigger>
<SelectContent>
{notifiers.map((n) => (
<SelectItem key={n.id} value={n.id}>
{n.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="flex flex-col gap-2">
<Label>Default storage</Label>
<Select
value={storageId}
onValueChange={selectStorage}
disabled={storages.length === 0}
>
<SelectTrigger>
<SelectValue
placeholder={
storages.length === 0
? "No storage connected"
: "Choose a storage"
}
/>
</SelectTrigger>
<SelectContent>
{storages.map((s) => (
<SelectItem key={s.id} value={s.id}>
{s.label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<Button type="button" onClick={onContinue}>
Continue
</Button>
</div>
);
};