Mailspring/internal_packages/composer-scheduler/lib/composer/event-datetime-input.jsx
Evan Morikawa a1b5a23273 refactor(scheduler): move all event data into metadata
Summary: Moved events into metadata. Removed a lot of code

Test Plan: todo

Reviewers: juan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2866
2016-04-09 21:19:01 -04:00

68 lines
1.7 KiB
JavaScript

import React from 'react';
import moment from 'moment-timezone'
import {Utils} from 'nylas-exports'
function getDateFormat(type) {
if (type === "date") {
return "YYYY-MM-DD";
} else if (type === "time") {
return "HH:mm:ss"
}
return null
}
export default class EventDatetimeInput extends React.Component {
static displayName = "EventDatetimeInput";
static propTypes = {
name: React.PropTypes.string,
value: React.PropTypes.number.isRequired,
onChange: React.PropTypes.func.isRequired,
reversed: React.PropTypes.bool,
};
constructor(props) {
super(props);
this._datePartStrings = {time: "", date: ""};
}
_onDateChange() {
const {date, time} = this._datePartStrings;
const format = `${getDateFormat("date")} ${getDateFormat("time")}`;
const newDate = moment.tz(`${date} ${time}`, format, Utils.timeZone).unix();
this.props.onChange(newDate)
}
_renderInput(type) {
const unixDate = this.props.value;
const str = moment.unix(unixDate).tz(Utils.timeZone).format(getDateFormat(type))
this._datePartStrings[type] = unixDate != null ? str : null;
return (
<input type={type}
ref={type}
name={`${this.props.name}-${type}`}
value={this._datePartStrings[type]}
onChange={e => {
this._datePartStrings[type] = e.target.value;
this._onDateChange()
}}
/>
)
}
render() {
if (this.props.reversed) {
return (
<span className="datetime-input-container">
{this._renderInput("time")} on {this._renderInput("date")}
</span>
)
}
return (
<span className="datetime-input-container">
{this._renderInput("date")} at {this._renderInput("time")}
</span>
)
}
}