Mailspring/internal_packages/send-later/lib/send-later-popover.jsx
Juan Tejada e3fc29ee36 remove(popover): Remove Popover in favor of FixedPopover
Summary:
- FixedPopover now correctly adjusts itself when overflowing outside
  window, in all directions
  - Updates styles
  - Adds specs
- Remove Popover and popover.less, and refactor all code that used it in
  favor of the new FixedPopover

Test Plan: Unit tests

Reviewers: drew, evan, bengotow

Reviewed By: bengotow

Differential Revision: https://phab.nylas.com/D2697
2016-03-09 10:05:46 -08:00

100 lines
2.7 KiB
JavaScript

/** @babel */
import React, {Component, PropTypes} from 'react'
import {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,
};
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 (
<div className="send-later-option">
{optionKey}
<span className="time">{formatted}</span>
</div>
);
}
render() {
const headerComponents = [
<span key="send-later-header">Send later:</span>,
]
const footerComponents = [
<div key="divider" className="divider" />,
<DateInput
key="custom"
className="custom-section"
dateFormat={DATE_FORMAT_LONG}
onSubmitDate={this.onSelectCustomOption} />,
];
if (this.props.scheduledDate) {
footerComponents.push(<div key="divider-unschedule" className="divider" />)
footerComponents.push(
<div className="cancel-section" key="cancel-section">
<button className="btn btn-cancel" onClick={this.props.onCancelSendLater}>
Unschedule Send
</button>
</div>
)
}
return (
<div
className="send-later">
<Menu
ref="menu"
items={Object.keys(SendLaterOptions)}
itemKey={item => item}
itemContent={this.renderMenuOption}
defaultSelectedIndex={-1}
headerComponents={headerComponents}
footerComponents={footerComponents}
onSelect={this.onSelectMenuOption} />
</div>
);
}
}
export default SendLaterPopover