diff --git a/client/src/Components/Forms/make_admin.jsx b/client/src/Components/Forms/make_admin.jsx new file mode 100644 index 0000000000000000000000000000000000000000..1249a35debe46529cc1453afab53836fd7a666b0 --- /dev/null +++ b/client/src/Components/Forms/make_admin.jsx @@ -0,0 +1,60 @@ +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/> + <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