//@flow import React from "react"; import { translate } from "react-i18next"; import styled from "styled-components"; import { Image, ErrorNotification, InputField, SubmitButton, UnauthorizedError } from "@scm-manager/ui-components"; type Props = { error?: Error, loading: boolean, loginHandler: (username: string, password: string) => void, // context props t: string => string }; type State = { username: string, password: string }; const TopMarginBox = styled.div` margin-top: 5rem; `; const AvatarWrapper = styled.figure` margin-top: -70px; padding-bottom: 20px; `; const AvatarImage = styled(Image)` width: 128px; height: 128px; padding: 5px; background: #fff; border: 1px solid lightgray; border-radius: 50%; `; class LoginForm extends React.Component { constructor(props: Props) { super(props); this.state = { username: "", password: "" }; } handleSubmit = (event: Event) => { event.preventDefault(); if (this.isValid()) { this.props.loginHandler(this.state.username, this.state.password); } }; handleUsernameChange = (value: string) => { this.setState({ username: value }); }; handlePasswordChange = (value: string) => { this.setState({ password: value }); }; isValid() { return this.state.username && this.state.password; } areCredentialsInvalid() { const { t, error } = this.props; if (error instanceof UnauthorizedError) { return new Error(t("errorNotification.wrongLoginCredentials")); } else { return error; } } render() { const { loading, t } = this.props; return (

{t("login.title")}

{t("login.subtitle")}

); } } export default translate("commons")(LoginForm);