@@ -6,6 +6,7 @@ import { Trans } from "react-i18next"
6
6
import { useWorkspaceProxiesData } from "./hooks"
7
7
import { Region } from "api/typesGenerated"
8
8
import { displayError } from "components/GlobalSnackbar/utils"
9
+ import { useProxy } from "contexts/ProxyContext"
9
10
// import { ConfirmDeleteDialog } from "./components"
10
11
// import { Stack } from "components/Stack/Stack"
11
12
// import Button from "@material-ui/core/Button"
@@ -24,7 +25,7 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
24
25
</ Trans >
25
26
)
26
27
27
- const [ preferred , setPreferred ] = useState ( getPreferredProxy ( ) )
28
+ const { value , setValue } = useProxy ( )
28
29
29
30
const {
30
31
data : response ,
@@ -46,21 +47,15 @@ export const WorkspaceProxyPage: FC<PropsWithChildren<unknown>> = () => {
46
47
isLoading = { isFetching }
47
48
hasLoaded = { isFetched }
48
49
getWorkspaceProxiesError = { getProxiesError }
49
- preferredProxy = { preferred }
50
+ preferredProxy = { value . selectedRegion }
50
51
onSelect = { ( proxy ) => {
51
52
if ( ! proxy . healthy ) {
52
53
displayError ( "Please select a healthy workspace proxy." )
53
54
return
54
55
}
55
- // normProxy is a normalized proxy to
56
- const normProxy = {
57
- ...proxy ,
58
- // Trim trailing slashes to be consistent
59
- path_app_url : proxy . path_app_url . replace ( / \/ $ / , "" ) ,
60
- }
61
56
62
- savePreferredProxy ( normProxy )
63
- setPreferred ( normProxy )
57
+ // Set the fetched regions + the selected proxy
58
+ setValue ( response ? response . regions : [ ] , proxy )
64
59
} }
65
60
/>
66
61
</ Section >
@@ -81,24 +76,3 @@ const useStyles = makeStyles((theme) => ({
81
76
} ) )
82
77
83
78
export default WorkspaceProxyPage
84
-
85
- // Exporting to be used in the tests
86
- export const savePreferredProxy = ( proxy : Region ) : void => {
87
- window . localStorage . setItem ( "preferred-proxy" , JSON . stringify ( proxy ) )
88
- }
89
-
90
- export const getPreferredProxy = ( ) : Region | undefined => {
91
- const str = localStorage . getItem ( "preferred-proxy" )
92
- if ( str === undefined || str === null ) {
93
- return undefined
94
- }
95
- const proxy = JSON . parse ( str )
96
- if ( proxy . id === undefined || proxy . id === null ) {
97
- return undefined
98
- }
99
- return proxy
100
- }
101
-
102
- export const clearPreferredProxy = ( ) : void => {
103
- localStorage . removeItem ( "preferred-proxy" )
104
- }
0 commit comments