Files
prowler/ui/components/onboarding/onboarding-trigger.logic.ts
Alan Buscaglia 49309b43d3 feat(ui): UI onboarding system (#11430)
Co-authored-by: Pablo F.G <pablo.fernandez@prowler.com>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
Co-authored-by: Alejandro Bailo <59607668+alejandrobailo@users.noreply.github.com>
2026-06-15 13:53:48 +02:00

49 lines
1.7 KiB
TypeScript

import type { TourCompletionRecord } from "@/lib/tours/tour-types";
import type { OnboardingSequenceMode } from "@/store/onboarding-sequence";
// Flat, framework-free inputs for `resolveTriggerRequest` — unit-testable without React.
export interface TriggerRequestInput {
param: string | null; // `?onboarding=<id>` value, or null
replayRequestFlowId: string | null; // in-memory replay request (same-route navbar), or null
sliceActive: boolean;
currentFlowId: string | null; // flow the active sequence points at
flowId: string; // flow this route owns
}
// Resolved start request, or null when this route's flow should not start.
export interface TriggerRequest {
start: true;
mode: OnboardingSequenceMode;
}
// Replay (param or in-memory request) takes precedence over the sequence so a
// manual replay is never hijacked. The in-memory request is how the navbar starts
// a same-route replay without a `?onboarding=` URL param (which would force an RSC refetch).
export function resolveTriggerRequest({
param,
replayRequestFlowId,
sliceActive,
currentFlowId,
flowId,
}: TriggerRequestInput): TriggerRequest | null {
if (param === flowId) {
return { start: true, mode: "replay" };
}
if (replayRequestFlowId === flowId) {
return { start: true, mode: "replay" };
}
if (sliceActive && currentFlowId === flowId) {
return { start: true, mode: "sequence" };
}
return null;
}
// completed → advance the sequence; anything else → stop.
export type SequenceCloseAction = "advance" | "stop";
export function mapCloseToSequenceAction(
state: TourCompletionRecord["state"],
): SequenceCloseAction {
return state === "completed" ? "advance" : "stop";
}