11import React , { useCallback , useState } from 'react' ;
2- import { Col , Form , Modal , Row , Select , Space } from 'antd' ;
3- import { createUseStyles } from 'react-jss' ;
2+ import { Form , Modal , Select , Space , TimePicker } from 'antd' ;
43import { observer } from 'mobx-react' ;
4+ // eslint-disable-next-line import/named
5+ import moment , { Moment } from 'moment' ;
56
67import rootStore from '../../modules/RootStore' ;
78import IModalProps from '../../types/IModalProps' ;
89import NewProfilePopover from './NewProfilePopover' ;
10+ import { timeToMs } from '../../helpers/DateTime' ;
11+ import { DEFAULT_SETTINGS } from '../../modules/settings/models/SettingsModel' ;
912
1013const { settingsStore } = rootStore ;
1114
1215interface ISettingsModalProps extends IModalProps { }
1316
17+ const timeFormat = 'HH:mm' ;
18+
1419const SettingsModal : React . VFC < ISettingsModalProps > = observer (
1520 ( props : ISettingsModalProps ) => {
1621 const { visible, onClose } = props ;
22+ const { settings } = settingsStore ;
1723
1824 const [ showNewProfilePopover , setShowNewProfilePopover ] = useState < boolean > (
1925 false
2026 ) ;
21- const [ profile , setProfile ] = useState < string > (
22- settingsStore . settings . currentProfile
27+ const [ profile , setProfile ] = useState < string > ( settings . currentProfile ) ;
28+ const [ workingHours , setWorkingHours ] = useState < Moment | null > (
29+ moment ( settings . numberOfWorkingHours ) . utcOffset ( 0 )
2330 ) ;
2431
2532 const handleSave = useCallback ( ( ) => {
26- settingsStore . setActiveProfile ( profile ) ;
33+ settingsStore . setSettings ( {
34+ currentProfile : profile ,
35+ numberOfWorkingHours : workingHours
36+ ? timeToMs ( workingHours ?. toDate ( ) )
37+ : DEFAULT_SETTINGS . numberOfWorkingHours ,
38+ } ) ;
2739 onClose ( ) ;
28- } , [ profile , onClose ] ) ;
40+ } , [ profile , workingHours , onClose ] ) ;
2941
3042 const handleChangeProfile = useCallback ( ( selected : string ) => {
3143 setProfile ( selected ) ;
@@ -50,14 +62,14 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
5062 onOk = { handleSave }
5163 onCancel = { onClose }
5264 >
53- < Form . Item label = "Profile " labelCol = { { span : 24 } } >
65+ < Form . Item label = "Switch profile " labelCol = { { span : 24 } } >
5466 < Space >
5567 < Select
5668 value = { profile }
5769 onChange = { handleChangeProfile }
5870 style = { { width : 200 } }
5971 >
60- { settingsStore . settings . profiles . map ( ( profile ) => (
72+ { settings . profiles . map ( ( profile ) => (
6173 < Select . Option key = { profile } value = { profile } >
6274 { profile }
6375 </ Select . Option >
@@ -69,6 +81,16 @@ const SettingsModal: React.VFC<ISettingsModalProps> = observer(
6981 />
7082 </ Space >
7183 </ Form . Item >
84+ < Form . Item label = "Number of working hours" >
85+ < TimePicker
86+ value = { workingHours }
87+ onChange = { ( value ) => setWorkingHours ( value ) }
88+ format = { timeFormat }
89+ minuteStep = { 5 }
90+ showNow = { false }
91+ allowClear = { false }
92+ />
93+ </ Form . Item >
7294 </ Modal >
7395 ) ;
7496 }
0 commit comments