1- import React , { useState } from 'react' ;
2- import { StyleSheet , Text , View } from 'react-native' ;
1+ import React , { useEffect , useState } from 'react' ;
2+ import { StyleSheet , Text , TextInput , View } from 'react-native' ;
33import { Modal , RadioButton } from 'react-native-paper' ;
44import { APP_ENVIRONMENTS , useAppEnvironment } from '../AppEnvironment' ;
55import RoundedButton from '../Components/RoundedButton' ;
@@ -16,31 +16,63 @@ export default function EnvironmentSelect({
1616
1717 const { environment, setEnvironment} = useAppEnvironment ( ) ;
1818 const [ selectedEnv , setSelectedEnv ] = useState < string > ( environment . name . toLowerCase ( ) ) ;
19+ const [ customUrl , setCustomUrl ] = useState < string > ( '' ) ;
1920
20- return (
21- < Modal visible = { visible } onDismiss = { onDismiss } contentContainerStyle = { styles . sheet } >
22- < Text style = { styles . title } > Change Server</ Text >
21+ useEffect ( ( ) => {
22+ if ( visible ) {
23+ setSelectedEnv ( environment . name . toLowerCase ( ) ) ;
24+ setCustomUrl ( '' ) ;
25+ }
26+ } , [ visible ] ) ;
2327
24- < RadioButton . Group onValueChange = { setSelectedEnv } value = { selectedEnv } >
25- < View style = { { flexDirection : 'row' , alignItems : 'center' , marginBottom : 8 } } >
26- < RadioButton . Android value = "production" />
27- < Text > Production</ Text >
28- </ View >
29- < View style = { { flexDirection : 'row' , alignItems : 'center' , marginBottom : 8 } } >
30- < RadioButton . Android value = "test" />
31- < Text > Test</ Text >
32- </ View >
33- < View style = { { flexDirection : 'row' , alignItems : 'center' , marginBottom : 8 } } >
34- < RadioButton . Android value = "demo" />
35- < Text > Demo</ Text >
36- </ View >
37- </ RadioButton . Group >
28+ return (
29+ < Modal visible = { visible } onDismiss = { onDismiss } contentContainerStyle = { styles . sheet } >
30+ < Text style = { styles . title } > Change Server</ Text >
31+ < RadioButton . Group onValueChange = { setSelectedEnv } value = { selectedEnv } >
32+ < View style = { styles . row } >
33+ < RadioButton . Android value = "production" />
34+ < Text > Production</ Text >
35+ </ View >
36+ < View style = { styles . row } >
37+ < RadioButton . Android value = "test" />
38+ < Text > Test</ Text >
39+ </ View >
40+ < View style = { styles . row } >
41+ < RadioButton . Android value = "demo" />
42+ < Text > Demo</ Text >
43+ </ View >
44+ < View style = { styles . row } >
45+ < RadioButton . Android value = "other" />
46+ < Text > Other</ Text >
47+ </ View >
48+ </ RadioButton . Group >
3849
39- < RoundedButton title = "Save Changes" onPress = { ( ) => {
50+ { selectedEnv === "other" && (
51+ < TextInput
52+ style = { styles . textInput }
53+ placeholder = "Enter base URL"
54+ value = { customUrl }
55+ onChangeText = { setCustomUrl }
56+ />
57+ ) }
58+
59+ < RoundedButton title = "Save Changes" onPress = { ( ) => {
60+ if ( selectedEnv === "other" ) {
61+ if ( ! customUrl . trim ( ) ) {
62+ onDismiss ( ) ;
63+ return ;
64+ }
65+ setEnvironment ( {
66+ name : "Other" ,
67+ production : false ,
68+ baseUrl : customUrl ,
69+ } ) ;
70+ } else {
4071 setEnvironment ( APP_ENVIRONMENTS [ selectedEnv ] ) ;
41- onDismiss ( ) ;
42- } } />
43- </ Modal >
72+ }
73+ onDismiss ( ) ;
74+ } } />
75+ </ Modal >
4476 ) ;
4577}
4678
@@ -60,4 +92,13 @@ const styles = StyleSheet.create({
6092 marginBottom : 16 ,
6193 textAlign : 'center' ,
6294 } ,
95+ row : {
96+ flexDirection : 'row' ,
97+ alignItems : 'center' ,
98+ marginBottom : 8 ,
99+ } ,
100+ textInput : {
101+ padding : 8 ,
102+ marginBottom : 12 ,
103+ } ,
63104} ) ;
0 commit comments