@@ -25,6 +25,8 @@ import {
25
25
useCreateClusterContext ,
26
26
} from '../CreateClusterWizard'
27
27
28
+ const nameRegex = / ^ [ a - z ] [ a - z 0 - 9 - ] [ a - z 0 - 9 ] { 4 , 9 } $ /
29
+
28
30
export function ConfigureCloudInstanceStep ( ) {
29
31
const theme = useTheme ( )
30
32
const { setCurStep, setContinueBtn, setConsoleInstanceId } =
@@ -34,9 +36,10 @@ export function ConfigureCloudInstanceStep() {
34
36
const [ size , setSize ] = useState < ConsoleSize > ( ConsoleSize . Small )
35
37
const [ cloud , setCloud ] = useState < CloudProvider > ( CloudProvider . Aws )
36
38
const [ region , setRegion ] = useState < string > ( regions [ 0 ] )
39
+ const isNameValid = nameRegex . test ( name )
37
40
38
41
const canSubmit = ! ! (
39
- name &&
42
+ isNameValid &&
40
43
size &&
41
44
cloud &&
42
45
( cloud === CloudProvider . Aws ? region : true )
@@ -89,9 +92,22 @@ export function ConfigureCloudInstanceStep() {
89
92
After completing this step it may take a few minutes for your Console to
90
93
deploy. It will run in the background as you proceed.
91
94
</ Callout >
92
- < FormFieldSC label = "Cluster name" >
95
+ < FormFieldSC
96
+ label = "Cluster name"
97
+ hint = {
98
+ < FormFieldCaptionSC $name = { name } >
99
+ Name must be between 6 and 11 characters, lowercase, alphanumeric,
100
+ and begin with a letter.
101
+ </ FormFieldCaptionSC >
102
+ }
103
+ >
93
104
< Input
94
105
placeholder = "Enter cluster name"
106
+ borderColor = {
107
+ name === '' || isNameValid
108
+ ? undefined
109
+ : theme . colors [ 'border-danger' ]
110
+ }
95
111
value = { name }
96
112
onChange = { ( e ) => setName ( e . target . value ) }
97
113
/>
@@ -147,4 +163,15 @@ export const FormFieldSC = styled(FormField)(({ theme }) => ({
147
163
color : theme . colors . text ,
148
164
} ) )
149
165
166
+ const FormFieldCaptionSC = styled . span < {
167
+ $name : string
168
+ } > ( ( { theme, $name } ) => ( {
169
+ ...theme . partials . text . caption ,
170
+ color : nameRegex . test ( $name )
171
+ ? theme . colors [ 'text-success-light' ]
172
+ : $name !== ''
173
+ ? theme . colors [ 'text-danger-light' ]
174
+ : theme . colors [ 'text-light' ] ,
175
+ } ) )
176
+
150
177
const regions = [ 'us-east-1' ]
0 commit comments