2017-02-28 21:32:23 +00:00
|
|
|
import React, {PureComponent} from 'react';
|
2017-03-03 01:44:07 +00:00
|
|
|
import autobind from 'autobind-decorator';
|
2016-07-22 22:27:04 +00:00
|
|
|
import Modal from '../base/Modal';
|
|
|
|
import ModalBody from '../base/ModalBody';
|
|
|
|
import ModalHeader from '../base/ModalHeader';
|
|
|
|
import ModalFooter from '../base/ModalFooter';
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
@autobind
|
2017-02-28 21:32:23 +00:00
|
|
|
class AlertModal extends PureComponent {
|
2017-03-03 01:44:07 +00:00
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
title: '',
|
|
|
|
message: '',
|
|
|
|
};
|
|
|
|
}
|
2016-11-29 20:55:31 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_setModalRef (m) {
|
|
|
|
this.modal = m;
|
|
|
|
}
|
2017-02-28 21:32:23 +00:00
|
|
|
|
2017-03-03 01:44:07 +00:00
|
|
|
_handleOk () {
|
2016-11-29 20:55:31 +00:00
|
|
|
this.hide();
|
|
|
|
this._okCallback();
|
|
|
|
};
|
|
|
|
|
|
|
|
hide () {
|
|
|
|
this.modal.hide();
|
|
|
|
}
|
2016-07-19 16:59:26 +00:00
|
|
|
|
2016-11-20 07:43:22 +00:00
|
|
|
show (options = {}) {
|
2016-08-15 17:04:36 +00:00
|
|
|
this.modal.show();
|
2016-11-20 07:43:22 +00:00
|
|
|
|
|
|
|
const {title, message} = options;
|
2016-11-07 20:24:38 +00:00
|
|
|
this.setState({title, message});
|
2016-11-29 20:55:31 +00:00
|
|
|
|
|
|
|
return new Promise(resolve => this._okCallback = resolve);
|
2016-07-19 16:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const {extraProps} = this.props;
|
2016-11-07 20:24:38 +00:00
|
|
|
const {message, title} = this.state;
|
2016-07-19 16:59:26 +00:00
|
|
|
|
|
|
|
return (
|
2017-02-28 21:32:23 +00:00
|
|
|
<Modal ref={this._setModalRef} closeOnKeyCodes={[13]} {...extraProps}>
|
2016-11-07 20:24:38 +00:00
|
|
|
<ModalHeader>{title || 'Uh Oh!'}</ModalHeader>
|
2016-07-19 16:59:26 +00:00
|
|
|
<ModalBody className="wide pad">
|
|
|
|
{message}
|
|
|
|
</ModalBody>
|
|
|
|
<ModalFooter>
|
2016-11-29 20:55:31 +00:00
|
|
|
<button className="btn" onClick={this._handleOk}>
|
2016-07-19 16:59:26 +00:00
|
|
|
Ok
|
|
|
|
</button>
|
|
|
|
</ModalFooter>
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AlertModal.propTypes = {};
|
|
|
|
|
|
|
|
export default AlertModal;
|