2020-02-08 06:12:01 +00:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl'
|
|
|
|
import DatePicker from 'react-datepicker'
|
|
|
|
import { changeScheduledAt } from '../../../actions/compose'
|
|
|
|
import { openModal } from '../../../actions/modal'
|
|
|
|
import { me } from '../../../initial_state'
|
|
|
|
import { isMobile } from '../../../utils/is_mobile'
|
|
|
|
import ComposeExtraButton from './compose_extra_button'
|
2019-09-19 01:15:27 +01:00
|
|
|
|
2020-02-08 22:57:09 +00:00
|
|
|
// import 'react-datepicker/dist/react-datepicker.css'
|
2019-09-19 01:15:27 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-02-08 06:12:01 +00:00
|
|
|
schedule_status: { id: 'schedule_status.title', defaultMessage: 'Schedule' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = state => ({
|
|
|
|
date: state.getIn(['compose', 'scheduled_at']),
|
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
setScheduledAt (date) {
|
|
|
|
dispatch(changeScheduledAt(date))
|
|
|
|
},
|
|
|
|
|
|
|
|
onOpenProUpgradeModal() {
|
|
|
|
dispatch(openModal('PRO_UPGRADE'))
|
|
|
|
},
|
|
|
|
})
|
2019-09-19 01:15:27 +01:00
|
|
|
|
2020-01-29 21:54:39 +00:00
|
|
|
class DatePickerWrapper extends PureComponent {
|
2019-09-19 03:52:59 +01:00
|
|
|
static propTypes = {
|
|
|
|
value: PropTypes.string,
|
|
|
|
onClick: PropTypes.func,
|
2020-02-08 06:12:01 +00:00
|
|
|
}
|
2019-09-19 03:52:59 +01:00
|
|
|
|
|
|
|
render() {
|
2020-02-08 06:12:01 +00:00
|
|
|
const { value, onClick } = this.props
|
2019-09-19 03:52:59 +01:00
|
|
|
|
|
|
|
return (
|
2020-02-08 06:12:01 +00:00
|
|
|
<button className='schedule-post-dropdown-wrapper' onClick={onClick}>
|
2019-09-19 03:52:59 +01:00
|
|
|
{value}
|
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2019-09-19 03:04:49 +01:00
|
|
|
|
2020-02-08 06:12:01 +00:00
|
|
|
export default
|
|
|
|
@injectIntl
|
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
2020-01-29 21:54:39 +00:00
|
|
|
class SchedulePostDropdown extends PureComponent {
|
2019-09-19 01:15:27 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
date: PropTypes.instanceOf(Date),
|
|
|
|
setScheduledAt: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isPro: PropTypes.bool,
|
|
|
|
onOpenProUpgradeModal: PropTypes.func.isRequired,
|
2019-09-19 21:07:35 +01:00
|
|
|
position: PropTypes.string,
|
2020-02-08 06:12:01 +00:00
|
|
|
}
|
2019-09-19 01:15:27 +01:00
|
|
|
|
|
|
|
handleToggle = () => {
|
|
|
|
if (!this.props.isPro) {
|
2020-02-08 06:12:01 +00:00
|
|
|
return this.props.onOpenProUpgradeModal()
|
2019-09-19 01:15:27 +01:00
|
|
|
}
|
|
|
|
|
2020-02-08 06:12:01 +00:00
|
|
|
const { date } = this.props
|
|
|
|
const value = date ? null : new Date()
|
|
|
|
this.handleSetDate(value)
|
2019-09-19 01:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleSetDate = (date) => {
|
2020-02-08 06:12:01 +00:00
|
|
|
this.props.setScheduledAt(date)
|
2019-09-19 01:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2020-02-08 06:12:01 +00:00
|
|
|
const { intl, date, isPro, position } = this.props
|
2019-09-19 03:52:59 +01:00
|
|
|
|
2020-02-08 06:12:01 +00:00
|
|
|
const open = !!date
|
|
|
|
const datePickerDisabled = !isPro
|
|
|
|
const withPortal = isMobile(window.innerWidth)
|
|
|
|
const popperPlacement = position || undefined
|
2019-09-19 01:15:27 +01:00
|
|
|
|
|
|
|
return (
|
2020-02-08 06:12:01 +00:00
|
|
|
<div className={[].join(' ')}>
|
|
|
|
<div className={[].join(' ')}>
|
|
|
|
<ComposeExtraButton
|
2019-09-19 01:15:27 +01:00
|
|
|
icon='calendar'
|
2019-09-19 02:15:29 +01:00
|
|
|
title={intl.formatMessage(messages.schedule_status)}
|
2019-09-19 01:15:27 +01:00
|
|
|
onClick={this.handleToggle}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
open &&
|
|
|
|
<DatePicker
|
|
|
|
target={this}
|
|
|
|
className='schedule-post-dropdown__datepicker'
|
|
|
|
minDate={new Date()}
|
|
|
|
selected={date}
|
|
|
|
onChange={date => this.handleSetDate(date)}
|
2020-02-08 06:12:01 +00:00
|
|
|
timeFormat='p'
|
2019-09-19 01:15:27 +01:00
|
|
|
timeIntervals={15}
|
2020-02-08 06:12:01 +00:00
|
|
|
timeCaption='Time'
|
|
|
|
dateFormat='MMM d, yyyy h:mm aa'
|
2019-09-19 01:15:27 +01:00
|
|
|
disabled={datePickerDisabled}
|
|
|
|
showTimeSelect
|
2019-09-19 03:04:49 +01:00
|
|
|
customInput={<DatePickerWrapper />}
|
|
|
|
withPortal={withPortal}
|
2019-09-19 21:07:35 +01:00
|
|
|
popperPlacement={popperPlacement}
|
2019-09-19 02:39:43 +01:00
|
|
|
popperModifiers={{
|
|
|
|
offset: {
|
|
|
|
enabled: true,
|
2020-02-08 06:12:01 +00:00
|
|
|
offset: '0px, 5px'
|
2019-09-19 02:39:43 +01:00
|
|
|
},
|
|
|
|
preventOverflow: {
|
|
|
|
enabled: true,
|
|
|
|
escapeWithReference: false,
|
2020-02-08 06:12:01 +00:00
|
|
|
boundariesElement: 'viewport'
|
2019-09-19 02:39:43 +01:00
|
|
|
}
|
|
|
|
}}
|
2019-09-19 01:15:27 +01:00
|
|
|
/>
|
|
|
|
}
|
|
|
|
</div>
|
2020-02-08 06:12:01 +00:00
|
|
|
)
|
2019-09-19 01:15:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|