gab-social/app/javascript/gabsocial/components/modal/mute_modal.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-03-24 04:39:12 +00:00
import { injectIntl, defineMessages } from 'react-intl'
import { makeGetAccount } from '../../selectors'
import { muteAccount } from '../../actions/accounts'
import ConfirmationModal from './confirmation_modal'
2019-07-02 08:10:25 +01:00
2019-08-13 16:54:29 +01:00
const messages = defineMessages({
2020-03-24 04:39:12 +00:00
title: { id: 'mute_title', defaultMessage: 'Mute {name}' },
2019-08-13 16:54:29 +01:00
muteMessage: { id: 'confirmations.mute.message', defaultMessage: 'Are you sure you want to mute {name}?' },
2020-03-24 04:39:12 +00:00
mute: { id: 'confirmations.mute.confirm', defaultMessage: 'Mute' },
})
const mapStateToProps = (state, { accountId }) => {
const getAccount = makeGetAccount()
2019-07-02 08:10:25 +01:00
return {
2020-03-24 04:39:12 +00:00
account: getAccount(state, accountId),
}
}
2019-07-02 08:10:25 +01:00
2020-04-11 23:29:19 +01:00
const mapDispatchToProps = (dispatch) => ({
onConfirm(account, notifications) {
dispatch(muteAccount(account.get('id'), notifications))
},
})
2019-07-02 08:10:25 +01:00
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps, mapDispatchToProps)
2019-07-02 08:10:25 +01:00
@injectIntl
class MuteModal extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
account: PropTypes.object.isRequired,
onConfirm: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
2020-04-07 02:53:23 +01:00
onClose: PropTypes.func.isRequired,
2019-07-02 08:10:25 +01:00
}
handleClick = () => {
2020-03-24 04:39:12 +00:00
this.props.onConfirm(this.props.account)
2019-07-02 08:10:25 +01:00
}
2020-03-24 04:39:12 +00:00
render() {
2020-04-07 02:53:23 +01:00
const { account, intl, onClose } = this.props
2019-07-02 08:10:25 +01:00
2020-03-24 04:39:12 +00:00
const title = intl.formatMessage(messages.title, {
name: !!account ? account.get('acct') : '',
})
const message = intl.formatMessage(messages.muteMessage, {
name: !!account ? account.get('acct') : '',
})
2019-07-02 08:10:25 +01:00
return (
2020-03-24 04:39:12 +00:00
<ConfirmationModal
title={title}
message={message}
confirm={intl.formatMessage(messages.mute)}
onConfirm={this.handleClick}
2020-04-07 02:53:23 +01:00
onClose={onClose}
2020-03-24 04:39:12 +00:00
/>
)
2019-07-02 08:10:25 +01:00
}
}