2019-11-06 12:12:41 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2020-02-26 12:44:56 +00:00
|
|
|
import { StyledDatePicker } from "./StyledControls";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
2019-11-06 12:12:41 +00:00
|
|
|
import moment from "moment-timezone";
|
|
|
|
|
|
|
|
|
|
class DatePickerControl extends BaseControl<DatePickerControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDatePicker
|
|
|
|
|
formatDate={this.formatDate}
|
|
|
|
|
parseDate={this.parseDate}
|
|
|
|
|
placeholder={"DD/MM/YYYY"}
|
|
|
|
|
showActionsBar={true}
|
|
|
|
|
timePickerProps={{
|
|
|
|
|
useAmPm: true,
|
2020-03-20 11:03:50 +00:00
|
|
|
value: new Date(this.props.propertyValue),
|
2020-02-26 12:44:56 +00:00
|
|
|
showArrowButtons: true,
|
|
|
|
|
}}
|
|
|
|
|
onChange={this.onDateSelected}
|
2020-03-20 11:03:50 +00:00
|
|
|
value={new Date(this.props.propertyValue)}
|
2020-02-26 12:44:56 +00:00
|
|
|
/>
|
2019-11-06 12:12:41 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
formatDate = (date: Date): string => {
|
|
|
|
|
return moment(date).format("DD/MM/YYYY");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
parseDate = (dateStr: string): Date => {
|
|
|
|
|
return moment(dateStr).toDate();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
onDateSelected = (date: Date): void => {
|
|
|
|
|
this.updateProperty(this.props.propertyName, date);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "DATE_PICKER";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface DatePickerControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
propertyValue: Date;
|
2020-03-20 11:03:50 +00:00
|
|
|
enableTimePicker: boolean;
|
2019-11-06 12:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default DatePickerControl;
|