forked from Yadro/time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeRangeModal.tsx
More file actions
79 lines (68 loc) · 1.85 KB
/
TimeRangeModal.tsx
File metadata and controls
79 lines (68 loc) · 1.85 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
import React, { useEffect, useState } from 'react';
import { DatePicker, Modal } from 'antd';
import { Moment } from 'moment/moment';
import moment from 'moment';
import { RangeValue } from 'rc-picker/lib/interface';
import './TimeRangeModal.less';
import rootStore from '../../services/RootStore';
import TaskTimeModel from '../../models/TaskTimeModel';
import { ITimeRangeModel } from '../../models/TaskModel';
import { Undefined } from '../../types/CommonTypes';
const { RangePicker } = DatePicker;
interface TimeRangeModalProps {
taskTime?: TaskTimeModel;
visible: boolean;
onClose: () => void;
}
export default function TimeRangeModal({
taskTime,
visible,
onClose,
}: TimeRangeModalProps) {
const [taskTimeItem, setTaskTimeItem] = useState(taskTime);
const [timeRange, setTimeRange] = useState<Undefined<ITimeRangeModel>>();
useEffect(() => {
if (taskTime) {
setTaskTimeItem(taskTime);
setTimeRange({ ...taskTime.time });
}
}, [taskTime]);
function handleOk() {
if (taskTime?.task && timeRange) {
const { task, index } = taskTime;
task.time[index] = timeRange;
}
onClose();
}
function handleCancel() {
onClose();
}
function onChange(dates: RangeValue<Moment>) {
setTimeRange({
start: dates?.[0]?.toDate() || new Date(),
end: dates?.[1]?.toDate(),
description: '',
});
}
return (
<Modal
title="Edit time range"
visible={visible}
onOk={handleOk}
onCancel={handleCancel}
okText="Save"
>
<div>Task: {taskTime?.task.title}</div>
<RangePicker
showTime={{ format: 'HH:mm' }}
format="DD-MM-YYYY HH:mm"
value={[
moment(timeRange?.start),
timeRange?.end ? moment(timeRange?.end) : undefined,
]}
onOk={onChange}
onChange={onChange}
/>
</Modal>
);
}