2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-03-27 22:57:03 +00:00
|
|
|
import DatePicker from 'react-datepicker'
|
2020-05-02 07:25:55 +01:00
|
|
|
import { FormattedMessage } from 'react-intl'
|
|
|
|
import moment from 'moment-mini'
|
2020-03-27 22:57:03 +00:00
|
|
|
import { changeScheduledAt } from '../../actions/compose'
|
2020-05-02 07:25:55 +01:00
|
|
|
import { openModal } from '../../actions/modal'
|
|
|
|
import { closePopover } from '../../actions/popover'
|
2020-03-27 22:57:03 +00:00
|
|
|
import { me } from '../../initial_state'
|
2020-07-06 21:13:44 +01:00
|
|
|
import { MODAL_PRO_UPGRADE } from '../../constants'
|
2020-03-27 22:57:03 +00:00
|
|
|
import PopoverLayout from './popover_layout'
|
2020-05-02 07:25:55 +01:00
|
|
|
import Button from '../button'
|
|
|
|
import Text from '../text'
|
2020-03-27 22:57:03 +00:00
|
|
|
|
2020-04-16 07:00:43 +01:00
|
|
|
import '!style-loader!css-loader!react-datepicker/dist/react-datepicker.css'
|
2020-03-27 22:57:03 +00:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class DatePickerPopover extends React.PureComponent {
|
2020-05-13 01:36:54 +01:00
|
|
|
|
2020-03-27 22:57:03 +00:00
|
|
|
handleSetDate = (date) => {
|
2020-05-15 04:46:10 +01:00
|
|
|
this.props.setScheduledAt(date, this.props.isPro)
|
2020-03-27 22:57:03 +00:00
|
|
|
}
|
2020-05-02 07:25:55 +01:00
|
|
|
|
|
|
|
handleRemoveDate = () => {
|
2020-05-15 04:46:10 +01:00
|
|
|
this.props.setScheduledAt(null, this.props.isPro)
|
2020-05-02 07:25:55 +01:00
|
|
|
}
|
2020-03-27 22:57:03 +00:00
|
|
|
|
2020-07-06 21:13:44 +01:00
|
|
|
handleOnClosePopover = () => {
|
|
|
|
this.props.onClosePopover()
|
|
|
|
}
|
|
|
|
|
2020-02-24 21:56:07 +00:00
|
|
|
render() {
|
2020-05-13 01:36:54 +01:00
|
|
|
const { date, isPro, isXS } = this.props
|
2020-03-27 22:57:03 +00:00
|
|
|
const datePickerDisabled = !isPro
|
|
|
|
|
2020-02-24 21:56:07 +00:00
|
|
|
return (
|
2020-07-06 21:13:44 +01:00
|
|
|
<PopoverLayout
|
|
|
|
width={360}
|
|
|
|
isXS={isXS}
|
|
|
|
onClose={this.handleOnClosePopover}
|
|
|
|
>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.bgSubtle].join(' ')}>
|
2020-05-02 07:25:55 +01:00
|
|
|
<DatePicker
|
|
|
|
inline
|
|
|
|
target={this}
|
|
|
|
className='schedule-post-dropdown__datepicker'
|
|
|
|
minDate={new Date()}
|
|
|
|
selected={date}
|
|
|
|
onChange={date => this.handleSetDate(date)}
|
|
|
|
timeFormat='p'
|
|
|
|
timeIntervals={15}
|
|
|
|
timeCaption='Time'
|
|
|
|
dateFormat='MMM d, yyyy h:mm aa'
|
|
|
|
disabled={datePickerDisabled}
|
|
|
|
showTimeSelect
|
|
|
|
popperModifiers={{
|
|
|
|
offset: {
|
|
|
|
enabled: true,
|
|
|
|
offset: '0px, 5px'
|
|
|
|
},
|
|
|
|
preventOverflow: {
|
|
|
|
enabled: true,
|
|
|
|
escapeWithReference: false,
|
|
|
|
boundariesElement: 'viewport'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{
|
|
|
|
date &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.aiCenter, _s.flexRow, _s.px10, _s.py10, _s.borderTop1PX, _s.borderColorSecondary].join(' ')}>
|
2020-05-02 07:25:55 +01:00
|
|
|
<Text size='extraSmall' color='secondary'>
|
|
|
|
<FormattedMessage id='scheduled_for_datetime' defaultMessage='Scheduled for {datetime}' values={{
|
|
|
|
datetime: moment.utc(date).format('lll'),
|
|
|
|
}}/>
|
|
|
|
</Text>
|
|
|
|
<div className={_s.mlAuto}>
|
|
|
|
<Button
|
|
|
|
isNarrow
|
|
|
|
radiusSmall
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='tertiary'
|
|
|
|
onClick={this.handleRemoveDate}
|
|
|
|
>
|
|
|
|
<Text color='inherit' size='small'>
|
|
|
|
<FormattedMessage id='remove' defaultMessage='Remove' />
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
2020-03-27 22:57:03 +00:00
|
|
|
</PopoverLayout>
|
2020-02-24 21:56:07 +00:00
|
|
|
)
|
|
|
|
}
|
2020-05-13 01:36:54 +01:00
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
date: state.getIn(['compose', 'scheduled_at']),
|
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
setScheduledAt (date, isPro) {
|
|
|
|
if (!isPro) {
|
|
|
|
dispatch(closePopover())
|
|
|
|
return dispatch(openModal(MODAL_PRO_UPGRADE))
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(changeScheduledAt(date))
|
|
|
|
|
|
|
|
if (!date) {
|
|
|
|
dispatch(closePopover())
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onClosePopover: () => dispatch(closePopover())
|
|
|
|
})
|
|
|
|
|
|
|
|
DatePickerPopover.propTypes = {
|
|
|
|
date: PropTypes.instanceOf(Date),
|
|
|
|
setScheduledAt: PropTypes.func.isRequired,
|
|
|
|
isPro: PropTypes.bool,
|
|
|
|
position: PropTypes.string,
|
|
|
|
small: PropTypes.bool,
|
|
|
|
isXS: PropTypes.bool,
|
|
|
|
onClosePopover: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DatePickerPopover)
|