frontend/smart-hut/src/views/Forgot-pass-reset.js

112 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-03-23 20:24:17 +00:00
import React, { Component } from "react";
import {
Button,
Form,
Grid,
Header,
Image,
Icon,
Message,
} from "semantic-ui-react";
2020-03-19 10:52:13 +00:00
import { Redirect } from "react-router-dom";
import { Forms } from "../remote";
2020-03-05 10:03:44 +00:00
2020-03-23 20:24:17 +00:00
export default class ChangePass extends Component {
constructor(props) {
super(props);
this.state = {
password: "",
error: {
state: false,
message: "",
},
2020-03-26 07:34:21 +00:00
success: false,
2020-03-23 20:24:17 +00:00
};
this.handleChangePassword = this.handleChangePassword.bind(this);
}
2020-03-05 10:03:44 +00:00
2020-03-23 20:24:17 +00:00
onChangeHandler = (event) => {
let nam = event.target.name;
let val = event.target.value;
this.setState({ [nam]: val });
};
2020-03-26 07:34:21 +00:00
handleChangePassword = (e) => {
if (this.state.confirmPassword !== this.state.password) {
2020-03-23 20:24:17 +00:00
this.setState({
error: {
state: true,
message: "Passwords do not match.",
},
});
2020-03-05 10:03:44 +00:00
}
Forms.submitResetPassword(this.props.query.token, this.state.password)
.then(() => this.setState({ success: true }))
.catch((err) => this.setState({ error:
{ state: true, message: err.messages.join(' - ') }}));
2020-03-23 20:24:17 +00:00
};
2020-03-05 10:03:44 +00:00
2020-03-23 20:24:17 +00:00
render() {
2020-03-26 07:34:21 +00:00
if (this.state.success) {
return <Redirect to="/login" />;
}
2020-03-23 20:24:17 +00:00
return (
<React.Fragment>
<Button circular style={{ margin: "2em" }} href="/">
<Icon name="arrow alternate circle left" />
Go Home{" "}
</Button>
<Grid
textAlign="center"
style={{ height: "70vh" }}
verticalAlign="middle"
>
<Grid.Column style={{ maxWidth: 450 }}>
<Header as="h2" color="blue" textAlign="center">
<Image src="img/logo.png" /> Reset Password
</Header>
<Form
size="large"
style={{ marginTop: "2em" }}
error={this.state.error.state}
2020-03-05 10:03:44 +00:00
>
2020-03-23 20:24:17 +00:00
<Message
error
header="Change Password Error"
content={this.state.error.message}
/>
<Form.Input
icon="address card outline"
iconPosition="left"
placeholder="Reset your password"
name="password"
type="password"
onChange={this.onChangeHandler}
required
/>
<Form.Input
icon="address card outline"
iconPosition="left"
placeholder="Confirm Password"
2020-03-26 07:34:21 +00:00
name="confirmPassword"
2020-03-23 20:24:17 +00:00
type="password"
2020-03-26 07:34:21 +00:00
onChange={this.onChangeHandler}
2020-03-23 20:24:17 +00:00
required
/>
<Button
color="blue"
fluid
size="large"
onClick={this.handleChangePassword}
>
Confirm password
</Button>
</Form>
</Grid.Column>
</Grid>
</React.Fragment>
);
}
}