1- import React , { useState } from 'react' ;
1+ import React , { useCallback , useState } from 'react' ;
22import { Col , Form , Modal , Row , Select , Space } from 'antd' ;
33import { createUseStyles } from 'react-jss' ;
4+ import { observer } from 'mobx-react' ;
45
56import rootStore from '../../modules/RootStore' ;
67import IModalProps from '../../types/IModalProps' ;
@@ -10,45 +11,58 @@ const { settingsStore } = rootStore;
1011
1112interface ISettingsModalProps extends IModalProps { }
1213
13- const SettingsModal : React . VFC < ISettingsModalProps > = (
14- props : ISettingsModalProps
15- ) => {
16- const { visible, onClose } = props ;
17- const [ showNewProfilePopover , setShowNewProfilePopover ] = useState < boolean > (
18- false
19- ) ;
20-
21- return (
22- < Modal
23- title = "Settings"
24- visible = { visible }
25- // okButtonProps={{ disabled: !valid }}
26- okText = "Save"
27- onOk = { onClose }
28- onCancel = { onClose }
29- >
30- < Row >
31- < Col span = { 24 } >
32- < Form . Item label = "Profile" labelCol = { { span : 24 } } >
33- < Space >
34- < Select >
35- { settingsStore . settings . profiles . map ( ( profile ) => (
36- < Select . Option key = { profile } value = { profile } >
37- { profile }
38- </ Select . Option >
39- ) ) }
40- </ Select >
41- < NewProfilePopover
42- visible = { showNewProfilePopover }
43- setVisible = { setShowNewProfilePopover }
44- />
45- </ Space >
46- </ Form . Item >
47- </ Col >
48- </ Row >
49- </ Modal >
50- ) ;
51- } ;
14+ const SettingsModal : React . VFC < ISettingsModalProps > = observer (
15+ ( props : ISettingsModalProps ) => {
16+ const { visible, onClose } = props ;
17+
18+ const [ showNewProfilePopover , setShowNewProfilePopover ] = useState < boolean > (
19+ false
20+ ) ;
21+ const [ profile , setProfile ] = useState < string > (
22+ settingsStore . settings . currentProfile
23+ ) ;
24+
25+ const handleSave = useCallback ( ( ) => {
26+ settingsStore . setActiveProfile ( profile ) ;
27+ onClose ( ) ;
28+ } , [ profile , onClose ] ) ;
29+
30+ const handleChangeProfile = useCallback ( ( selected : string ) => {
31+ setProfile ( selected ) ;
32+ } , [ ] ) ;
33+
34+ return (
35+ < Modal
36+ title = "Settings"
37+ visible = { visible }
38+ // okButtonProps={{ disabled: !valid }}
39+ okText = "Save"
40+ onOk = { handleSave }
41+ onCancel = { onClose }
42+ >
43+ < Row >
44+ < Col span = { 24 } >
45+ < Form . Item label = "Profile" labelCol = { { span : 24 } } >
46+ < Space >
47+ < Select value = { profile } onChange = { handleChangeProfile } >
48+ { settingsStore . settings . profiles . map ( ( profile ) => (
49+ < Select . Option key = { profile } value = { profile } >
50+ { profile }
51+ </ Select . Option >
52+ ) ) }
53+ </ Select >
54+ < NewProfilePopover
55+ visible = { showNewProfilePopover }
56+ setVisible = { setShowNewProfilePopover }
57+ />
58+ </ Space >
59+ </ Form . Item >
60+ </ Col >
61+ </ Row >
62+ </ Modal >
63+ ) ;
64+ }
65+ ) ;
5266
5367const useStyles = createUseStyles ( { } ) ;
5468
0 commit comments