@@ -4,38 +4,35 @@ import { Badge, Box, Button, descriptors, Flex, Icon, Spinner, Text, useLocaliza
44import { CaretLeft , CaretRight } from '@/icons' ;
55import { Route , Switch , useRouter } from '@/router' ;
66
7- import type { WizardInnerStep , WizardStep } from './types' ;
8- import { useWizard , WizardProvider } from './WizardContext' ;
7+ import { useConfigureSSOFlow } from '../ConfigureSSOContext' ;
8+ import { ConfigureSSOWizardProvider , useConfigureSSOWizard } from './ConfigureSSOWizardContext' ;
9+ import type { ConfigureSSOWizardInnerStep , ConfigureSSOWizardStep } from './types' ;
910
10- interface WizardRootProps < TData = unknown > {
11- steps : ReadonlyArray < WizardStep < TData > > ;
12- /**
13- * Optional data passed to each step's `shouldSkip` predicate. When the
14- * referenced shape changes, the active step list is recomputed
15- */
16- data ?: TData ;
17- /**
18- * `true` while the parent flow is still loading async dependencies.
19- * The header renders a skeleton breadcrumb, the content renders a
20- * centered spinner, and the footer's buttons are disabled
21- */
22- isLoading ?: boolean ;
11+ interface ConfigureSSOWizardRootProps {
12+ steps : ReadonlyArray < ConfigureSSOWizardStep > ;
2313 children : React . ReactNode ;
2414}
2515
26- const Root = < TData , > ( props : WizardRootProps < TData > ) : JSX . Element => {
27- const { steps, data, isLoading = false , children } = props ;
16+ /**
17+ * Top-level wizard scaffold for the ConfigureSSO flow. Sources its
18+ * `data` and `isLoading` from `useConfigureSSOFlow()` directly, so it
19+ * must be rendered inside `<ConfigureSSOFlowProvider>`
20+ */
21+ const Root = ( props : ConfigureSSOWizardRootProps ) : JSX . Element => {
22+ const { steps, children } = props ;
2823 const router = useRouter ( ) ;
24+ const data = useConfigureSSOFlow ( ) ;
25+ const { isLoading } = data ;
2926
30- const activeSteps = React . useMemo ( ( ) => steps . filter ( s => ! s . shouldSkip ?.( data as TData ) ) , [ steps , data ] ) ;
27+ const activeSteps = React . useMemo ( ( ) => steps . filter ( s => ! s . shouldSkip ?.( data ) ) , [ steps , data ] ) ;
3128
3229 const getActiveInnerSteps = React . useCallback (
33- ( step : WizardStep < TData > | undefined ) : WizardInnerStep < TData > [ ] =>
34- step ?. innerSteps ?. filter ( s => ! s . shouldSkip ?.( data as TData ) ) ?? [ ] ,
30+ ( step : ConfigureSSOWizardStep | undefined ) : ConfigureSSOWizardInnerStep [ ] =>
31+ step ?. innerSteps ?. filter ( s => ! s . shouldSkip ?.( data ) ) ?? [ ] ,
3532 [ data ] ,
3633 ) ;
3734
38- const currentStep = React . useMemo < WizardStep < TData > | undefined > ( ( ) => {
35+ const currentStep = React . useMemo < ConfigureSSOWizardStep | undefined > ( ( ) => {
3936 if ( activeSteps . length === 0 ) {
4037 return undefined ;
4138 }
@@ -57,7 +54,7 @@ const Root = <TData,>(props: WizardRootProps<TData>): JSX.Element => {
5754 // is the catch-all, the first inner step of any main
5855 // step is its parent's index route (no segment)
5956 const buildPath = React . useCallback (
60- ( mainStep : WizardStep < TData > , innerStep ?: WizardInnerStep < TData > ) : string => {
57+ ( mainStep : ConfigureSSOWizardStep , innerStep ?: ConfigureSSOWizardInnerStep ) : string => {
6158 const inners = getActiveInnerSteps ( mainStep ) ;
6259 const target = innerStep ?? inners [ 0 ] ;
6360 const isFirstMain = activeSteps [ 0 ] ?. id === mainStep . id ;
@@ -68,7 +65,7 @@ const Root = <TData,>(props: WizardRootProps<TData>): JSX.Element => {
6865 [ activeSteps , getActiveInnerSteps ] ,
6966 ) ;
7067
71- const currentInnerStep = React . useMemo < WizardInnerStep < TData > | undefined > ( ( ) => {
68+ const currentInnerStep = React . useMemo < ConfigureSSOWizardInnerStep | undefined > ( ( ) => {
7269 if ( ! currentStep || innerSteps . length === 0 ) {
7370 return undefined ;
7471 }
@@ -82,7 +79,7 @@ const Root = <TData,>(props: WizardRootProps<TData>): JSX.Element => {
8279 } , [ currentStep , innerSteps , router , buildPath ] ) ;
8380
8481 const navigateTo = React . useCallback (
85- ( mainStep : WizardStep < TData > | undefined , innerStep ?: WizardInnerStep < TData > ) =>
82+ ( mainStep : ConfigureSSOWizardStep | undefined , innerStep ?: ConfigureSSOWizardInnerStep ) =>
8683 mainStep ? router . navigate ( buildPath ( mainStep , innerStep ) ) : undefined ,
8784 [ router , buildPath ] ,
8885 ) ;
@@ -128,7 +125,7 @@ const Root = <TData,>(props: WizardRootProps<TData>): JSX.Element => {
128125 ) ;
129126
130127 return (
131- < WizardProvider
128+ < ConfigureSSOWizardProvider
132129 activeSteps = { activeSteps }
133130 currentStep = { currentStep }
134131 innerSteps = { innerSteps }
@@ -139,15 +136,15 @@ const Root = <TData,>(props: WizardRootProps<TData>): JSX.Element => {
139136 goToStep = { goToStep }
140137 >
141138 { children }
142- </ WizardProvider >
139+ </ ConfigureSSOWizardProvider >
143140 ) ;
144141} ;
145142
146143/**
147144 * Renders a container step's inner sub-routes, or falls back to the
148145 * step's own `Component` for leaf steps
149146 */
150- const StepRoutes = < TData , > ( { step } : { step : WizardStep < TData > } ) : JSX . Element | null => {
147+ const StepRoutes = ( { step } : { step : ConfigureSSOWizardStep } ) : JSX . Element | null => {
151148 const Component = step . Component ;
152149 if ( ! step . innerSteps ?. length ) {
153150 return Component ? < Component /> : null ;
@@ -176,7 +173,7 @@ const StepRoutes = <TData,>({ step }: { step: WizardStep<TData> }): JSX.Element
176173 * doesn't match another main step (e.g. its own inner-step paths)
177174 */
178175const Content = ( ) : JSX . Element | null => {
179- const { activeSteps, isLoading } = useWizard ( ) ;
176+ const { activeSteps, isLoading } = useConfigureSSOWizard ( ) ;
180177
181178 if ( isLoading ) {
182179 return (
@@ -222,7 +219,7 @@ const Content = (): JSX.Element | null => {
222219 * are clickable for backwards navigation, future steps are disabled
223220 */
224221const Header = ( ) : JSX . Element => {
225- const { activeSteps, currentIndex, isLoading, goToStep } = useWizard ( ) ;
222+ const { activeSteps, currentIndex, isLoading, goToStep } = useConfigureSSOWizard ( ) ;
226223 const { t } = useLocalizations ( ) ;
227224
228225 return (
@@ -335,7 +332,7 @@ const SkeletonBreadcrumbStep = (): JSX.Element => (
335332 * need to reserve room for it
336333 */
337334const StepIndicator = ( ) : JSX . Element | null => {
338- const { totalInnerSteps, currentInnerIndex } = useWizard ( ) ;
335+ const { totalInnerSteps, currentInnerIndex } = useConfigureSSOWizard ( ) ;
339336
340337 if ( totalInnerSteps <= 0 || currentInnerIndex < 0 ) {
341338 return null ;
@@ -391,7 +388,7 @@ interface FooterProps {
391388 */
392389const Footer = ( props : FooterProps ) : JSX . Element => {
393390 const { previousLabel = 'Previous' , continueLabel = 'Continue' , hidePrevious = false , isDisabled = false } = props ;
394- const { isFirstStep, isLastStep, isLoading, goPrev, goNext, continueAction } = useWizard ( ) ;
391+ const { isFirstStep, isLastStep, isLoading, goPrev, goNext, continueAction } = useConfigureSSOWizard ( ) ;
395392 const isForceDisabled = isDisabled || isLoading ;
396393 const { t } = useLocalizations ( ) ;
397394
@@ -457,7 +454,7 @@ const Footer = (props: FooterProps): JSX.Element => {
457454 ) ;
458455} ;
459456
460- export const Wizard = {
457+ export const ConfigureSSOWizard = {
461458 Root,
462459 Header,
463460 Content,
0 commit comments