do not show login tips, if they could not fetched

This commit is contained in:
Sebastian Sdorra
2019-08-15 10:08:48 +02:00
parent 3823c033b9
commit 372e629dfc
4 changed files with 53 additions and 48 deletions

View File

@@ -33,15 +33,14 @@ const styles = {
}, },
"@media (max-width: 768px)": { "@media (max-width: 768px)": {
link: { link: {
width: "100%", width: "100%"
} }
} }
}; };
type Props = { type Props = {
type: "plugin" | "feature", type: "plugin" | "feature",
item?: InfoItem, item: InfoItem,
error?: Error,
// context props // context props
classes: any, classes: any,
@@ -51,27 +50,16 @@ type Props = {
class InfoBox extends React.Component<Props> { class InfoBox extends React.Component<Props> {
renderBody = () => { renderBody = () => {
const { item, error, t } = this.props; const { item, t } = this.props;
const bodyClasses = classNames("media-content", "content", this.props.classes.content); const bodyClasses = classNames("media-content", "content", this.props.classes.content);
if (error) {
return (
<div className={bodyClasses}>
<h4>{t("login.error")}</h4>
<ErrorNotification error={error}/>
</div>
);
}
const title = item ? item.title : t("login.loading"); const title = item ? item.title : t("login.loading");
const summary = item ? item.summary : t("login.loading"); const summary = item ? item.summary : t("login.loading");
return ( return (
<div className={bodyClasses}> <div className={bodyClasses}>
<h4> <h4>
<a href={this.createHref()}>{title}</a> <a href={item._links.self.href}>{title}</a>
</h4> </h4>
<p>{summary}</p> <p>{summary}</p>
</div> </div>
@@ -79,15 +67,11 @@ class InfoBox extends React.Component<Props> {
}; };
createHref = () => {
const { item } = this.props;
return item ? item._links.self.href : "#";
};
createLink = () => { createLink = () => {
const { classes } = this.props; const { item, classes } = this.props;
// eslint-disable-next-line jsx-a11y/anchor-has-content // eslint-disable-next-line jsx-a11y/anchor-has-content
return <a href={this.createHref()} className={classes.link} />; return <a href={item._links.self.href} className={classes.link}/>;
}; };
render() { render() {

View File

@@ -26,7 +26,7 @@ const styles = {
type Props = { type Props = {
error?: Error, error?: Error,
loading: boolean, loading: boolean,
login: (username: string, password: string) => void, loginHandler: (username: string, password: string) => void,
// context props // context props
t: string => string, t: string => string,
@@ -48,7 +48,7 @@ class LoginForm extends React.Component<Props, State> {
handleSubmit = (event: Event) => { handleSubmit = (event: Event) => {
event.preventDefault(); event.preventDefault();
if (this.isValid()) { if (this.isValid()) {
this.props.login( this.props.loginHandler(
this.state.username, this.state.username,
this.state.password this.state.password
); );

View File

@@ -2,15 +2,24 @@
import React from "react"; import React from "react";
import InfoBox from "./InfoBox"; import InfoBox from "./InfoBox";
import type { InfoItem } from "./InfoItem"; import type { InfoItem } from "./InfoItem";
import LoginForm from "./LoginForm";
import { Loading } from "@scm-manager/ui-components";
type Props = { type Props = {
loginInfoLink: string loginInfoLink?: string,
loading?: boolean,
error?: Error,
loginHandler: (username: string, password: string) => void,
};
type LoginInfoResponse = {
plugin?: InfoItem,
feature?: InfoItem
}; };
type State = { type State = {
plugin?: InfoItem, info?: LoginInfoResponse,
feature?: InfoItem, loading?: boolean,
error?: Error
}; };
class LoginInfo extends React.Component<Props, State> { class LoginInfo extends React.Component<Props, State> {
@@ -18,34 +27,53 @@ class LoginInfo extends React.Component<Props, State> {
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
this.state = { this.state = {
loading: !!props.loginInfoLink
}; };
} }
componentDidMount() { componentDidMount() {
const { loginInfoLink } = this.props; const { loginInfoLink } = this.props;
if (!loginInfoLink) {
return;
}
fetch(loginInfoLink) fetch(loginInfoLink)
.then(response => response.json()) .then(response => response.json())
.then(info => { .then(info => {
this.setState({ this.setState({
plugin: info.plugin, info,
feature: info.feature, loading: false
error: undefined
}); });
}) })
.catch(error => { .catch(() => {
this.setState({ this.setState({
error loading: false
}); });
}); });
} }
createInfoPanel = (info: LoginInfoResponse) => (
<div className="column is-7 is-offset-1 is-paddingless">
<InfoBox item={info.feature} type="feature" />
<InfoBox item={info.plugin} type="plugin" />
</div>
);
render() { render() {
const { plugin, feature, error } = this.state; const { info, loading } = this.state;
if (loading) {
return <Loading/>;
}
let infoPanel;
if (info) {
infoPanel = this.createInfoPanel(info);
}
return ( return (
<div className="column is-7 is-offset-1 is-paddingless"> <>
<InfoBox item={feature} type="feature" error={error} /> <LoginForm {...this.props} />
<InfoBox item={plugin} type="plugin" error={error} /> {infoPanel}
</div> </>
); );
} }

View File

@@ -9,7 +9,6 @@ import {
} from "../modules/auth"; } from "../modules/auth";
import { connect } from "react-redux"; import { connect } from "react-redux";
import { getLoginLink, getLoginInfoLink } from "../modules/indexResource"; import { getLoginLink, getLoginInfoLink } from "../modules/indexResource";
import LoginForm from "../components/LoginForm";
import LoginInfo from "../components/LoginInfo"; import LoginInfo from "../components/LoginInfo";
import classNames from "classnames"; import classNames from "classnames";
import injectSheet from "react-jss"; import injectSheet from "react-jss";
@@ -39,7 +38,7 @@ type Props = {
class Login extends React.Component<Props> { class Login extends React.Component<Props> {
login = (username: string, password: string) => { handleLogin = (username: string, password: string): void => {
const { link, login } = this.props; const { link, login } = this.props;
login(link, username, password); login(link, username, password);
}; };
@@ -50,24 +49,18 @@ class Login extends React.Component<Props> {
}; };
render() { render() {
const { authenticated, loginInfoLink, loading, error, classes } = this.props; const { authenticated, classes, ...restProps } = this.props;
if (authenticated) { if (authenticated) {
return this.renderRedirect(); return this.renderRedirect();
} }
let loginInfo;
if (loginInfoLink) {
loginInfo = <LoginInfo loginInfoLink={loginInfoLink}/>
}
return ( return (
<section className={classNames("hero", classes.section )}> <section className={classNames("hero", classes.section )}>
<div className="hero-body"> <div className="hero-body">
<div className="container"> <div className="container">
<div className="columns is-centered"> <div className="columns is-centered">
<LoginForm loading={loading} error={error} login={this.login}/> <LoginInfo loginHandler={this.handleLogin} {...restProps} />
{loginInfo}
</div> </div>
</div> </div>
</div> </div>