/** @babel */ import React, {Component, PropTypes} from 'react' import {Actions, DateUtils} from 'nylas-exports' import {Menu, DateInput} from 'nylas-component-kit' const {DATE_FORMAT_SHORT, DATE_FORMAT_LONG} = DateUtils const SendLaterOptions = { 'In 1 hour': DateUtils.in1Hour, 'In 2 hours': DateUtils.in2Hours, 'Later today': DateUtils.laterToday, 'Tomorrow morning': DateUtils.tomorrow, 'Tomorrow evening': DateUtils.tomorrowEvening, 'This weekend': DateUtils.thisWeekend, 'Next week': DateUtils.nextWeek, } class SendLaterPopover extends Component { static displayName = 'SendLaterPopover'; static propTypes = { scheduledDate: PropTypes.string, onSendLater: PropTypes.func.isRequired, onCancelSendLater: PropTypes.func.isRequired, }; onEscape() { Actions.closePopover() } onSelectMenuOption = (optionKey)=> { const date = SendLaterOptions[optionKey](); this.selectDate(date, optionKey); }; onSelectCustomOption = (date, inputValue)=> { if (date) { this.selectDate(date, "Custom"); } else { NylasEnv.showErrorDialog(`Sorry, we can't parse ${inputValue} as a valid date.`); } }; selectDate = (date, dateLabel)=> { const formatted = DateUtils.format(date.utc()); this.props.onSendLater(formatted, dateLabel); }; renderMenuOption(optionKey) { const date = SendLaterOptions[optionKey](); const formatted = DateUtils.format(date, DATE_FORMAT_SHORT); return (
{optionKey} {formatted}
); } render() { const headerComponents = [ Send later:, ] const footerComponents = [
, , ]; if (this.props.scheduledDate) { footerComponents.push(
) footerComponents.push(
) } return (
item} itemContent={this.renderMenuOption} defaultSelectedIndex={-1} headerComponents={headerComponents} footerComponents={footerComponents} onEscape={this.onEscape} onSelect={this.onSelectMenuOption} />
); } } export default SendLaterPopover