<commit_before>import React from 'react';
import { Modal, ModalBody, Container, Row } from 'reactstrap';

export default props => {
  console.log(props);
  return (
    <Modal isOpen={true} toggle={props.hideModals}>
      <ModalBody>
        <Container>
          <Row>
            create new product
          </Row>
        </Container>
      </ModalBody>
    </Modal>
  );
};<commit_msg>create new product form loads options from server<commit_after>import React from 'react';
import {
  Modal, ModalBody, Container, Row, Form, FormGroup,
  Label, Input, Button, Col, InputGroupAddon, InputGroup,
} from 'reactstrap';

import api from '../../api';

export default class NewProductAdmin extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      categories: [],
      subCategories: [],
      suppliers: []
    };
  }

  componentDidMount() {
    this.loadSuppliers();
    this.loadCategories();
    this.loadSubCategories(1);
  }

  loadSuppliers = () => {
    api.get('suppliers')
      .then((response) => {
        if (response) {
          this.setState({
            suppliers: response.data.suppliers.items.map(item => {
              return item.supplier
            })
          });
        }
      })
      .catch(response => {
        console.log('error ', response);
      });
  };

  loadCategories = () => {
    api.get('categories')
      .then(response => {
        if (response) {
          this.setState({
            categories: response.data.categories.items.map(item => {
              return item.category
            })
          });
        }
      })
      .catch(response => {
        console.log('error ', response);
      });
  };

  loadSubCategories = (subCategoryId) => {
    api.get('categories?mainCategory=' + subCategoryId)
      .then(response => {
        if (response) {
          this.setState({
            subCategories: response.data.categories.items.map(item => {
              return item.category
            })
          });
        }
      })
      .catch(response => {
        console.log('error ', response);
      });
  };

  onSubmit = (event) => {
    event.preventDefault();
    api.post('products', new FormData(event.target))
      .then(data => {
        console.log('success ', data);
      })
      .catch(response => {
        console.log('error ', response);
      });
  };

  onCategoryChosen = (event) => {
    this.loadSubCategories(event.target.value);
  };

  renderCategoryOptions = () => {
    return this.state.categories.map(category => {
      return (
        <option key={category.id} value={category.id}>{category.name}</option>
      );
    });
  };

  renderSubCategoryOptions = () => {
    return this.state.subCategories.map(category => {
      return (
        <option key={category.id} value={category.id}>{category.name}</option>
      );
    });
  };

  renderSupplierOptions = () => {
    return this.state.suppliers.map(supplier => {
      return (
        <option key={supplier.id} value={supplier.id}>{supplier.name}</option>
      );
    });
  };

  render() {
    return (
      <Modal isOpen={true} toggle={this.props.hideModals}>
        <ModalBody>
          <Container>
            <Row>
              <Form onSubmit={this.onSubmit}>

                <FormGroup row>
                  <Label for="productName" sm={4}>Název</Label>
                  <Col sm={8}>
                    <Input required type="text" name="productName" id="productName"/>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productPrice" sm={4}>Cena</Label>
                  <Col sm={8}>
                    <InputGroup>
                      <Input required type="number" name="productPrice" id="productPrice"/>
                      <InputGroupAddon>Kč</InputGroupAddon>
                    </InputGroup>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productPriceAfterDiscount" sm={4}>Cena po slevě</Label>
                  <Col sm={8}>
                    <InputGroup>
                      <Input type="number" name="productPriceAfterDiscount" id="productPriceAfterDiscount"/>
                      <InputGroupAddon>Kč</InputGroupAddon>
                    </InputGroup>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productQuantity" sm={4}>Skladem</Label>
                  <Col sm={8}>
                    <InputGroup>
                      <Input type="number" name="productQuantity" id="productQuantity" defaultValue="0"/>
                      <InputGroupAddon>Ks</InputGroupAddon>
                    </InputGroup>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productCategory" sm={4}>Kategorie</Label>
                  <Col sm={8}>
                    <Input onChange={this.onCategoryChosen} required type="select" name="productCategory"
                           id="productCategory">
                      {this.renderCategoryOptions()}
                    </Input>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productSubCategory" sm={4}>Podkategorie</Label>
                  <Col sm={8}>
                    <Input disabled={this.state.subCategories.length === 0}
                           required type="select" name="productSubCategory" id="productSubCategory">
                      {this.renderSubCategoryOptions()}
                    </Input>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productSupplier" sm={4}>Dodavatel</Label>
                  <Col sm={8}>
                    <Input type="select" name="productSupplier" id="productSupplier">
                      {this.renderSupplierOptions()}
                    </Input>
                  </Col>
                </FormGroup>

                <FormGroup row>
                  <Label for="productDesc" sm={4}>Popis</Label>
                  <Col sm={8}>
                    <Input type="textarea" name="productDesc" id="productDesc"/>
                  </Col>
                </FormGroup>

                <FormGroup check row>
                  <Col sm={{size: 10, offset: 2}}>
                    <Button type="submit">Vytvořit</Button>
                  </Col>
                </FormGroup>
              </Form>
            </Row>
          </Container>
        </ModalBody>
      </Modal>
    );
  }
}
{'fraction_non_alphanumeric': 0.13652857574841246, 'fraction_numerical': 0.003326277592984578, 'mean_word_length': 1.50948406676783, 'pattern_counts': {'":': 0, '<': 104, '<?xml version=': 0, '>': 127, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7479975', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1716, 'n_words': 308}