File tree Expand file tree Collapse file tree
packages/manager/apps/pci-instances/src/pages/instances/create/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export const Name = () => {
1414 register,
1515 control,
1616 setValue,
17+ getValues,
1718 formState : {
1819 errors : { name : error } ,
1920 } ,
@@ -25,14 +26,16 @@ export const Name = () => {
2526 select : selectOvhInstanceName ( flavorId ) ,
2627 } ) ;
2728
28- const hasInitializedName = useRef ( false ) ;
29+ const lastAutoGeneratedName = useRef < string | null > ( null ) ;
2930
3031 useEffect ( ( ) => {
31- if ( ovhInstanceName && ! hasInitializedName . current ) {
32+ if ( ! ovhInstanceName ) return ;
33+ const currentName = getValues ( 'name' ) ;
34+ if ( ! currentName || currentName === lastAutoGeneratedName . current ) {
3235 setValue ( 'name' , ovhInstanceName ) ;
33- hasInitializedName . current = true ;
36+ lastAutoGeneratedName . current = ovhInstanceName ;
3437 }
35- } , [ ovhInstanceName , setValue ] ) ;
38+ } , [ ovhInstanceName , getValues , setValue ] ) ;
3639
3740 return (
3841 < article className = "flex w-full flex-col" >
You can’t perform that action at this time.
0 commit comments