Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class AdvertAdd extends Component {
  2.     constructor(props) {
  3.         super(props);
  4.  
  5.         this.state = {
  6.             carProducerValue: '',
  7.             carModelValue: '',
  8.             fuelTypeValue: '',
  9.             shortDescriptionValue: '',
  10.             descriptionValue: '',
  11.             equipmentValue: [],
  12.             phoneNumberValue: '',
  13.             yearProductionValue: ''
  14.         }
  15.     }
  16.  
  17.  
  18.  
  19.    
  20.    
  21.  
  22.     onClickSubmit() {
  23.        
  24.         this.sendAdvert();
  25.     }
  26.     async sendAdvert() {
  27.         const ob = {
  28.             ShortDescription: this.state.shortDescriptionValue,
  29.             Description: this.state.descriptionValue,
  30.             PhoneNumber: this.state.phoneNumberValue,
  31.             Equipment: this.state.equipmentValue,
  32.             CarProducer: this.state.carProducerValue,
  33.             CarModel: this.state.carModelValue,
  34.             Fuel: this.state.fuelTypeValue,
  35.             Year: this.state.yearProductionValue
  36.  
  37.         };
  38.         console.log(ob);
  39.         /*   await fetch("https://localhost:44394/api/CarOffer", {
  40.                    method: "post",
  41.                    headers: {
  42.                        "Content-type": "application/json; charset=UTF-8"
  43.                    },
  44.                    body: JSON.stringify(ob)
  45.                })
  46.                .then(res => res.json())
  47.                .then(res => {
  48.                  
  49.                    console.log(res);
  50.                })*/
  51.  
  52.     }
  53.  
  54.     onChangeEquipment(state,e) {
  55.  
  56.         if (e.target.checked == true) {
  57.  
  58.             state.equipmentValue = state.equipmentValue.filter(name => !name.includes(e.target.id));
  59.             state.equipmentValue.push(e.target.id);
  60.         }
  61.         else
  62.             state.equipmentValue = state.equipmentValue.filter(name => !name.includes(e.target.id));
  63.  
  64.     }
  65.  
  66.     //to przekazuje
  67.     onChangeProducer = (carProducerValue) => {
  68.         this.state.carProducerValue = carProducerValue;
  69.        
  70.     }
  71.     async componentDidMount() {
  72.        
  73.  
  74.     }
  75.     shouldComponentUpdate(nextProps, nextState) {
  76.  
  77.       //  console.log( nextProps.carModelValue +" "+ this.state.carModelValue )
  78.         return  nextProps.carModelValue != this.state.carModelValue;
  79.         return false;
  80.     }
  81.     onChangeCarModel = (carModelValue) => {
  82.         this.setState({
  83.             carModelValue
  84.         })
  85.       //  this.state.carModelValue = carModelValue;
  86.     }
  87.     onChangeFuelType = (fuelTypeValue) => {
  88.         this.setState({
  89.             fuelTypeValue
  90.         })
  91.     }
  92.     onChangeShortDescription = (shortDescriptionValue) => {
  93.         this.setState({
  94.             shortDescriptionValue
  95.         })
  96.     }
  97.     onChangePhoneNumber = (phoneNumberValue ) => {
  98.         this.setState({
  99.             phoneNumberValue
  100.         })
  101.     }
  102.     onChangeEquipment = (equipmentValue ) => {
  103.         this.setState({
  104.             equipmentValue
  105.         })
  106.     }
  107.     onChangeYearProduction = (yearProductionValue) =>{
  108.         console.log(111+yearProductionValue)
  109.         this.setState({
  110.             yearProductionValue
  111.         })
  112.     }
  113.     render() {
  114.         let optionItems;
  115.         if (this.props.carModel.length > 0) {
  116.             optionItems = this.props.carModel.map((x) =>
  117.                 <option key={x.idString} value={x.idString}>{x.modelName}</option>
  118.             );
  119.         }
  120.         return (
  121.             <div>
  122.                 carProducentAd
  123.                 <div>
  124.                     <MainInformationContainer
  125.                
  126.                         onChangeProducer={this.onChangeProducer}
  127.                         onChangeCarModel={this.onChangeCarModel}
  128.                         onChangeFuelType={this.onChangeFuelType}
  129.                         onChangeShortDescription={this.onChangeShortDescription}
  130.                         onChangePhoneNumber={this.onChangePhoneNumber}
  131.                         onChangeYearProduction={this.onChangeYearProduction}
  132.                         state={this.state}
  133.                     />
  134.                     <EquipmentContainer
  135.                         state={this.state}
  136.                         onChangeEquipment={this.onChangeEquipment}
  137.                     />
  138.                     <div>
  139.                         Opis:
  140.                         <div>
  141.                             <textarea id="description" onChange={x => this.state.descriptionValue = x.target.value} maxLength="4096" ></textarea>
  142.                         </div>
  143.                     </div>
  144.  
  145.                     <input type="button" value="wyślij" onClick={this.onClickSubmit.bind(this)} />
  146.                 </div>
  147.             </div>
  148.         )
  149.     }
  150.  
  151. }
  152. export default AdvertAdd;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement