@@ -11,6 +11,7 @@ import React, {
11
11
import { useParams } from "react-router-dom" ;
12
12
import { getEnvironmentById , updateEnvironment } from "../services/environments.service" ;
13
13
import { Environment } from "../types/environment.types" ;
14
+ import { useEnvironmentContext } from './EnvironmentContext' ;
14
15
15
16
interface SingleEnvironmentContextState {
16
17
// Environment data
@@ -52,6 +53,9 @@ import React, {
52
53
const { envId } = useParams < { envId : string } > ( ) ;
53
54
const environmentId = propEnvironmentId || envId ;
54
55
56
+ // Access the environments context to refresh the list
57
+ const { refreshEnvironments } = useEnvironmentContext ( ) ;
58
+
55
59
// State for environment data
56
60
const [ environment , setEnvironment ] = useState < Environment | null > ( null ) ;
57
61
@@ -98,16 +102,19 @@ import React, {
98
102
// Show success message
99
103
message . success ( "Environment updated successfully" ) ;
100
104
101
- // Update local state
102
- setEnvironment ( updatedEnv ) ;
105
+ // Refresh both the single environment and environments list
106
+ await Promise . all ( [
107
+ fetchEnvironment ( ) , // Refresh the current environment
108
+ refreshEnvironments ( ) // Refresh the environments list
109
+ ] ) ;
103
110
104
111
return updatedEnv ;
105
112
} catch ( err ) {
106
113
const errorMessage = err instanceof Error ? err . message : "Failed to update environment" ;
107
114
message . error ( errorMessage ) ;
108
115
throw err ;
109
116
}
110
- } , [ environment , environmentId ] ) ;
117
+ } , [ environment , environmentId , fetchEnvironment , refreshEnvironments ] ) ;
111
118
112
119
// Load environment data when the component mounts or environmentId changes
113
120
useEffect ( ( ) => {
0 commit comments