import axios from "axios"; import React, { Component } from "react"; import { addUser } from "../../services/userService"; import Input from "../component/Input"; import { getUserRole } from "../../services/userRoleService"; import { getCompanies } from "../../services/companyService"; export default class UserAdd extends Component { state = { userFirstName: "", userLastName: "", userEmail: "", userPassword: null, companyId:null, userRoleId: null, pendingApicall: false, //tek request atabilmek için ekledim. errors: {}, userRoles: [], companies:[] }; componentDidMount() { getUserRole().then((response) => { this.setState({ userRoles: 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 { userFirstName, userLastName, userPassword, userEmail, userRoleId,companyId } = this.state; const body = { userFirstName, userLastName, userEmail, userPassword, userRoleId, companyId }; this.setState({ pendingApicall: true }); try { const response = await addUser(body); } catch (error) { if (error.response.data.validationErrors) { this.setState({ errors: error.response.data.validationErrors }); } } this.setState({ pendingApicall: false }); }; render() { const { errors } = this.state; const { userFirstName, userLastName, userPassword, userEmail, userRoleId } = errors; return (

Kullanıcı Ekle

); } }