@@ -10,6 +10,7 @@ import { StepAuthProvider } from './StepAuthProvider.js';
1010import { StepResources } from './StepResources.js' ;
1111import { StepInstall } from './StepInstall.js' ;
1212import { useInstallDeps } from './useInstallDeps.js' ;
13+ import { StepName } from './StepName.js' ;
1314
1415type Props = {
1516 name : string | undefined ;
@@ -20,6 +21,12 @@ const stepReducer = (
2021 action
2122) : ProjectConfiguration => {
2223 switch ( state . step ) {
24+ case 'name' :
25+ return {
26+ ...state ,
27+ name : action . value ,
28+ step : 'data-provider' ,
29+ } ;
2330 case 'data-provider' :
2431 return {
2532 ...state ,
@@ -67,16 +74,21 @@ const stepReducer = (
6774} ;
6875
6976export default function App ( { name = 'my-admin' } : Props ) {
77+ const sanitizedName = sanitizeName ( name ) ;
7078 const [ state , dispatch ] = useReducer ( stepReducer , {
7179 ...InitialProjectConfiguration ,
72- name,
80+ name : sanitizedName ,
81+ step : sanitizedName === name ? 'data-provider' : 'name' ,
7382 } ) ;
7483 const helpMessages = useRef ( [ ] ) ;
7584 const installDeps = useInstallDeps ( ) ;
7685 const handleSubmit = ( value : any ) => {
7786 dispatch ( { value } ) ;
7887 } ;
7988
89+ if ( state . step === 'name' ) {
90+ return < StepName initialValue = { state . name } onSubmit = { handleSubmit } /> ;
91+ }
8092 if ( state . step === 'data-provider' ) {
8193 return < StepDataProvider onSubmit = { handleSubmit } /> ;
8294 }
@@ -125,3 +137,12 @@ export default function App({ name = 'my-admin' }: Props) {
125137 </ >
126138 ) ;
127139}
140+
141+ const sanitizeName = ( name : string ) => {
142+ return name
143+ . trim ( )
144+ . toLowerCase ( )
145+ . replace ( / \s + / g, '-' )
146+ . replace ( / ^ [ . _ ] / , '' )
147+ . replace ( / [ ^ a - z \d \- ~ ] + / g, '-' ) ;
148+ } ;
0 commit comments