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) { if (notifiers.length === 0) {
meta.resumeStepId = "notifier"; meta.resumeStepId = "notifier";
return { stepId: "notifier", flowData: fullData }; return { stepId: "notifier", flowData: fullData };
@@ -128,21 +143,6 @@ export async function resolveOnboardingState(): Promise<ResolvedOnboardingState>
return { stepId: "storage", flowData: fullData }; return { stepId: "storage", flowData: fullData };
} }
if (!agents || agents.length === 0) { meta.resumeStepId = "agent-create";
meta.resumeStepId = "agent-create"; return { stepId: "agent-create", flowData: fullData };
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 };
} }
@@ -17,9 +17,9 @@ export const StepAgentWaiting = () => {
} }
}, [data?.connected, next]); }, [data?.connected, next]);
// Don't render until the first fetch completes if the agent is already // Don't render until the first fetch completes, or if the agent is already
// connected, next() fires before the spinner is ever displayed. // connected (next() fires before the spinner is ever displayed).
if (isLoading) return null; if (isLoading || data?.connected) return null;
return ( return (
<div className="flex flex-col items-center justify-center gap-4 h-full text-center"> <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 { useOnboarding } from "@onboardjs/react";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import {
import { OnboardingChannel, OnboardingDefaultsData } from "@/features/onboarding/types"; Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
OnboardingChannel,
OnboardingDefaultsData,
} from "@/features/onboarding/types";
import { updateNotificationSettingsAction } from "@/features/settings/notification.action"; import { updateNotificationSettingsAction } from "@/features/settings/notification.action";
import { updateStorageSettingsAction } from "@/features/settings/storage.action"; import { updateStorageSettingsAction } from "@/features/settings/storage.action";
export const StepDefaults = () => { export const StepDefaults = () => {
const { next, updateContext, state } = useOnboarding(); const { next, updateContext, state } = useOnboarding();
const notifiers = (state?.context.flowData.notifiers ?? []) as OnboardingChannel[]; const notifiers = (state?.context.flowData.notifiers ??
const storages = (state?.context.flowData.storages ?? []) as OnboardingChannel[]; []) as OnboardingChannel[];
const existingDefaults = (state?.context.flowData.defaults ?? {}) as OnboardingDefaultsData; const storages = (state?.context.flowData.storages ??
const [notifierId, setNotifierId] = useState<string | undefined>(existingDefaults.notifierId); []) as OnboardingChannel[];
const [storageId, setStorageId] = useState<string | undefined>(existingDefaults.storageId); 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) => { const selectNotifier = async (value: string) => {
setNotifierId(value); setNotifierId(value);
await updateNotificationSettingsAction({ name: "system", data: { notificationChannelId: value } }); await updateNotificationSettingsAction({
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId: value, storageId } } }); name: "system",
}; data: { notificationChannelId: value },
});
await updateContext({
flowData: {
...state?.context.flowData,
defaults: { notifierId: value, storageId },
},
});
};
const selectStorage = async (value: string) => { const selectStorage = async (value: string) => {
setStorageId(value); setStorageId(value);
await updateStorageSettingsAction({ name: "system", data: { storageChannelId: value, encryption: false } }); await updateStorageSettingsAction({
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId, storageId: value } } }); name: "system",
}; data: { storageChannelId: value, encryption: false },
});
await updateContext({
flowData: {
...state?.context.flowData,
defaults: { notifierId, storageId: value },
},
});
};
const onContinue = async () => { const onContinue = async () => {
await updateContext({ flowData: { ...state?.context.flowData, defaults: { notifierId, storageId } } }); await updateContext({
await next(); flowData: {
}; ...state?.context.flowData,
defaults: { notifierId, storageId },
},
});
await next();
};
return ( return (
<div className="flex flex-col gap-4"> <div className="flex flex-col gap-4">
<div> <div>
<h1 className="text-2xl font-semibold">Set your defaults</h1> <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> <p className="text-sm text-muted-foreground mt-1">
</div> Optional choose the default notifier and storage for new agents.
<div className="flex flex-col gap-2"> </p>
<Label>Default notifier</Label> </div>
<Select value={notifierId} onValueChange={selectNotifier} disabled={notifiers.length === 0}> <div className="flex flex-col gap-2">
<SelectTrigger> <Label>Default notifier</Label>
<SelectValue placeholder={notifiers.length === 0 ? "No notifier connected" : "Choose a notifier"} /> <Select
</SelectTrigger> value={notifierId}
<SelectContent> onValueChange={selectNotifier}
{notifiers.map((n) => ( disabled={notifiers.length === 0}
<SelectItem key={n.id} value={n.id}> >
{n.label} <SelectTrigger>
</SelectItem> <SelectValue
))} placeholder={
</SelectContent> notifiers.length === 0
</Select> ? "No notifier connected"
</div> : "Choose a notifier"
<div className="flex flex-col gap-2"> }
<Label>Default storage</Label> />
<Select value={storageId} onValueChange={selectStorage} disabled={storages.length === 0}> </SelectTrigger>
<SelectTrigger> <SelectContent>
<SelectValue placeholder={storages.length === 0 ? "No storage connected" : "Choose a storage"} /> {notifiers.map((n) => (
</SelectTrigger> <SelectItem key={n.id} value={n.id}>
<SelectContent> {n.label}
{storages.map((s) => ( </SelectItem>
<SelectItem key={s.id} value={s.id}> ))}
{s.label} </SelectContent>
</SelectItem> </Select>
))} </div>
</SelectContent> <div className="flex flex-col gap-2">
</Select> <Label>Default storage</Label>
</div> <Select
<Button type="button" onClick={onContinue}> value={storageId}
Continue onValueChange={selectStorage}
</Button> disabled={storages.length === 0}
</div> >
); <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>
);
}; };