@@ -49,6 +49,18 @@ const ApiConfigManager = ({
4949 return null
5050 }
5151
52+ const resetCreateState = ( ) => {
53+ setIsCreating ( false )
54+ setNewProfileName ( "" )
55+ setError ( null )
56+ }
57+
58+ const resetRenameState = ( ) => {
59+ setIsRenaming ( false )
60+ setInputValue ( "" )
61+ setError ( null )
62+ }
63+
5264 // Focus input when entering rename mode
5365 useEffect ( ( ) => {
5466 if ( isRenaming ) {
@@ -67,17 +79,13 @@ const ApiConfigManager = ({
6779
6880 // Reset state when current profile changes
6981 useEffect ( ( ) => {
70- setIsRenaming ( false )
71- setIsCreating ( false )
72- setInputValue ( "" )
73- setNewProfileName ( "" )
74- setError ( null )
82+ resetCreateState ( )
83+ resetRenameState ( )
7584 } , [ currentApiConfigName ] )
7685
7786 const handleAdd = ( ) => {
87+ resetCreateState ( )
7888 setIsCreating ( true )
79- setNewProfileName ( "" )
80- setError ( null )
8189 }
8290
8391 const handleStartRename = ( ) => {
@@ -87,9 +95,7 @@ const ApiConfigManager = ({
8795 }
8896
8997 const handleCancel = ( ) => {
90- setIsRenaming ( false )
91- setInputValue ( "" )
92- setError ( null )
98+ resetRenameState ( )
9399 }
94100
95101 const handleSave = ( ) => {
@@ -103,17 +109,13 @@ const ApiConfigManager = ({
103109
104110 if ( isRenaming && currentApiConfigName ) {
105111 if ( currentApiConfigName === trimmedValue ) {
106- setIsRenaming ( false )
107- setInputValue ( "" )
108- setError ( null )
112+ resetRenameState ( )
109113 return
110114 }
111115 onRenameConfig ( currentApiConfigName , trimmedValue )
112116 }
113117
114- setIsRenaming ( false )
115- setInputValue ( "" )
116- setError ( null )
118+ resetRenameState ( )
117119 }
118120
119121 const handleNewProfileSave = ( ) => {
@@ -126,9 +128,7 @@ const ApiConfigManager = ({
126128 }
127129
128130 onUpsertConfig ( trimmedValue )
129- setIsCreating ( false )
130- setNewProfileName ( "" )
131- setError ( null )
131+ resetCreateState ( )
132132 }
133133
134134 const handleDelete = ( ) => {
@@ -293,24 +293,15 @@ const ApiConfigManager = ({
293293 setNewProfileName ( "" )
294294 setError ( null )
295295 } else {
296- setIsCreating ( false )
297- setNewProfileName ( "" )
298- setError ( null )
296+ resetCreateState ( )
299297 }
300298 } }
301299 aria-labelledby = "new-profile-title" >
302300 < DialogContent className = "p-4 max-w-sm" >
303301 < h2 id = "new-profile-title" className = "text-lg font-semibold mb-4" >
304302 New Configuration Profile
305303 </ h2 >
306- < button
307- className = "absolute right-4 top-4"
308- aria-label = "Close dialog"
309- onClick = { ( ) => {
310- setIsCreating ( false )
311- setNewProfileName ( "" )
312- setError ( null )
313- } } >
304+ < button className = "absolute right-4 top-4" aria-label = "Close dialog" onClick = { resetCreateState } >
314305 < span className = "codicon codicon-close" />
315306 </ button >
316307 < VSCodeTextField
@@ -328,9 +319,7 @@ const ApiConfigManager = ({
328319 if ( event . key === "Enter" && newProfileName . trim ( ) ) {
329320 handleNewProfileSave ( )
330321 } else if ( event . key === "Escape" ) {
331- setIsCreating ( false )
332- setNewProfileName ( "" )
333- setError ( null )
322+ resetCreateState ( )
334323 }
335324 } }
336325 />
@@ -340,13 +329,7 @@ const ApiConfigManager = ({
340329 </ p >
341330 ) }
342331 < div className = "flex justify-end gap-2 mt-4" >
343- < VSCodeButton
344- appearance = "secondary"
345- onClick = { ( ) => {
346- setIsCreating ( false )
347- setNewProfileName ( "" )
348- setError ( null )
349- } } >
332+ < VSCodeButton appearance = "secondary" onClick = { resetCreateState } >
350333 Cancel
351334 </ VSCodeButton >
352335 < VSCodeButton
0 commit comments