2016-02-19 02:00:11 +08:00
|
|
|
/** @babel */
|
|
|
|
import React, {Component, PropTypes} from 'react'
|
2016-03-23 04:42:16 +08:00
|
|
|
import {Actions, DateUtils} from 'nylas-exports'
|
2016-03-10 02:01:18 +08:00
|
|
|
import {Menu, DateInput} from 'nylas-component-kit'
|
2016-03-07 08:55:28 +08:00
|
|
|
|
|
|
|
const {DATE_FORMAT_SHORT, DATE_FORMAT_LONG} = DateUtils
|
2016-02-19 02:00:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
const SendLaterOptions = {
|
|
|
|
'In 1 hour': DateUtils.in1Hour,
|
2016-02-24 05:52:08 +08:00
|
|
|
'In 2 hours': DateUtils.in2Hours,
|
2016-02-25 09:44:53 +08:00
|
|
|
'Later today': DateUtils.laterToday,
|
|
|
|
'Tomorrow morning': DateUtils.tomorrow,
|
|
|
|
'Tomorrow evening': DateUtils.tomorrowEvening,
|
|
|
|
'This weekend': DateUtils.thisWeekend,
|
|
|
|
'Next week': DateUtils.nextWeek,
|
2016-02-19 02:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class SendLaterPopover extends Component {
|
|
|
|
static displayName = 'SendLaterPopover';
|
|
|
|
|
|
|
|
static propTypes = {
|
2016-03-10 02:01:18 +08:00
|
|
|
scheduledDate: PropTypes.string,
|
|
|
|
onSendLater: PropTypes.func.isRequired,
|
|
|
|
onCancelSendLater: PropTypes.func.isRequired,
|
2016-03-04 04:37:20 +08:00
|
|
|
};
|
|
|
|
|
2016-03-23 04:42:16 +08:00
|
|
|
onEscape() {
|
|
|
|
Actions.closePopover()
|
|
|
|
}
|
|
|
|
|
2016-02-24 05:52:08 +08:00
|
|
|
onSelectMenuOption = (optionKey)=> {
|
|
|
|
const date = SendLaterOptions[optionKey]();
|
2016-03-04 04:37:20 +08:00
|
|
|
this.selectDate(date, optionKey);
|
2016-02-19 02:00:11 +08:00
|
|
|
};
|
|
|
|
|
2016-03-04 04:37:20 +08:00
|
|
|
onSelectCustomOption = (date, inputValue)=> {
|
2016-02-25 03:19:03 +08:00
|
|
|
if (date) {
|
2016-03-04 04:37:20 +08:00
|
|
|
this.selectDate(date, "Custom");
|
2016-02-25 03:19:03 +08:00
|
|
|
} else {
|
2016-03-04 04:37:20 +08:00
|
|
|
NylasEnv.showErrorDialog(`Sorry, we can't parse ${inputValue} as a valid date.`);
|
2016-02-25 03:19:03 +08:00
|
|
|
}
|
2016-02-25 09:53:19 +08:00
|
|
|
};
|
2016-02-25 03:19:03 +08:00
|
|
|
|
2016-03-04 04:37:20 +08:00
|
|
|
selectDate = (date, dateLabel)=> {
|
|
|
|
const formatted = DateUtils.format(date.utc());
|
2016-03-10 02:01:18 +08:00
|
|
|
this.props.onSendLater(formatted, dateLabel);
|
2016-03-04 04:37:20 +08:00
|
|
|
};
|
2016-02-19 02:00:11 +08:00
|
|
|
|
2016-02-24 05:52:08 +08:00
|
|
|
renderMenuOption(optionKey) {
|
|
|
|
const date = SendLaterOptions[optionKey]();
|
|
|
|
const formatted = DateUtils.format(date, DATE_FORMAT_SHORT);
|
2016-02-19 02:00:11 +08:00
|
|
|
return (
|
2016-03-10 02:01:18 +08:00
|
|
|
<div className="send-later-option">
|
|
|
|
{optionKey}
|
|
|
|
<span className="time">{formatted}</span>
|
|
|
|
</div>
|
2016-02-24 05:52:08 +08:00
|
|
|
);
|
2016-02-19 02:00:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2016-02-26 02:23:53 +08:00
|
|
|
const headerComponents = [
|
2016-03-10 02:01:18 +08:00
|
|
|
<span key="send-later-header">Send later:</span>,
|
2016-02-26 02:23:53 +08:00
|
|
|
]
|
2016-02-24 05:52:08 +08:00
|
|
|
const footerComponents = [
|
|
|
|
<div key="divider" className="divider" />,
|
2016-03-04 04:37:20 +08:00
|
|
|
<DateInput
|
|
|
|
key="custom"
|
|
|
|
className="custom-section"
|
|
|
|
dateFormat={DATE_FORMAT_LONG}
|
|
|
|
onSubmitDate={this.onSelectCustomOption} />,
|
2016-02-24 05:52:08 +08:00
|
|
|
];
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
if (this.props.scheduledDate) {
|
2016-02-24 05:52:08 +08:00
|
|
|
footerComponents.push(<div key="divider-unschedule" className="divider" />)
|
|
|
|
footerComponents.push(
|
|
|
|
<div className="cancel-section" key="cancel-section">
|
2016-03-10 02:01:18 +08:00
|
|
|
<button className="btn btn-cancel" onClick={this.props.onCancelSendLater}>
|
2016-02-24 05:52:08 +08:00
|
|
|
Unschedule Send
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2016-02-19 02:00:11 +08:00
|
|
|
|
|
|
|
return (
|
2016-03-23 04:42:16 +08:00
|
|
|
<div className="send-later">
|
2016-03-10 02:01:18 +08:00
|
|
|
<Menu
|
|
|
|
ref="menu"
|
|
|
|
items={Object.keys(SendLaterOptions)}
|
|
|
|
itemKey={item => item}
|
|
|
|
itemContent={this.renderMenuOption}
|
|
|
|
defaultSelectedIndex={-1}
|
|
|
|
headerComponents={headerComponents}
|
|
|
|
footerComponents={footerComponents}
|
2016-03-23 04:42:16 +08:00
|
|
|
onEscape={this.onEscape}
|
2016-03-10 02:01:18 +08:00
|
|
|
onSelect={this.onSelectMenuOption} />
|
|
|
|
</div>
|
2016-02-19 02:00:11 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default SendLaterPopover
|