-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStreamDelete.js
58 lines (49 loc) · 1.34 KB
/
StreamDelete.js
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
import React from "react";
import { connect } from "react-redux";
import { Link } from "react-router-dom";
import Modal from "../Modal";
import history from "../../history";
import { fetchStream, deleteStream } from "../../actions";
class StreamDelete extends React.Component {
componentDidMount() {
this.props.fetchStream(this.props.match.params.id);
}
renderActions() {
const { id } = this.props.match.params;
return (
<React.Fragment>
<button
onClick={() => this.props.deleteStream(id)}
className="ui button negative"
>
Delete
</button>
<Link to="/" className="ui button">
Cancel
</Link>
</React.Fragment>
);
}
renderContent() {
if (!this.props.stream) {
return "Are you sure you want to delete this stream?";
}
return `Are you sure you want to delete the stream with title: ${this.props.stream.title}?`;
}
render() {
return (
<Modal
title="Delete Stream"
content={this.renderContent()}
actions={this.renderActions()}
onDismiss={() => history.push("/")}
/>
);
}
}
const matchStateToProps = (state, ownProps) => {
return { stream: state.streams[ownProps.match.params.id] };
};
export default connect(matchStateToProps, { fetchStream, deleteStream })(
StreamDelete
);