@@ -24,10 +24,10 @@ export default function Environments() {
2424 const [ isAddingEnv , setIsAddingEnv ] = useState ( false ) ;
2525 const [ isRotatingKey , setIsRotatingKey ] = useState ( false ) ;
2626 const [ isEditingVariable , setIsEditingVariable ] = useState ( false ) ;
27- const [ isTogglingVariable , setIsToggligVariable ] = useState ( false ) ;
28- const [ isDeletingVarible , setIsDeletingVarible ] = useState ( false ) ;
27+ const [ isTogglingVariable , setIsToggligVariable ] = useState ( null ) ;
28+ const [ isDeletingVariable , setIsDeletingVariable ] = useState ( null ) ;
2929 const [ isDeletingProject , setIsDeletingProject ] = useState ( false ) ;
30- const [ isDeletingEnv , setIsDeletingEnv ] = useState ( false ) ;
30+ const [ isDeletingEnv , setIsDeletingEnv ] = useState ( null ) ;
3131
3232
3333
@@ -59,14 +59,14 @@ function openDeleteEnvDialog(envId) {
5959 setConfirmDescription ( "Are you sure you want to delete this environment? This action cannot be undone." ) ;
6060 setConfirmAction ( ( ) => async ( ) => {
6161 try {
62- setIsDeletingEnv ( true ) ;
62+ setIsDeletingEnv ( envId ) ;
6363 await api . del ( `/api/environments/${ envId } ` , token ) ;
6464 setEnvs ( ( prev ) => prev . filter ( ( e ) => e . _id !== envId ) ) ;
6565 if ( selectedEnv === envId ) setSelectedEnv ( null ) ;
6666 } catch ( error ) {
6767
6868 } finally {
69- setIsDeletingEnv ( false ) ;
69+ setIsDeletingEnv ( null ) ;
7070 }
7171 } ) ;
7272 setConfirmOpen ( true ) ;
@@ -79,14 +79,14 @@ function openDeleteVariableDialog(envId, key) {
7979 setConfirmDescription ( `Are you sure you want to delete the variable "${ key } "? This action cannot be undone.` ) ;
8080 setConfirmAction ( ( ) => async ( ) => {
8181 try {
82- setIsDeletingVarible ( true ) ;
82+ setIsDeletingVariable ( key ) ;
8383 await api . del ( `/api/environments/${ envId } /data/${ key } ` , token ) ;
8484 const res = await api . get ( `/api/environments/${ envId } /data` , token ) ;
8585 setEnvData ( ( prev ) => ( { ...prev , [ envId ] : res } ) ) ;
8686 } catch ( error ) {
8787
8888 } finally {
89- setIsDeletingVarible ( false )
89+ setIsDeletingVariable ( null )
9090 }
9191
9292 } ) ;
@@ -207,15 +207,16 @@ function openDeleteProjectDialog() {
207207
208208 // 🔹 Change status active/inactive
209209 async function changeStatus ( envId , key , currentStatus ) {
210- setIsToggligVariable ( true ) ;
210+ if ( isTogglingVariable ) return ;
211+ setIsToggligVariable ( key ) ;
211212 try {
212213 await api . patch ( `/api/environments/${ envId } /data/${ key } /status` , token ) ;
213214 const res = await api . get ( `/api/environments/${ envId } /data` , token ) ;
214215 setEnvData ( ( prev ) => ( { ...prev , [ envId ] : res } ) ) ;
215216 } catch ( error ) {
216217
217218 } finally {
218- setIsToggligVariable ( false ) ;
219+ setIsToggligVariable ( null ) ;
219220 }
220221
221222 }
@@ -353,8 +354,8 @@ function openDeleteProjectDialog() {
353354 ) }
354355 </ Button >
355356 < Button onClick = { ( ) => openDeleteEnvDialog ( env . _id ) } variant = "destructive" size = "sm" className = "gap-2" >
356- { ! isDeletingEnv && < > < Trash2 className = "w-4 h-4" /> Delete</ > }
357- { isDeletingEnv && < > < Loader2 className = "w-4 h-4 animate-spin" /> Deleting Env</ > }
357+ { isDeletingEnv !== env . _id && < > < Trash2 className = "w-4 h-4" /> Delete</ > }
358+ { isDeletingEnv === env . _id && < > < Loader2 className = "w-4 h-4 animate-spin" /> Deleting Env.. </ > }
358359
359360 </ Button >
360361 </ div >
@@ -435,7 +436,7 @@ function openDeleteProjectDialog() {
435436 onClick = { ( ) => changeStatus ( env . _id , k , v . status ) }
436437
437438 >
438- { isTogglingVariable && < Loader2 className = "animate-spin h-4 w-4 mr-1" > </ Loader2 > }
439+ { isTogglingVariable === k && < Loader2 className = "animate-spin h-4 w-4 mr-1" > </ Loader2 > }
439440 { v . status }
440441
441442 </ Badge >
@@ -446,7 +447,8 @@ function openDeleteProjectDialog() {
446447 size = "sm"
447448 className = "text-destructive hover:text-destructive gap-2"
448449 >
449- < Trash2 className = "w-4 h-4" />
450+ { isDeletingVariable === k && < > < Loader2 className = "w-4 h-4 animate-spin" /> Deleting...</ > }
451+ { isDeletingVariable !== k && < Trash2 className = "w-4 h-4" /> }
450452 </ Button >
451453 </ div >
452454 </ div >
0 commit comments