import React, { Component } from "react"; import { getCarBrands } from "../../services/carBrand"; import { getCarModels } from "../../services/carModelService"; import { getCompanies } from "../../services/companyService"; import Input from "../component/Input"; import { addCar } from "../../services/carService"; import alertify from "alertifyjs"; import { Link } from "react-router-dom"; export default class CarAdd extends Component { state = { carKm: null, carInsuranceDate: null, carLicencePlate: null, carStatus: null, carActive: null, carIsCarForRent: null, carModelId: null, carBrandId: null, companyId: null, pendingApicall: false, //tek request atabilmek için ekledim. errors: {}, carBrands: [], carModels: [], companies: [], }; componentDidMount() { getCarBrands().then((response) => { this.setState({ carBrands: response.data.data, }); }); getCarModels().then((response) => { this.setState({ carModels: response.data.data, }); }); getCompanies().then((response) => { this.setState({ companies: response.data.data, }); }); } onChange = (event) => { const { name, value } = event.target; const errors = { ...this.state.errors }; //inputa kullanıcı herhangi bir giriş yapmaya başlayınca hata mesajının silinmesi için errors[name] = undefined; //inputa kullanıcı herhangi bir giriş yapmaya başlayınca hata mesajının silinmesi için this.setState({ [name]: value, errors, }); }; onClickSignUp = async (event) => { event.preventDefault(); const { carKm, carInsuranceDate, carLicencePlate, carStatus, carActive, carIsCarForRent, carBrandId, carModelId, companyId, } = this.state; const body = { carKm, carInsuranceDate, carLicencePlate, carStatus: true, carActive: true, carIsCarForRent, carModelId, carBrandId, companyId, }; this.setState({ pendingApicall: true }); try { const response = await addCar(body); } catch (error) { if (error.response.data.validationErrors) { this.setState({ errors: error.response.data.validationErrors }); console.log(error); } } this.setState({ pendingApicall: false }); }; render() { const { errors } = this.state; const { carKm, carInsuranceDate, carLicencePlate, carStatus, carActive, carIsCarForRent, carBrandId, carModelId, companyId, } = errors; return (

Araç Ekle

); } }