From 8d4d718f7d83b23d5ed25f9b34cfdbfb143f3a7d Mon Sep 17 00:00:00 2001 From: John Mitchell Date: Fri, 17 Jan 2020 13:40:55 -0500 Subject: [PATCH] add redirect to login on 401 --- .../components/ContentError/ContentError.jsx | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/awx/ui_next/src/components/ContentError/ContentError.jsx b/awx/ui_next/src/components/ContentError/ContentError.jsx index eda9df08fb..30fa451124 100644 --- a/awx/ui_next/src/components/ContentError/ContentError.jsx +++ b/awx/ui_next/src/components/ContentError/ContentError.jsx @@ -1,6 +1,6 @@ -import React from 'react'; +import React, { Fragment } from 'react'; import styled from 'styled-components'; -import { Link } from 'react-router-dom'; +import { Link, Redirect } from 'react-router-dom'; import { bool, instanceOf } from 'prop-types'; import { t } from '@lingui/macro'; import { withI18n } from '@lingui/react'; @@ -33,22 +33,31 @@ function ContentError({ error, children, isNotFound, i18n }) { } const is404 = isNotFound || (error && error.response && error.response.status === 404); + const is401 = error && error.response && error.response.status === 401; return ( - - - - {is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)} - - - {is404 - ? i18n._(t`The page you requested could not be found.`) - : i18n._( - t`There was an error loading this content. Please reload the page.` - )}{' '} - {children || {i18n._(t`Back to Dashboard.`)}} - - {error && } - + + {is401 ? ( + + ) : ( + + + + {is404 ? i18n._(t`Not Found`) : i18n._(t`Something went wrong...`)} + + + {is404 + ? i18n._(t`The page you requested could not be found.`) + : i18n._( + t`There was an error loading this content. Please reload the page.` + )}{' '} + {children || ( + {i18n._(t`Back to Dashboard.`)} + )} + + {error && } + + )} + ); } ContentError.propTypes = {