Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AddProviderInstanceDialog.logic.ts

36 lines1.3 KB

1export type WizardNavigation =
2 | { readonly kind: "navigate"; readonly step: number }
3 | { readonly kind: "blocked"; readonly step: number; readonly error: string };
4​
5const IDENTITY_STEP = 1;
6​
7export const ADD_PROVIDER_WIZARD_STEPS = ["Driver", "Identity", "Config"] as const;
8​
9/**
10 * Resolve navigation within the add-provider wizard.
11 *
12 * Moving forward past Identity requires a valid instance id, whether the user
13 * advances one step at a time or skips directly to Config from a step header.
14 * A blocked skip lands on Identity so its existing inline validation is
15 * visible. Backward navigation is always preserved.
16 */
17export function resolveWizardNavigation(
18 currentStep: number,
19 requestedStep: number,
20 stepCount: number,
21 validation: { readonly instanceIdError: string | null },
22): WizardNavigation {
23 const lastStep = Math.max(0, stepCount - 1);
24 const targetStep = Math.max(0, Math.min(lastStep, requestedStep));
25 const movesForwardPastIdentity = currentStep <= IDENTITY_STEP && targetStep > IDENTITY_STEP;
26​
27 if (movesForwardPastIdentity && validation.instanceIdError !== null) {
28 return {
29 kind: "blocked",
30 step: Math.min(IDENTITY_STEP, lastStep),
31 error: validation.instanceIdError,
32 };
33 }
34​
35 return { kind: "navigate", step: targetStep };