@@ -6,83 +6,67 @@ import { Form, Title, Wizard, WizardStep, WizardStepType } from '@patternfly/rea
6
6
7
7
import { CreatePlanWizardFooter } from './components/CreatePlanWizardFooter' ;
8
8
import { GeneralInformationForm } from './steps/GeneralInformationForm' ;
9
- import {
10
- defaultCurrentStep ,
11
- getPlanWizardStepNames ,
12
- planStepIndexes ,
13
- PlanWizardStepId ,
14
- } from './constants' ;
9
+ import { defaultCurrentStep , planStepIndexes , planStepNames , PlanWizardStepId } from './constants' ;
10
+
11
+ import './CreatePlanWizard.style.css' ;
15
12
16
13
export const CreatePlanWizard : FC = ( ) => {
17
14
const { t } = useForkliftTranslation ( ) ;
18
15
const form = useForm ( { mode : 'onChange' } ) ;
19
16
const [ currentStep , setCurrentStep ] = useState < WizardStepType > ( defaultCurrentStep ) ;
20
17
const { formState, getValues } = form ;
21
18
const formValues = getValues ( ) ;
22
- const stepNames = getPlanWizardStepNames ( t ) ;
23
19
24
20
const onSubmit = ( ) => console . log ( 'SUBMITTED: ' , formValues ) ;
25
21
26
- const isStepDisabled = ( stepId : PlanWizardStepId ) =>
27
- currentStep ?. index < planStepIndexes [ stepId ] && Object . keys ( formState ?. errors ) . length > 0 ;
22
+ const getStepProps = ( id : PlanWizardStepId ) => ( {
23
+ id,
24
+ name : planStepNames [ id ] ,
25
+ isDisabled :
26
+ currentStep ?. index < planStepIndexes [ id ] && Object . keys ( formState ?. errors ) . length > 0 ,
27
+ } ) ;
28
28
29
29
return (
30
30
< FormProvider { ...form } >
31
31
< Wizard
32
32
isVisitRequired
33
33
title = { t ( 'Create migration plan' ) }
34
- footer = { ( { id : stepId } ) => (
35
- < CreatePlanWizardFooter canSkipToReview = { stepId === PlanWizardStepId . MigrationType } />
36
- ) }
34
+ footer = { < CreatePlanWizardFooter /> }
37
35
onStepChange = { ( _event , currentStep ) => setCurrentStep ( currentStep ) }
38
36
>
39
37
< WizardStep
40
- name = { t ( stepNames [ PlanWizardStepId . BasicSetUp ] ) }
41
- id = { PlanWizardStepId . BasicSetUp }
38
+ { ...getStepProps ( PlanWizardStepId . BasicSetUp ) }
42
39
steps = { [
43
- < WizardStep
44
- key = { PlanWizardStepId . General }
45
- id = { PlanWizardStepId . General }
46
- name = { stepNames [ PlanWizardStepId . General ] }
47
- isDisabled = { isStepDisabled ( PlanWizardStepId . General ) }
48
- >
40
+ < WizardStep key = { PlanWizardStepId . General } { ...getStepProps ( PlanWizardStepId . General ) } >
49
41
< GeneralInformationForm />
50
42
</ WizardStep > ,
51
43
< WizardStep
52
44
key = { PlanWizardStepId . VirtualMachines }
53
- id = { PlanWizardStepId . VirtualMachines }
54
- name = { stepNames [ PlanWizardStepId . VirtualMachines ] }
55
- isDisabled = { isStepDisabled ( PlanWizardStepId . VirtualMachines ) }
45
+ { ...getStepProps ( PlanWizardStepId . VirtualMachines ) }
56
46
>
57
47
< Form >
58
48
< Title headingLevel = "h2" > { t ( 'Virtual machines' ) } </ Title >
59
49
</ Form >
60
50
</ WizardStep > ,
61
51
< WizardStep
62
52
key = { PlanWizardStepId . NetworkMapping }
63
- id = { PlanWizardStepId . NetworkMapping }
64
- name = { stepNames [ PlanWizardStepId . NetworkMapping ] }
65
- isDisabled = { isStepDisabled ( PlanWizardStepId . NetworkMapping ) }
53
+ { ...getStepProps ( PlanWizardStepId . NetworkMapping ) }
66
54
>
67
55
< Form >
68
56
< Title headingLevel = "h2" > { t ( 'Network mappings' ) } </ Title >
69
57
</ Form >
70
58
</ WizardStep > ,
71
59
< WizardStep
72
60
key = { PlanWizardStepId . StorageMapping }
73
- id = { PlanWizardStepId . StorageMapping }
74
- name = { stepNames [ PlanWizardStepId . StorageMapping ] }
75
- isDisabled = { isStepDisabled ( PlanWizardStepId . StorageMapping ) }
61
+ { ...getStepProps ( PlanWizardStepId . StorageMapping ) }
76
62
>
77
63
< Form >
78
64
< Title headingLevel = "h2" > { t ( 'Storage mappings' ) } </ Title >
79
65
</ Form >
80
66
</ WizardStep > ,
81
67
< WizardStep
82
68
key = { PlanWizardStepId . MigrationType }
83
- id = { PlanWizardStepId . MigrationType }
84
- name = { stepNames [ PlanWizardStepId . MigrationType ] }
85
- isDisabled = { isStepDisabled ( PlanWizardStepId . MigrationType ) }
69
+ { ...getStepProps ( PlanWizardStepId . MigrationType ) }
86
70
>
87
71
< Form >
88
72
< Title headingLevel = "h2" > { t ( 'Migration type' ) } </ Title >
@@ -92,25 +76,17 @@ export const CreatePlanWizard: FC = () => {
92
76
/>
93
77
94
78
< WizardStep
95
- name = { stepNames [ PlanWizardStepId . AdditionalSetUp ] }
96
- id = { PlanWizardStepId . AdditionalSetUp }
79
+ { ...getStepProps ( PlanWizardStepId . AdditionalSetUp ) }
97
80
steps = { [
98
81
< WizardStep
99
82
key = { PlanWizardStepId . OtherSettings }
100
- id = { PlanWizardStepId . OtherSettings }
101
- name = { stepNames [ PlanWizardStepId . OtherSettings ] }
102
- isDisabled = { isStepDisabled ( PlanWizardStepId . OtherSettings ) }
83
+ { ...getStepProps ( PlanWizardStepId . OtherSettings ) }
103
84
>
104
85
< Form >
105
86
< Title headingLevel = "h2" > { t ( 'Other settings' ) } </ Title >
106
87
</ Form >
107
88
</ WizardStep > ,
108
- < WizardStep
109
- key = { PlanWizardStepId . Hooks }
110
- id = { PlanWizardStepId . Hooks }
111
- name = { stepNames [ PlanWizardStepId . Hooks ] }
112
- isDisabled = { isStepDisabled ( PlanWizardStepId . Hooks ) }
113
- >
89
+ < WizardStep key = { PlanWizardStepId . Hooks } { ...getStepProps ( PlanWizardStepId . Hooks ) } >
114
90
< Form >
115
91
< Title headingLevel = "h2" > { t ( 'Hooks' ) } </ Title >
116
92
</ Form >
@@ -119,10 +95,8 @@ export const CreatePlanWizard: FC = () => {
119
95
/>
120
96
121
97
< WizardStep
122
- name = { stepNames [ PlanWizardStepId . ReviewAndCreate ] }
123
- id = { PlanWizardStepId . ReviewAndCreate }
124
98
footer = { < CreatePlanWizardFooter nextButtonText = { t ( 'Create plan' ) } onNext = { onSubmit } /> }
125
- isDisabled = { isStepDisabled ( PlanWizardStepId . ReviewAndCreate ) }
99
+ { ... getStepProps ( PlanWizardStepId . ReviewAndCreate ) }
126
100
>
127
101
< pre > { JSON . stringify ( formValues , null , 2 ) } </ pre >
128
102
</ WizardStep >
0 commit comments