import React from 'react'; import { Paper, Dialog, Card, CardActions, CardHeader, CardMedia, CardTitle, CardText, TextField, FlatButton, Checkbox, RaisedButton, GridList, GridTile, Divider } from 'material-ui'; import {observer, inject} from 'mobx-react'; import LoadingDialog from '../LoadingDialog/index'; import {LINKS} from "../../routes"; @inject('appstate') @observer export default class ChangePassword extends React.Component { constructor(props) { super(props); this.props = props; this.state = { password : '', error_retype : '', retype : '', loading : false, tokenData : { email : "" }, status : 0, openDialog : false }; this.defaultState = Object.assign({}, this.state); this.authStore = props.appstate.auth; this.http = props.appstate.http; } handleTextFieldChange = (event, name) => { this.setState({ [name]: event.target.value }); }; handleDialogOpen = (title,message)=>{ this.setState({ dialogTitle : title, dialogMessage : message, openDialog : true }) } acceptInvite() { const {state} = this; if(state.username != '' && state.password != '' && state.retype != ''){ this.setState({loading : true}) let contactData = { password : state.password, id : state.tokenData.id, } this.handleDialogOpen('Success','Change Password Success'); this.http.post('authentication/reset_password',contactData).then(res=>{ this.setState({loading : false,status : 1}); this.handleDialogOpen('Success','Success change password'); }).catch(err=>{ this.setState({loading : false,status : 0}); this.handleDialogOpen('Error','Something went wrong'); }) // this.props.appstate.http.post('authentication/accept_invite_admin', contactData).then(() => { // }) } else{ this.handleDialogOpen('Error','Please fill all form!'); } } componentDidMount() { this.query = this .props .location .search .substr(1) .split('&') .reduce((q, value) => { const [k, v] = value.split('='); q[k] = v; return q; }, {}); if(this.query.token) { this.setState({ tokenData: JSON.parse(atob(this.query.token.split('.')[1])) }); } } handleRetype = (event)=>{ let password = this.state.password; if(password === event.target.value){ this.setState({ error_retype : '' }) } else{ this.setState({ error_retype : 'Password and retype password is not same' }) } this.setState({ retype : event.target.value }) }; closeDialog = ()=>{ if(this.state.status){ this.props.history.push(LINKS.LOGIN); } else{ this.setState({ openDialog : false }) } } render() { const action = [ this.closeDialog()} style={{marginRight: 10}} /> ]; return (

5 Roti dan 2 Ikan

Marketplace

Confirm Password

}>

Email

Password

this.handleTextFieldChange(event, 'password')} />

Re-Type Password

this.acceptInvite()}/>
this.setState({openDialog : false})} > {this.state.dialogMessage}
) } }