mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
fix(onboarding): properly resolve onboarding state, remove redirect trap in step-defaults, block waiting flash
This commit is contained in:
@@ -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">
|
||||||
|
|||||||
@@ -4,41 +4,71 @@ 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({
|
||||||
|
flowData: {
|
||||||
|
...state?.context.flowData,
|
||||||
|
defaults: { notifierId, storageId },
|
||||||
|
},
|
||||||
|
});
|
||||||
await next();
|
await next();
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,13 +76,25 @@ export const StepDefaults = () => {
|
|||||||
<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">
|
||||||
|
Optional — choose the default notifier and storage for new agents.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Default notifier</Label>
|
<Label>Default notifier</Label>
|
||||||
<Select value={notifierId} onValueChange={selectNotifier} disabled={notifiers.length === 0}>
|
<Select
|
||||||
|
value={notifierId}
|
||||||
|
onValueChange={selectNotifier}
|
||||||
|
disabled={notifiers.length === 0}
|
||||||
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder={notifiers.length === 0 ? "No notifier connected" : "Choose a notifier"} />
|
<SelectValue
|
||||||
|
placeholder={
|
||||||
|
notifiers.length === 0
|
||||||
|
? "No notifier connected"
|
||||||
|
: "Choose a notifier"
|
||||||
|
}
|
||||||
|
/>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{notifiers.map((n) => (
|
{notifiers.map((n) => (
|
||||||
@@ -65,9 +107,19 @@ export const StepDefaults = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-col gap-2">
|
||||||
<Label>Default storage</Label>
|
<Label>Default storage</Label>
|
||||||
<Select value={storageId} onValueChange={selectStorage} disabled={storages.length === 0}>
|
<Select
|
||||||
|
value={storageId}
|
||||||
|
onValueChange={selectStorage}
|
||||||
|
disabled={storages.length === 0}
|
||||||
|
>
|
||||||
<SelectTrigger>
|
<SelectTrigger>
|
||||||
<SelectValue placeholder={storages.length === 0 ? "No storage connected" : "Choose a storage"} />
|
<SelectValue
|
||||||
|
placeholder={
|
||||||
|
storages.length === 0
|
||||||
|
? "No storage connected"
|
||||||
|
: "Choose a storage"
|
||||||
|
}
|
||||||
|
/>
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
{storages.map((s) => (
|
{storages.map((s) => (
|
||||||
|
|||||||
Reference in New Issue
Block a user