
import React,{Component} from 'react';
import axios from 'axios';
import {Link} from 'react-router-dom';
import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css'; // Import css

export default class AdminAddUser extends Component{
    constructor(props){
        super(props);
         this.state={assetsLoaded:false,fullname:'',mobile:'',username:'',password:'',city:''
         }
         this.handleChange = this.handleChange.bind(this)
      }

      componentDidMount(){
        
      }

      handleChange(event){
        this.setState({
          [event.target.name] : event.target.value
        })
      }

      handleFile(e){
        console.log(e.target.files[0]);
        this.setState({img:e.target.files[0]})
      }

    submitForm(event){event.preventDefault();
        var formData = new FormData();
        formData.append("fullname", this.state.fullname);
        formData.append("mobile", this.state.mobile);
        formData.append("city", this.state.city);
        formData.append("username", this.state.username);
        formData.append("password", this.state.password);
        
        axios.post('http://ftxsr.com:8081/addnewuser_api', {username:this.state.fullname,mobile:this.state.mobile,
        city:this.state.city,fullname:this.state.fullname,password:this.state.password})
            .then((res) => {
            console.log(res.data);
            //if(res.status==1){this.componentDidMount();}
        }).catch((err) => alert("File Upload Error"));    
    }

    render(){
        return (
            <div className="content-wrapper">
                <section className="content-header">
                    <h5>Add New User</h5>
                    <ol className="breadcrumb">
                        <li><Link to="/admin"><i className="fa fa-dashboard"></i> Home</Link></li>
                        <li className="active">User Add/Edit</li>
                    </ol>
                </section>
                <section className="content">
                <div className="row clearfix">
                    <div className="col-md-4">
                        <div className="panel panel-primary cardbg">
                            <div className="panel-body">
                                <form onSubmit={(e)=>this.submitForm(e)}>
                                    <input type="hidden" name='pat_id' value={this.state.pat_id}/>
                                    <div className='form-group'>
                                        <label>Full Name</label>
                                        <input type="text" onChange={this.handleChange} 
                                        className="form-control" value={this.state.fullname} required name='fullname'/>
                                    </div>
                                    <div className='form-group'>
                                        <label>Mobile</label>
                                        <input type="text" onChange={this.handleChange} 
                                        className="form-control" value={this.state.mobile} required name='mobile'/>
                                    </div>
                                    <div className='form-group'>
                                        <label>Username</label>
                                        <input type="text" onChange={this.handleChange} 
                                        className="form-control" value={this.state.username} required name='username'/>
                                    </div>
                                    <div className='form-group'>
                                        <label>Password</label>
                                        <input type="password" onChange={this.handleChange} 
                                        className="form-control" value={this.state.password} required name='password'/>
                                    </div>
                                    <div className='form-group'>
                                        <label>City</label>
                                        <input type="text" onChange={this.handleChange} 
                                        className="form-control" value={this.state.city} required name='city'/>
                                    </div>
                                    <button className='btn btn-primary' type='submit'>Add User</button>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                </section>
            </div>
        );
    }
}


