Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 797a500

Browse files
author
Dmitry Yadrikhinsky
committed
TimePicker + description
1 parent 77a29fe commit 797a500

File tree

1 file changed

+55
-24
lines changed

1 file changed

+55
-24
lines changed
Lines changed: 55 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useEffect, useState } from 'react';
2-
import { DatePicker, Modal } from 'antd';
2+
import { Col, Form, Input, Modal, Row, Space, TimePicker } from 'antd';
33
import { Moment } from 'moment/moment';
44
import moment from 'moment';
5-
import { RangeValue } from 'rc-picker/lib/interface';
65

76
import './TimeRangeModal.less';
87

@@ -11,7 +10,12 @@ import TaskTimeModel from '../../models/TaskTimeModel';
1110
import { ITimeRangeModel } from '../../models/TaskModel';
1211
import { Undefined } from '../../types/CommonTypes';
1312

14-
const { RangePicker } = DatePicker;
13+
const { tasksStore } = rootStore;
14+
15+
enum RangeField {
16+
start = 'start',
17+
end = 'end',
18+
}
1519

1620
interface TimeRangeModalProps {
1721
taskTime?: TaskTimeModel;
@@ -24,20 +28,24 @@ export default function TimeRangeModal({
2428
visible,
2529
onClose,
2630
}: TimeRangeModalProps) {
27-
const [taskTimeItem, setTaskTimeItem] = useState(taskTime);
31+
const [description, setDescription] = useState<string>('');
2832
const [timeRange, setTimeRange] = useState<Undefined<ITimeRangeModel>>();
33+
const timeInProgress = !taskTime?.time.end;
2934

3035
useEffect(() => {
3136
if (taskTime) {
32-
setTaskTimeItem(taskTime);
3337
setTimeRange({ ...taskTime.time });
38+
setDescription(taskTime.time.description || '');
3439
}
3540
}, [taskTime]);
3641

3742
function handleOk() {
3843
if (taskTime?.task && timeRange) {
3944
const { task, index } = taskTime;
40-
task.time[index] = timeRange;
45+
if (description) {
46+
timeRange.description = description;
47+
}
48+
tasksStore.setTime(task, index, timeRange);
4149
}
4250
onClose();
4351
}
@@ -46,12 +54,14 @@ export default function TimeRangeModal({
4654
onClose();
4755
}
4856

49-
function onChange(dates: RangeValue<Moment>) {
50-
setTimeRange({
51-
start: dates?.[0]?.toDate() || new Date(),
52-
end: dates?.[1]?.toDate(),
53-
description: '',
54-
});
57+
function onChange(field: RangeField) {
58+
return (value: Moment | null) => {
59+
const newTimeRange = {
60+
...timeRange,
61+
[field]: value?.toDate() || undefined,
62+
};
63+
setTimeRange(newTimeRange as ITimeRangeModel);
64+
};
5565
}
5666

5767
return (
@@ -62,18 +72,39 @@ export default function TimeRangeModal({
6272
onCancel={handleCancel}
6373
okText="Save"
6474
>
65-
<div>Task: {taskTime?.task.title}</div>
66-
67-
<RangePicker
68-
showTime={{ format: 'HH:mm' }}
69-
format="DD-MM-YYYY HH:mm"
70-
value={[
71-
moment(timeRange?.start),
72-
timeRange?.end ? moment(timeRange?.end) : undefined,
73-
]}
74-
onOk={onChange}
75-
onChange={onChange}
76-
/>
75+
<Form colon>
76+
<Form.Item label="Task">
77+
<div>{taskTime?.task.title}</div>
78+
</Form.Item>
79+
<Form.Item label="Description">
80+
<Input
81+
placeholder="Type description..."
82+
value={description}
83+
onChange={(e) => setDescription(e.target.value)}
84+
/>
85+
</Form.Item>
86+
<Row>
87+
<Col span={12}>
88+
<Form.Item label="Start" labelCol={{ span: 24 }}>
89+
<TimePicker
90+
format="HH:mm"
91+
value={moment(timeRange?.start)}
92+
onChange={onChange(RangeField.start)}
93+
/>
94+
</Form.Item>
95+
</Col>
96+
<Col span={12}>
97+
<Form.Item label="End" labelCol={{ span: 24 }}>
98+
<TimePicker
99+
format="HH:mm"
100+
value={timeRange?.end && moment(timeRange?.end)}
101+
onChange={onChange(RangeField.end)}
102+
disabled={timeInProgress}
103+
/>
104+
</Form.Item>
105+
</Col>
106+
</Row>
107+
</Form>
77108
</Modal>
78109
);
79110
}

0 commit comments

Comments
 (0)