File size: 1,768 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Notice from 'calypso/components/notice';
import NoticeAction from 'calypso/components/notice/notice-action';
import {
	bumpStat,
	composeAnalytics,
	recordTracksEvent,
	withAnalytics,
} from 'calypso/state/analytics/actions';
import { deleteComment } from 'calypso/state/comments/actions';
import { getSiteComment } from 'calypso/state/comments/selectors';

const CommentDeleteWarning = ( { isLoading, destroyComment, translate } ) =>
	! isLoading && (
		<Notice
			status="is-warning"
			showDismiss={ false }
			text={ translate( 'Delete this comment permanently?' ) }
		>
			<NoticeAction icon="trash" onClick={ destroyComment }>
				Delete Permanently
			</NoticeAction>
		</Notice>
	);

CommentDeleteWarning.propTypes = {
	siteId: PropTypes.number,
	postId: PropTypes.number,
	commentId: PropTypes.number.isRequired,
	destroyComment: PropTypes.func.isRequired,
	redirectToPostView: PropTypes.func.isRequired,
	translate: PropTypes.func.isRequired,
};

const mapStateToProps = ( state, { siteId, commentId } ) => {
	const comment = getSiteComment( state, siteId, commentId );

	return {
		isLoading: typeof comment === 'undefined',
	};
};

const mapDispatchToProps = ( dispatch, { siteId, postId, commentId, redirectToPostView } ) => ( {
	destroyComment: () => {
		dispatch(
			withAnalytics(
				composeAnalytics(
					recordTracksEvent( 'calypso_comment_management_delete' ),
					bumpStat( 'calypso_comment_management', 'comment_deleted' )
				),
				deleteComment( siteId, postId, commentId )
			)
		);

		redirectToPostView();
	},
} );

export default connect( mapStateToProps, mapDispatchToProps )( localize( CommentDeleteWarning ) );