// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import $ from 'jquery'; import ReactDOM from 'react-dom'; import {Modal} from 'react-bootstrap'; import ModalStore from 'stores/modal_store.jsx'; import {deletePost} from 'actions/post_actions.jsx'; import Constants from 'utils/constants.jsx'; import {FormattedMessage} from 'react-intl'; var ActionTypes = Constants.ActionTypes; import React from 'react'; export default class DeletePostModal extends React.Component { constructor(props) { super(props); this.handleDelete = this.handleDelete.bind(this); this.handleToggle = this.handleToggle.bind(this); this.handleHide = this.handleHide.bind(this); this.state = { show: false, post: null, commentCount: 0, error: '' }; } componentDidMount() { ModalStore.addModalListener(ActionTypes.TOGGLE_DELETE_POST_MODAL, this.handleToggle); } componentWillUnmount() { ModalStore.removeModalListener(ActionTypes.TOGGLE_DELETE_POST_MODAL, this.handleToggle); } componentDidUpdate(prevProps, prevState) { if (this.state.show && !prevState.show) { setTimeout(() => { $(ReactDOM.findDOMNode(this.refs.deletePostBtn)).focus(); }, 0); } } handleDelete() { deletePost( this.state.post.channel_id, this.state.post, () => { this.handleHide(); }, (err) => { this.setState({error: err.message}); } ); } handleToggle(value, args) { this.setState({ show: value, post: args.post, commentCount: args.commentCount, error: '' }); } handleHide() { this.setState({show: false}); } render() { if (!this.state.post) { return null; } var error = null; if (this.state.error) { error =
; } var commentWarning = ''; if (this.state.commentCount > 0) { commentWarning = (