-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathdateTime.tsx
77 lines (66 loc) · 2.23 KB
/
dateTime.tsx
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
import * as React from 'react';
import moment from 'moment';
import {IEditorFieldProps} from '../../../../interfaces';
import {DateTimeInput} from '../../../UI/Form';
import {get} from 'lodash';
interface IProps extends IEditorFieldProps {
canClear?: boolean;
showToBeConfirmed?: boolean;
toBeConfirmed?: boolean;
isLocalTimeZoneDifferent?: boolean;
remoteTimeZone?: string;
singleValue?: boolean;
onToBeConfirmed?(field: string): void;
allDay?: boolean;
hideTime?: boolean;
}
export class EditorFieldDateTime extends React.PureComponent<IProps> {
node: HTMLInputElement;
constructor(props: IProps) {
super(props);
this.onChange = this.onChange.bind(this);
}
focus() {
if (this.node != null) {
this.node.focus();
}
}
onChange(field: string, value: moment.Moment) {
// `field` is appended with `.date` or `.time` depending on what changed
// Not all usages of this component requires this, so use `this.props.field` instead
if (this.props.singleValue === true) {
this.props.onChange(this.props.field, value);
} else {
this.props.onChange(field, value);
}
}
render() {
const field = this.props.field;
const value = get(this.props.item, field, this.props.defaultValue);
const error = get(this.props.errors ?? {}, field);
let momentValue : moment.Moment;
if (value != null) {
momentValue = this.props.allDay ? moment.utc(value) : moment(value);
} else {
momentValue = undefined;
}
return (
<DateTimeInput
{...this.props}
diff={this.props.item}
field={field}
value={momentValue}
message={error}
invalid={error?.length > 0 && this.props.invalid}
testId={this.props.testId}
readOnly={this.props.disabled}
required={this.props.schema?.required}
onChange={this.onChange}
refNode={(node) => {
this.node = node;
}}
allDay={this.props.allDay}
/>
);
}
}