import React from "react"; import { connect } from "react-redux"; import { AppState } from "reducers"; import { Keys } from "@blueprintjs/core"; import { showRunActionConfirmModal, cancelRunActionConfirmModal, acceptRunActionConfirmModal, } from "actions/pluginActionActions"; import DialogComponent from "components/ads/DialogComponent"; import styled from "styled-components"; import Button, { Category, Size } from "components/ads/Button"; import { createMessage, QUERY_CONFIRMATION_MODAL_MESSAGE, } from "constants/messages"; type Props = { isModalOpen: boolean; dispatch: any; }; const ModalBody = styled.div` padding-bottom: 20px; `; const ModalFooter = styled.div` display: flex; justify-content: flex-end; button { margin-left: 12px; } `; class ConfirmRunModal extends React.Component { addEventListener = () => { document.addEventListener("keydown", this.onKeyUp); }; removeEventListener = () => { document.removeEventListener("keydown", this.onKeyUp); }; onKeyUp = (event: KeyboardEvent) => { if (event.keyCode === Keys.ENTER) { this.onConfirm(); } }; onConfirm = () => { const { dispatch } = this.props; dispatch(acceptRunActionConfirmModal()); this.handleClose(); }; handleClose = () => { const { dispatch } = this.props; dispatch(showRunActionConfirmModal(false)); dispatch(cancelRunActionConfirmModal()); }; componentDidUpdate() { const { isModalOpen } = this.props; if (isModalOpen) { this.addEventListener(); } else { this.removeEventListener(); } } render() { const { dispatch, isModalOpen } = this.props; return ( {createMessage(QUERY_CONFIRMATION_MODAL_MESSAGE)}