Replace refresh of token expired banner with hard login link

This commit is contained in:
Sebastian Sdorra
2020-08-27 10:51:21 +02:00
parent 5c804f23d7
commit 20d34a8491
4 changed files with 96 additions and 24 deletions

View File

@@ -21,16 +21,26 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import React from "react";
import { WithTranslation, withTranslation } from "react-i18next";
import React, { FC } from "react";
import { useTranslation, WithTranslation, withTranslation } from "react-i18next";
import { BackendError, ForbiddenError, UnauthorizedError } from "./errors";
import Notification from "./Notification";
import BackendErrorNotification from "./BackendErrorNotification";
import { useLocation } from "react-router-dom";
import { withContextPath } from "./urls";
type Props = WithTranslation & {
error?: Error;
};
const LoginLink: FC = () => {
const [t] = useTranslation("commons");
const location = useLocation();
const from = encodeURIComponent(location.pathname);
return <a href={withContextPath(`/login?from=${from}`)}>{t("errorNotification.loginLink")}</a>;
};
class ErrorNotification extends React.Component<Props> {
render() {
const { t, error } = this.props;
@@ -40,8 +50,7 @@ class ErrorNotification extends React.Component<Props> {
} else if (error instanceof UnauthorizedError) {
return (
<Notification type="danger">
<strong>{t("errorNotification.prefix")}:</strong> {t("errorNotification.timeout")}{" "}
<a href="javascript:window.location.reload(true)">{t("errorNotification.loginLink")}</a>
<strong>{t("errorNotification.prefix")}:</strong> {t("errorNotification.timeout")} <LoginLink />
</Notification>
);
} else if (error instanceof ForbiddenError) {