ConfirmationDialog.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. Copyright (C) 2017 Cloudbase Solutions SRL
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. import React, { Component, PropTypes } from 'react';
  15. import withStyles from 'isomorphic-style-loader/lib/withStyles';
  16. import s from './ConfirmationDialog.scss';
  17. import Modal from '../NewModal';
  18. class ConfirmationDialog extends Component {
  19. static propTypes = {
  20. message: PropTypes.string,
  21. onConfirm: PropTypes.func,
  22. onCancel: PropTypes.func,
  23. visible: PropTypes.bool
  24. }
  25. static defaultProps = {
  26. message: "Are you sure?",
  27. visible: false,
  28. place: "right"
  29. }
  30. onCancel() {
  31. if (this.props.onCancel) {
  32. this.props.onCancel()
  33. }
  34. }
  35. onConfirm() {
  36. if (this.props.onConfirm) {
  37. this.props.onConfirm()
  38. }
  39. }
  40. render() {
  41. if (this.props.visible) {
  42. return (
  43. <div className={s.root}>
  44. <Modal
  45. isOpen={this.props.visible}
  46. contentLabel="Confirmation"
  47. contentStyle={{ width: '250px', padding: '16px' }}
  48. onRequestClose={this.onCancel.bind(this)}
  49. >
  50. <p className={s.message}>{this.props.message}</p>
  51. <div className={s.buttons}>
  52. <button className={s.leftBtn + " gray"} onClick={(e) => this.onCancel(e)}>Cancel</button>
  53. <button className={s.rightBtn} onClick={(e) => this.onConfirm(e)}>Yes</button>
  54. </div>
  55. </Modal>
  56. </div>
  57. );
  58. } else {
  59. return null
  60. }
  61. }
  62. }
  63. export default withStyles(ConfirmationDialog, s);