Advertisement
Guest User

Untitled

a guest
Jan 16th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react'
  2. import { Form } from 'semantic-ui-react'
  3. import { loadOffice, loadAllUsers } from '../AC'
  4. import {connect} from 'react-redux'
  5. import {mapToArr} from "../helpers";
  6.  
  7. class FormEditOffice extends Component {
  8.     componentDidMount() {
  9.         const {loadOffice, id, loadAllUsers} = this.props;
  10.         loadAllUsers();
  11.         loadOffice(id);
  12.     }
  13.  
  14.     handleChange = (e, { name, value }) => {
  15.         this.setState({ [name]: value });
  16.     };
  17.  
  18.     handleSubmit = (ev) => {
  19.         ev.preventDefault();
  20.         console.log('STATE', this.state);
  21.     };
  22.  
  23.     state = {
  24.         responsibles: []
  25.     };
  26.  
  27.     render() {
  28.         const {office, users} = this.props;
  29.         if (!office || !users) return null;
  30.  
  31.         const {responsibles} = this.state;
  32.         const userOptions = mapToArr(users).map((user) => {
  33.             return {
  34.                 key: user.id,
  35.                 value: user.id,
  36.                 text: user.username
  37.             }
  38.         });
  39.  
  40.         return (
  41.             <Form onSubmit={this.handleSubmit}>
  42.                 <Form.Group widths='equal'>
  43.                     <Form.Input fluid label='Название' placeholder={office.name} readOnly/>
  44.                 </Form.Group>
  45.                 <Form.Group widths='equal'>
  46.                     <Form.Dropdown label='Ответственные'
  47.                                    name='responsibles'
  48.                                    value={responsibles}
  49.                                    fluid multiple search selection
  50.                                    options={userOptions}
  51.                                    onChange={this.handleChange}/>
  52.                 </Form.Group>
  53.                 <Form.Button content='Сохранить' />
  54.             </Form>
  55.         )
  56.     }
  57. }
  58.  
  59. export default connect((state, ownProps) => {
  60.     return {
  61.         office: state.offices.entities.get(ownProps.id),
  62.         users: state.users.entities,
  63.     }
  64. }, {loadOffice, loadAllUsers})(FormEditOffice)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement