Skip to content

Commit 477135f

Browse files
committed
SettingsModal WIP
1 parent abdfdbd commit 477135f

File tree

7 files changed

+116
-12
lines changed

7 files changed

+116
-12
lines changed

src/components/Profile/Profile.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import React from 'react';
2+
import { Space } from 'antd';
3+
import { SettingOutlined } from '@ant-design/icons';
4+
import { createUseStyles } from 'react-jss';
5+
6+
import rootStore from '../../modules/RootStore';
7+
import useModal from '../../hooks/ModalHook';
8+
import SettingsModal from '../SettingsModal/SettingsModal';
9+
10+
const { settingsStore } = rootStore;
11+
12+
const Profile: React.VFC = () => {
13+
const classes = useStyles();
14+
const { settings } = settingsStore;
15+
const { open, openModal, closeModal } = useModal();
16+
17+
return (
18+
<Space className={classes.root}>
19+
<span className={classes.white}>{settings.currentProfile}</span>
20+
<SettingOutlined className={classes.white} onClick={openModal} />
21+
<SettingsModal visible={open} onClose={closeModal} />
22+
</Space>
23+
);
24+
};
25+
26+
const useStyles = createUseStyles({
27+
root: {
28+
marginLeft: 16,
29+
},
30+
white: {
31+
color: 'white',
32+
},
33+
});
34+
35+
export default Profile;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React from 'react';
2+
import { Col, Form, Modal, Row, Select } from 'antd';
3+
import { createUseStyles } from 'react-jss';
4+
5+
import rootStore from '../../modules/RootStore';
6+
7+
const { settingsStore } = rootStore;
8+
9+
interface ISettingsModalProps {
10+
visible: boolean;
11+
onClose: () => void;
12+
}
13+
14+
const SettingsModal: React.VFC<ISettingsModalProps> = (props: ISettingsModalProps) => {
15+
const { visible, onClose } = props;
16+
return (
17+
<Modal
18+
title="Settings"
19+
visible={visible}
20+
// okButtonProps={{ disabled: !valid }}
21+
okText="Save"
22+
onOk={onClose}
23+
onCancel={onClose}
24+
>
25+
<Row>
26+
<Col span={8}>
27+
<Form.Item label="Profile" labelCol={{ span: 24 }}>
28+
<Select>
29+
{settingsStore.settings.profiles.map((profile) => (
30+
<Select.Option key={profile} value={profile}>
31+
{profile}
32+
</Select.Option>
33+
))}
34+
</Select>
35+
</Form.Item>
36+
</Col>
37+
</Row>
38+
</Modal>
39+
);
40+
};
41+
42+
const useStyles = createUseStyles({});
43+
44+
export default SettingsModal;

src/hooks/ModalHook.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useCallback, useState } from 'react';
2+
3+
const useModal = () => {
4+
const [open, setOpen] = useState(false);
5+
6+
const openModal = useCallback(() => {
7+
setOpen(true);
8+
}, []);
9+
10+
const closeModal = useCallback(() => {
11+
setOpen(false);
12+
}, []);
13+
14+
return {
15+
open,
16+
openModal,
17+
closeModal,
18+
};
19+
};
20+
21+
export default useModal;

src/modules/settings/SettingsService.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
import IService from '../../base/IService';
2-
import SettingsModel from './models/SettingsModel';
2+
import SettingsModel, { DEFAULT_SETTINGS } from './models/SettingsModel';
33
import SettingsFactory from './SettingsFactory';
44
import SettingsRepository from './SettingsRepository';
55

6-
export const DEFAULT_SETTINGS = {
7-
currentProfile: 'profile1',
8-
profiles: ['profile1'],
9-
hoursInWorkingDay: 8 * 60 * 60 * 1000,
10-
};
11-
126
export default class SettingsService implements IService<SettingsModel> {
137
private repository: SettingsRepository = new SettingsRepository();
148
private factory: SettingsFactory = new SettingsFactory();

src/modules/settings/SettingsStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { makeAutoObservable } from 'mobx';
2-
import SettingsModel from './models/SettingsModel';
3-
import SettingsService, { DEFAULT_SETTINGS } from './SettingsService';
2+
import SettingsModel, { DEFAULT_SETTINGS } from './models/SettingsModel';
3+
import SettingsService from './SettingsService';
44

55
export default class SettingsStore {
66
settings: SettingsModel = new SettingsModel(DEFAULT_SETTINGS);

src/modules/settings/models/SettingsModel.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import AbstractModel from '../../../base/AbstractModel';
22

3+
export const DEFAULT_SETTINGS = {
4+
currentProfile: 'profile1',
5+
profiles: ['profile1'],
6+
hoursInWorkingDay: 8 * 60 * 60 * 1000,
7+
isFirstLoad: true,
8+
};
9+
310
export default class SettingsModel extends AbstractModel {
4-
currentProfile: string | null = null;
5-
profiles: string[] | null = null;
6-
hoursInWorkingDay: number | null = null;
11+
currentProfile: string = DEFAULT_SETTINGS.currentProfile;
12+
profiles: string[] = DEFAULT_SETTINGS.profiles;
13+
hoursInWorkingDay: number = DEFAULT_SETTINGS.hoursInWorkingDay;
14+
isFirstLoad: boolean = DEFAULT_SETTINGS.isFirstLoad;
715

816
constructor(data: any) {
917
super();

src/screens/Main.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import TaskControl from '../components/TaskControl/TaskControl';
88
import HeaderMenu from '../components/HeaderMenu/HeaderMenu';
99
import HoursScreen from './hours/HoursScreen';
1010
import Dashboard from './dashboard/Dashboard';
11+
import Profile from '../components/Profile/Profile';
1112

1213
const { Header } = Layout;
1314

@@ -26,6 +27,7 @@ export default observer(function Main() {
2627
</HeaderMenu>
2728
<span className="flex-1" />
2829
<TaskControl />
30+
<Profile />
2931
</Header>
3032
<Switch>
3133
<Route exact path="/">

0 commit comments

Comments
 (0)