Skip to content
Snippets Groups Projects
Commit 631eac24 authored by Chif Gergő's avatar Chif Gergő
Browse files

Make the modal disappear after confirm and when click close. Style the code

parent ffc62775
No related branches found
No related tags found
No related merge requests found
...@@ -5,11 +5,26 @@ import { connect } from 'react-redux'; ...@@ -5,11 +5,26 @@ import { connect } from 'react-redux';
import { postNews, writeNews, clearWrite } from '../../actions/news'; import { postNews, writeNews, clearWrite } from '../../actions/news';
class AddNewsForm extends Component { class AddNewsForm extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
};
}
render() { render() {
const { title, text } = this.props.newNews; const { title, text } = this.props.newNews;
const author = this.props.user.id; const author = this.props.user.id;
return ( return (
<Modal trigger={<Button >Add news</Button>}> <Modal
open={this.state.showModal}
trigger={
<Button
onClick={() => { this.setState({ showModal: true }); }}
>Add news
</Button>
}
>
<Modal.Header>Új hír:</Modal.Header> <Modal.Header>Új hír:</Modal.Header>
<Modal.Content> <Modal.Content>
<Form> <Form>
...@@ -32,14 +47,20 @@ class AddNewsForm extends Component { ...@@ -32,14 +47,20 @@ class AddNewsForm extends Component {
</Form> </Form>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button inverted color='red' > <Button
<Icon name='remove' /> Cancel inverted
color='red'
onClick={() => { this.setState({ showModal: false }); }}
>
<Icon name='remove' />
Cancel
</Button> </Button>
<Button <Button
inverted inverted
color='green' color='green'
onClick={() => { onClick={() => {
this.props.postNews({ title, text, author }); this.props.postNews({ title, text, author });
this.setState({ showModal: false });
this.props.clearWrite(); this.props.clearWrite();
}} }}
> >
......
...@@ -5,11 +5,24 @@ import { connect } from 'react-redux'; ...@@ -5,11 +5,24 @@ import { connect } from 'react-redux';
import { writeNews, editNews, clearWrite } from '../../actions/news'; import { writeNews, editNews, clearWrite } from '../../actions/news';
class EditNewsForm extends Component { class EditNewsForm extends Component {
constructor(props) {
super(props);
this.state = {
showModal: false,
};
}
render() { render() {
const { id, title, text } = this.props.selectedNews; const { id, title, text } = this.props.selectedNews;
const editedBy = this.props.user.id; const editedBy = this.props.user.id;
return ( return (
<Modal onOpen={this.props.onClick} trigger={<Button size='mini' >Edit</Button>}> <Modal
open={this.state.showModal}
onOpen={this.props.onClick}
trigger={
<Button onClick={() => { this.setState({ showModal: true }); }} size='mini' >Edit</Button>
}
>
<Modal.Header>Szerkesztés:</Modal.Header> <Modal.Header>Szerkesztés:</Modal.Header>
<Modal.Content> <Modal.Content>
<Form> <Form>
...@@ -32,7 +45,11 @@ class EditNewsForm extends Component { ...@@ -32,7 +45,11 @@ class EditNewsForm extends Component {
</Form> </Form>
</Modal.Content> </Modal.Content>
<Modal.Actions> <Modal.Actions>
<Button inverted color='red' > <Button
inverted
color='red'
onClick={() => { this.setState({ showModal: false }); }}
>
<Icon name='remove' /> Cancel <Icon name='remove' /> Cancel
</Button> </Button>
<Button <Button
...@@ -42,6 +59,7 @@ class EditNewsForm extends Component { ...@@ -42,6 +59,7 @@ class EditNewsForm extends Component {
this.props.editNews({ this.props.editNews({
id, title, text, editedBy, id, title, text, editedBy,
}); });
this.setState({ showModal: false });
this.props.clearWrite(); this.props.clearWrite();
}} }}
> >
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment