mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
do not show login tips, if they could not fetched
This commit is contained in:
@@ -33,15 +33,14 @@ const styles = {
|
||||
},
|
||||
"@media (max-width: 768px)": {
|
||||
link: {
|
||||
width: "100%",
|
||||
width: "100%"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
type Props = {
|
||||
type: "plugin" | "feature",
|
||||
item?: InfoItem,
|
||||
error?: Error,
|
||||
item: InfoItem,
|
||||
|
||||
// context props
|
||||
classes: any,
|
||||
@@ -51,27 +50,16 @@ type Props = {
|
||||
class InfoBox extends React.Component<Props> {
|
||||
|
||||
renderBody = () => {
|
||||
const { item, error, t } = this.props;
|
||||
const { item, t } = this.props;
|
||||
|
||||
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 summary = item ? item.summary : t("login.loading");
|
||||
|
||||
|
||||
return (
|
||||
<div className={bodyClasses}>
|
||||
<h4>
|
||||
<a href={this.createHref()}>{title}</a>
|
||||
<a href={item._links.self.href}>{title}</a>
|
||||
</h4>
|
||||
<p>{summary}</p>
|
||||
</div>
|
||||
@@ -79,15 +67,11 @@ class InfoBox extends React.Component<Props> {
|
||||
|
||||
};
|
||||
|
||||
createHref = () => {
|
||||
const { item } = this.props;
|
||||
return item ? item._links.self.href : "#";
|
||||
};
|
||||
|
||||
createLink = () => {
|
||||
const { classes } = this.props;
|
||||
const { item, classes } = this.props;
|
||||
// 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() {
|
||||
|
||||
@@ -26,7 +26,7 @@ const styles = {
|
||||
type Props = {
|
||||
error?: Error,
|
||||
loading: boolean,
|
||||
login: (username: string, password: string) => void,
|
||||
loginHandler: (username: string, password: string) => void,
|
||||
|
||||
// context props
|
||||
t: string => string,
|
||||
@@ -48,7 +48,7 @@ class LoginForm extends React.Component<Props, State> {
|
||||
handleSubmit = (event: Event) => {
|
||||
event.preventDefault();
|
||||
if (this.isValid()) {
|
||||
this.props.login(
|
||||
this.props.loginHandler(
|
||||
this.state.username,
|
||||
this.state.password
|
||||
);
|
||||
|
||||
@@ -2,15 +2,24 @@
|
||||
import React from "react";
|
||||
import InfoBox from "./InfoBox";
|
||||
import type { InfoItem } from "./InfoItem";
|
||||
import LoginForm from "./LoginForm";
|
||||
import { Loading } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
loginInfoLink: string
|
||||
loginInfoLink?: string,
|
||||
loading?: boolean,
|
||||
error?: Error,
|
||||
loginHandler: (username: string, password: string) => void,
|
||||
};
|
||||
|
||||
type LoginInfoResponse = {
|
||||
plugin?: InfoItem,
|
||||
feature?: InfoItem
|
||||
};
|
||||
|
||||
type State = {
|
||||
plugin?: InfoItem,
|
||||
feature?: InfoItem,
|
||||
error?: Error
|
||||
info?: LoginInfoResponse,
|
||||
loading?: boolean,
|
||||
};
|
||||
|
||||
class LoginInfo extends React.Component<Props, State> {
|
||||
@@ -18,35 +27,54 @@ class LoginInfo extends React.Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
loading: !!props.loginInfoLink
|
||||
};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { loginInfoLink } = this.props;
|
||||
if (!loginInfoLink) {
|
||||
return;
|
||||
}
|
||||
fetch(loginInfoLink)
|
||||
.then(response => response.json())
|
||||
.then(info => {
|
||||
this.setState({
|
||||
plugin: info.plugin,
|
||||
feature: info.feature,
|
||||
error: undefined
|
||||
info,
|
||||
loading: false
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
.catch(() => {
|
||||
this.setState({
|
||||
error
|
||||
loading: false
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const { plugin, feature, error } = this.state;
|
||||
return (
|
||||
createInfoPanel = (info: LoginInfoResponse) => (
|
||||
<div className="column is-7 is-offset-1 is-paddingless">
|
||||
<InfoBox item={feature} type="feature" error={error} />
|
||||
<InfoBox item={plugin} type="plugin" error={error} />
|
||||
<InfoBox item={info.feature} type="feature" />
|
||||
<InfoBox item={info.plugin} type="plugin" />
|
||||
</div>
|
||||
);
|
||||
|
||||
render() {
|
||||
const { info, loading } = this.state;
|
||||
if (loading) {
|
||||
return <Loading/>;
|
||||
}
|
||||
|
||||
let infoPanel;
|
||||
if (info) {
|
||||
infoPanel = this.createInfoPanel(info);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<LoginForm {...this.props} />
|
||||
{infoPanel}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
} from "../modules/auth";
|
||||
import { connect } from "react-redux";
|
||||
import { getLoginLink, getLoginInfoLink } from "../modules/indexResource";
|
||||
import LoginForm from "../components/LoginForm";
|
||||
import LoginInfo from "../components/LoginInfo";
|
||||
import classNames from "classnames";
|
||||
import injectSheet from "react-jss";
|
||||
@@ -39,7 +38,7 @@ type Props = {
|
||||
|
||||
class Login extends React.Component<Props> {
|
||||
|
||||
login = (username: string, password: string) => {
|
||||
handleLogin = (username: string, password: string): void => {
|
||||
const { link, login } = this.props;
|
||||
login(link, username, password);
|
||||
};
|
||||
@@ -50,24 +49,18 @@ class Login extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { authenticated, loginInfoLink, loading, error, classes } = this.props;
|
||||
const { authenticated, classes, ...restProps } = this.props;
|
||||
|
||||
if (authenticated) {
|
||||
return this.renderRedirect();
|
||||
}
|
||||
|
||||
let loginInfo;
|
||||
if (loginInfoLink) {
|
||||
loginInfo = <LoginInfo loginInfoLink={loginInfoLink}/>
|
||||
}
|
||||
|
||||
return (
|
||||
<section className={classNames("hero", classes.section )}>
|
||||
<div className="hero-body">
|
||||
<div className="container">
|
||||
<div className="columns is-centered">
|
||||
<LoginForm loading={loading} error={error} login={this.login}/>
|
||||
{loginInfo}
|
||||
<LoginInfo loginHandler={this.handleLogin} {...restProps} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user