-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTimeblockPreferenceEditorTimeblockRowDragOverlay.tsx
More file actions
82 lines (73 loc) · 2.42 KB
/
TimeblockPreferenceEditorTimeblockRowDragOverlay.tsx
File metadata and controls
82 lines (73 loc) · 2.42 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
import { useMemo, useContext } from 'react';
import { DateTime } from 'luxon';
import TimeSelect from '../../BuiltInFormControls/TimeSelect';
import Timespan from '../../Timespan';
import AppRootContext from '../../AppRootContext';
import { TimeblockDefinition } from '../../FormPresenter/TimeblockTypes';
import { WithGeneratedId } from '../../GeneratedIdUtils';
import { getTimeblockTimespanForDisplay } from '../../FormPresenter/TimeblockUtils';
export type TimeblockPreferenceEditorTimeblockRowDragOverlayProps = {
timeblock: WithGeneratedId<TimeblockDefinition, string>;
};
function TimeblockPreferenceEditorTimeblockRowDragOverlay({
timeblock,
}: TimeblockPreferenceEditorTimeblockRowDragOverlayProps): React.JSX.Element {
const { timezoneName } = useContext(AppRootContext);
const selectTimespan = useMemo(
() =>
Timespan.finiteFromDateTimes(
DateTime.fromObject({ hour: 0 }, { zone: timezoneName }),
DateTime.fromObject({ hour: 0 }, { zone: timezoneName }).plus({ hours: 31 }),
),
[timezoneName],
);
const timespanError = useMemo(() => {
if (!timeblock.start || !timeblock.finish) {
return null;
}
try {
getTimeblockTimespanForDisplay(timeblock);
} catch (e) {
return e instanceof Error ? e.message : String(e);
}
return null;
}, [timeblock]);
return (
<tr>
<td style={{ cursor: 'grabbing' }}>
<span className="visually-hidden">Drag to reorder</span>
<i className="bi-grip-vertical" />
</td>
<td>
<TimeSelect value={timeblock.start} onChange={() => {}} timespan={selectTimespan} />
{timespanError && (
<div className="small text-danger mt-1">
<i className="bi-exclamation-triangle-fill" /> {timespanError}
</div>
)}
</td>
<td>
<TimeSelect value={timeblock.finish} onChange={() => {}} timespan={selectTimespan} />
</td>
<td>
<input
aria-label="Timeblock label"
value={timeblock.label || ''}
className="form-control"
onChange={() => {}}
/>
</td>
<td>
<button
type="button"
className="btn btn-sm btn-outline-danger"
aria-label="Delete timeblock"
onClick={() => {}}
>
<i className="bi-trash" />
</button>
</td>
</tr>
);
}
export default TimeblockPreferenceEditorTimeblockRowDragOverlay;