2017-05-19 14:42:43 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-07-07 12:48:35 +02:00
|
|
|
import DateTimePicker from 'react-datetime';
|
2019-01-24 18:01:53 +09:00
|
|
|
import { Components, registerComponent } from 'meteor/vulcan:core';
|
2016-04-18 10:03:53 +09:00
|
|
|
|
2017-05-19 14:42:43 -06:00
|
|
|
class DateTime extends PureComponent {
|
2017-01-10 11:17:16 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.updateDate = this.updateDate.bind(this);
|
|
|
|
}
|
2017-01-11 18:02:12 +01:00
|
|
|
|
2017-01-10 11:17:16 +01:00
|
|
|
updateDate(date) {
|
2019-01-24 18:01:53 +09:00
|
|
|
this.context.updateCurrentValues({ [this.props.path]: date });
|
2016-07-07 12:48:35 +02:00
|
|
|
}
|
|
|
|
|
2016-04-18 10:03:53 +09:00
|
|
|
render() {
|
2019-01-24 18:01:53 +09:00
|
|
|
const date = this.props.value
|
|
|
|
? typeof this.props.value === 'string'
|
|
|
|
? new Date(this.props.value)
|
|
|
|
: this.props.value
|
|
|
|
: null;
|
2017-02-21 19:08:14 +01:00
|
|
|
|
2016-04-18 10:03:53 +09:00
|
|
|
return (
|
2019-01-24 18:01:53 +09:00
|
|
|
<Components.FormItem>
|
|
|
|
<DateTimePicker
|
|
|
|
value={date}
|
|
|
|
// newDate argument is a Moment object given by react-datetime
|
|
|
|
onChange={newDate => this.updateDate(newDate._d)}
|
|
|
|
format={'x'}
|
|
|
|
inputProps={{ name: this.props.name }}
|
|
|
|
/>
|
|
|
|
</Components.FormItem>
|
2016-07-06 15:53:14 +02:00
|
|
|
);
|
2016-04-18 10:03:53 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DateTime.propTypes = {
|
2017-05-19 14:42:43 -06:00
|
|
|
control: PropTypes.any,
|
|
|
|
datatype: PropTypes.any,
|
|
|
|
group: PropTypes.any,
|
|
|
|
label: PropTypes.string,
|
|
|
|
name: PropTypes.string,
|
|
|
|
value: PropTypes.any,
|
2016-09-07 14:35:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
DateTime.contextTypes = {
|
2017-05-19 14:42:43 -06:00
|
|
|
updateCurrentValues: PropTypes.func,
|
2016-09-07 14:35:49 +02:00
|
|
|
};
|
2016-04-18 10:03:53 +09:00
|
|
|
|
2016-09-27 07:30:58 +02:00
|
|
|
export default DateTime;
|
2017-08-19 10:41:08 +09:00
|
|
|
|
2019-01-24 18:01:53 +09:00
|
|
|
registerComponent('FormComponentDateTime', DateTime);
|