Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • schwifi
  • eckbalu-master-patch-41181
  • halof
  • our-team
  • 0.12.7 protected
  • 0.12.6 protected
  • 0.12.5 protected
  • 0.12.4 protected
  • 0.12.3 protected
  • 0.12.2 protected
  • 0.12.1 protected
  • 0.12.0 protected
  • 0.11.5 protected
  • 0.11.4 protected
  • 0.11.3 protected
  • 0.11.2 protected
  • 0.11.1 protected
  • 0.11.0 protected
  • 0.10.6 protected
  • 0.10.5 protected
  • 0.10.4 protected
  • 0.10.3 protected
  • 0.10.2 protected
  • 0.10.1 protected
25 results

README.md

Blame
  • AddNewsForm.js 2.12 KiB
    import React, { Component } from 'react';
    import { Modal, Button, Form, Input, TextArea, Icon } from 'semantic-ui-react';
    import { connect } from 'react-redux';
    
    import { postNews, writeNews, clearWrite } from '../../actions/news';
    
    class AddNewsForm extends Component {
      constructor(props) {
        super(props);
        this.state = {
          showModal: false,
        };
      }
    
      render() {
        const { title, text } = this.props.newNews;
        const author = this.props.user.id;
        return (
          <Modal
            open={this.state.showModal}
            trigger={
              <Button
                size='big'
                onClick={() => { this.setState({ showModal: true }); }}
              >Hír hozzáadása
              </Button>
            }
          >
            <Modal.Header>Új hír:</Modal.Header>
            <Modal.Content>
              <Form>
                <Form.Field
                  control={Input}
                  label='Title'
                  name='title'
                  onChange={e => this.props.writeNews(e)}
                  value={title}
                  placeholder='Title'
                />
                <Form.Field
                  control={TextArea}
                  label='Text'
                  name='text'
                  onChange={e => this.props.writeNews(e)}
                  value={text}
                  placeholder='Tell us what you want...'
                />
              </Form>
            </Modal.Content>
            <Modal.Actions>
              <Button
                inverted
                color='red'
                onClick={() => { this.setState({ showModal: false }); }}
              >
                <Icon name='remove' />
                Cancel
              </Button>
              <Button
                inverted
                color='green'
                onClick={() => {
                        this.props.postNews({ title, text, author });
                        this.setState({ showModal: false });
                        this.props.clearWrite();
                        }}
              >
                <Icon name='checkmark' /> Add
              </Button>
            </Modal.Actions>
          </Modal>
        );
      }
    }
    
    const mapStateToProps = ({ newNews, user }) => ({ newNews, user });
    
    export default connect(mapStateToProps, { postNews, writeNews, clearWrite })(AddNewsForm);