From f1668bad15d27e6e2b40e5079f0b878603b33684 Mon Sep 17 00:00:00 2001
From: Ryan Wang <R-Wang97@users.noreply.github.com>
Date: Tue, 25 Apr 2017 12:34:21 -0400
Subject: Add confirm dialog before leaving private channel (#6206)

---
 webapp/components/confirm_modal.jsx | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

(limited to 'webapp/components/confirm_modal.jsx')

diff --git a/webapp/components/confirm_modal.jsx b/webapp/components/confirm_modal.jsx
index 8034caf9d..05288e3ac 100644
--- a/webapp/components/confirm_modal.jsx
+++ b/webapp/components/confirm_modal.jsx
@@ -10,11 +10,21 @@ export default class ConfirmModal extends React.Component {
     constructor(props) {
         super(props);
 
-        this.handleConfirm = this.handleConfirm.bind(this);
+        this.handleKeypress = this.handleKeypress.bind(this);
     }
 
-    handleConfirm() {
-        this.props.onConfirm();
+    componentDidMount() {
+        document.addEventListener('keypress', this.handleKeypress);
+    }
+
+    componentWillUnmount() {
+        document.removeEventListener('keypress', this.handleKeypress);
+    }
+
+    handleKeypress(e) {
+        if (e.key === 'Enter' && this.props.show) {
+            this.props.onConfirm();
+        }
     }
 
     render() {
@@ -43,7 +53,7 @@ export default class ConfirmModal extends React.Component {
                     </button>
                     <button
                         type='button'
-                        className='btn btn-primary'
+                        className={this.props.confirmButtonClass}
                         onClick={this.props.onConfirm}
                     >
                         {this.props.confirmButton}
@@ -57,12 +67,14 @@ export default class ConfirmModal extends React.Component {
 ConfirmModal.defaultProps = {
     title: '',
     message: '',
+    confirmButtonClass: 'btn btn-primary',
     confirmButton: ''
 };
 ConfirmModal.propTypes = {
     show: React.PropTypes.bool.isRequired,
     title: React.PropTypes.node,
     message: React.PropTypes.node,
+    confirmButtonClass: React.PropTypes.string,
     confirmButton: React.PropTypes.node,
     onConfirm: React.PropTypes.func.isRequired,
     onCancel: React.PropTypes.func.isRequired
-- 
cgit v1.2.3-1-g7c22

