Files
SCM-Manager/scm-ui/src/containers/Login.js

119 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-07-02 16:05:58 +02:00
//@flow
2018-07-05 16:48:56 +02:00
import React from "react";
import injectSheet from "react-jss";
import { login } from "../modules/login";
import { connect } from "react-redux";
2018-07-02 16:05:58 +02:00
2018-07-11 14:59:01 +02:00
import InputField from "../components/InputField";
import SubmitButton from "../components/SubmitButton";
import classNames from "classnames";
import Avatar from "../images/blib.jpg";
2018-07-02 16:05:58 +02:00
const styles = {
2018-07-11 14:59:01 +02:00
spacing: {
paddingTop: "5rem"
},
avatar: {
marginTop: "-70px",
paddingBottom: "20px"
},
avatarImage: {
border: "1px solid lightgray",
padding: "5px",
background: "#fff",
borderRadius: "50%",
width: "128px",
height: "128px"
2018-07-02 16:05:58 +02:00
},
2018-07-11 14:59:01 +02:00
avatarSpacing: {
marginTop: "5rem"
2018-07-02 16:05:58 +02:00
}
};
2018-07-10 16:52:23 +02:00
type Props = {
classes: any,
login: (username: string, password: string) => void
};
type State = {
username: string,
password: string
};
class Login extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = { username: "", password: "" };
}
2018-07-11 14:59:01 +02:00
handleUsernameChange = (value: string) => {
this.setState({ username: value });
};
2018-07-05 16:48:56 +02:00
2018-07-11 14:59:01 +02:00
handlePasswordChange = (value: string) => {
this.setState({ password: value });
};
2018-07-05 16:48:56 +02:00
2018-07-10 16:52:23 +02:00
handleSubmit(event: Event) {
2018-07-05 16:48:56 +02:00
event.preventDefault();
this.props.login(this.state.username, this.state.password);
}
2018-07-02 16:05:58 +02:00
render() {
const { classes } = this.props;
return (
2018-07-11 14:59:01 +02:00
<section className="hero is-fullheight">
<div className={classes.spacing}>
<div className="container has-text-centered">
<div className="column is-4 is-offset-4">
<h3 className="title">Login</h3>
<p className="subtitle">Please login to proceed.</p>
<div className={classNames("box", classes.avatarSpacing)}>
<figure className={classes.avatar}>
<img
className={classes.avatarImage}
src={Avatar}
alt="SCM-Manager"
/>
</figure>
<form onSubmit={this.handleSubmit.bind(this)}>
<InputField
placeholder="Your Username"
onChange={this.handleUsernameChange}
/>
<InputField
placeholder="Your Password"
type="password"
onChange={this.handlePasswordChange}
/>
<SubmitButton value="Login" fullWidth={true} />
</form>
</div>
</div>
</div>
2018-07-02 16:05:58 +02:00
</div>
2018-07-11 14:59:01 +02:00
</section>
2018-07-02 16:05:58 +02:00
);
}
}
2018-07-05 16:48:56 +02:00
const mapStateToProps = state => {
return {};
};
const mapDispatchToProps = dispatch => {
return {
login: (username: string, password: string) =>
dispatch(login(username, password))
};
};
const StyledLogin = injectSheet(styles)(
connect(
mapStateToProps,
mapDispatchToProps
)(Login)
);
export default StyledLogin;