forked from Yadro/time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsModal.tsx
More file actions
147 lines (135 loc) · 4.48 KB
/
SettingsModal.tsx
File metadata and controls
147 lines (135 loc) · 4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import React, { useCallback, useState } from 'react';
import {
Button,
Checkbox,
Divider,
Form,
Modal,
Select,
Space,
TimePicker,
} from 'antd';
import { CheckboxChangeEvent } from 'antd/lib/checkbox';
import { SaveOutlined } from '@ant-design/icons';
import { observer } from 'mobx-react';
import * as Sentry from '@sentry/browser';
// eslint-disable-next-line import/named
import moment, { Moment } from 'moment';
import rootStore from '../../modules/RootStore';
import IModalProps from '../../types/IModalProps';
import NewProfilePopover from './NewProfilePopover';
import { timeToMs } from '../../helpers/DateTime';
import { DEFAULT_SETTINGS } from '../../modules/settings/models/SettingsModel';
import AbstractFileRepository from '../../base/repositories/AbstractFileRepository';
const { settingsStore } = rootStore;
interface ISettingsModalProps extends IModalProps {}
const timeFormat = 'HH:mm';
const SettingsModal: React.VFC<ISettingsModalProps> = observer(
(props: ISettingsModalProps) => {
const { visible, onClose } = props;
const { settings } = settingsStore;
const [showNewProfilePopover, setShowNewProfilePopover] = useState<boolean>(
false
);
const [showNotifications, setShowNotifications] = useState<boolean>(
settings.showNotifications
);
const [profile, setProfile] = useState<string>(settings.currentProfile);
const [workingHours, setWorkingHours] = useState<Moment | null>(
moment(settings.numberOfWorkingHours).utcOffset(0)
);
const handleSave = useCallback(() => {
settingsStore.setSettings({
currentProfile: profile,
numberOfWorkingHours: workingHours
? timeToMs(workingHours?.toDate())
: DEFAULT_SETTINGS.numberOfWorkingHours,
showNotifications,
});
onClose();
}, [profile, workingHours, showNotifications, onClose]);
const handleChangeProfile = useCallback((selected: string) => {
setProfile(selected);
}, []);
const handleCreateProfile = useCallback(
(visible: boolean, profile?: string) => {
setShowNewProfilePopover(visible);
if (profile) {
setProfile(profile);
}
},
[]
);
const handleChangeNotifications = useCallback((e: CheckboxChangeEvent) => {
setShowNotifications(e.target.checked);
}, []);
return (
<Modal
title="Settings"
visible={visible}
// okButtonProps={{ disabled: !valid }}
okButtonProps={{ icon: <SaveOutlined /> }}
okText="Save"
onOk={handleSave}
onCancel={onClose}
>
<Form.Item label="Switch profile" labelCol={{ span: 24 }}>
<Space>
<Select
value={profile}
onChange={handleChangeProfile}
style={{ width: 200 }}
>
{settings.profiles.map((profile) => (
<Select.Option key={profile} value={profile}>
{profile}
</Select.Option>
))}
</Select>
<NewProfilePopover
visible={showNewProfilePopover}
onChange={handleCreateProfile}
/>
</Space>
</Form.Item>
<Divider />
<Form.Item label="Amount of working hours" labelCol={{ span: 10 }}>
<TimePicker
value={workingHours}
onChange={(value) => setWorkingHours(value)}
format={timeFormat}
minuteStep={5}
showNow={false}
allowClear={false}
/>
</Form.Item>
<Form.Item label="Notifications" labelCol={{ span: 10 }}>
<Checkbox
checked={showNotifications}
onChange={handleChangeNotifications}
/>
</Form.Item>
{process.env.DEBUG_PROD === 'true' && (
<Button
onClick={() => {
const message = `${process.env.NODE_ENV} exception ${Date.now()}`;
Sentry.captureException(new Error(message));
console.log('Sentry.captureException', message);
}}
>
Test Sentry
</Button>
)}
{(process.env.NODE_ENV === 'development' ||
process.env.DEBUG_PROD === 'true') && (
<>
<p>{`APPDATA: ${AbstractFileRepository.appDataFolder}`}</p>
<p>{`SENTRY_DSN: ${process.env.SENTRY_DSN}`}</p>
<p>{`GA_UACODE: ${process.env.GA_UACODE}`}</p>
</>
)}
</Modal>
);
}
);
export default SettingsModal;