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

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-02-24 23:25:55 +00:00
import { injectIntl, FormattedMessage } from 'react-intl'
import ModalLayout from './modal_layout'
import Button from '../button'
2019-07-02 08:10:25 +01:00
2020-02-24 23:25:55 +00:00
export default
@injectIntl
class ConfirmationModal extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
message: PropTypes.node.isRequired,
confirm: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
secondary: PropTypes.string,
onSecondary: PropTypes.func,
intl: PropTypes.object.isRequired,
onCancel: PropTypes.func,
2020-02-24 23:25:55 +00:00
}
2019-07-02 08:10:25 +01:00
componentDidMount() {
2020-02-24 23:25:55 +00:00
this.button.focus()
2019-07-02 08:10:25 +01:00
}
handleClick = () => {
2020-02-24 23:25:55 +00:00
this.props.onClose()
this.props.onConfirm()
2019-07-02 08:10:25 +01:00
}
handleSecondary = () => {
2020-02-24 23:25:55 +00:00
this.props.onClose()
this.props.onSecondary()
2019-07-02 08:10:25 +01:00
}
handleCancel = () => {
2020-02-24 23:25:55 +00:00
const {onClose, onCancel} = this.props
onClose()
if (onCancel) onCancel()
2019-07-02 08:10:25 +01:00
}
setRef = (c) => {
2020-02-24 23:25:55 +00:00
this.button = c
2019-07-02 08:10:25 +01:00
}
render () {
2020-02-24 23:25:55 +00:00
const { message, confirm, secondary } = this.props
2019-07-02 08:10:25 +01:00
return (
<div className='modal-root__modal confirmation-modal'>
<div className='confirmation-modal__container'>
{message}
</div>
<div className='confirmation-modal__action-bar'>
<Button onClick={this.handleCancel} className='confirmation-modal__cancel-button'>
<FormattedMessage id='confirmation_modal.cancel' defaultMessage='Cancel' />
</Button>
{secondary !== undefined && (
<Button text={secondary} onClick={this.handleSecondary} className='confirmation-modal__secondary-button' />
)}
<Button text={confirm} onClick={this.handleClick} ref={this.setRef} />
</div>
</div>
2020-02-24 23:25:55 +00:00
)
2019-07-02 08:10:25 +01:00
}
}