Skip to content
Snippets Groups Projects
Commit 27955d7a authored by Ashwanth K's avatar Ashwanth K
Browse files

Upload New File

parent 3db13e92
No related branches found
No related tags found
No related merge requests found
import React, { Component } from 'react'
import './forms.css'
import axios from 'axios';
export default class Make_adm extends Component{
constructor(props){
super(props);
this.state = {
user_id: '',
name : ''
}
this.handleChange=this.handleChange.bind(this);
this.admin=this.admin.bind(this);
}
handleChange(event){
this.setState({
[event.target.name] : event.target.value
});
}
admin(event){
axios.get('http://localhost:5000/user/'+this.state.user_id)
.then(response => {
if(response.data._id != null && response.data.name===this.state.name){
const admin = {
admin_id : response.data._id,
name : response.data.name,
email: response.data.email,
password: response.data.password
}
axios.post('http://localhost:5000/admin/add',admin)
.then(window.alert(this.state.user_id+' is an admin now!'))
.catch(function(error) {
window.alert("error" + error);
});
}
else alert(this.state.user_id+ ' is not an existing user')
})
event.preventDefault();
}
render(){
return(
<div>
<h3 style={{fontFamily:"Roboto",marginLeft:"20px"}}>
<b>MAKE USER AN ADMIN</b>
</h3>
<form>
<ul style={{listStyle:"none"}}>
<li><div>
<input type="text" placeholder="User_id" name="user_id" onChange={this.handleChange} required/> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" placeholder="User_Name" name="name" onChange={this.handleChange} required/>
</div></li>
<li><div><input type="submit" value="Make Admin" style={{marginBottom:"20px",width:'150px'}} onClick={this.admin}/></div></li>
</ul>
</form>
</div>
)
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment