From 05af4c7c539fb688ec9bfeaf57d9b53a0a319659 Mon Sep 17 00:00:00 2001 From: Jake McDermott Date: Tue, 16 Oct 2018 00:24:44 -0400 Subject: [PATCH] nav login fixup --- src/App.jsx | 144 +++++++++++++++++++++----------------------- src/index.js | 13 +++- src/pages/Login.jsx | 7 +-- 3 files changed, 82 insertions(+), 82 deletions(-) diff --git a/src/App.jsx b/src/App.jsx index b1d738f912..7e6f5925c2 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,5 +1,4 @@ import React, { Fragment } from 'react'; -import { render } from 'react-dom'; import { HashRouter as Router, Route, @@ -87,7 +86,7 @@ class App extends React.Component { super(props); this.state = { - activeItem: 'dashboard', + activeItem: window.location.hash.split("#/").pop().split("/").shift(), isNavOpen: (typeof window !== 'undefined' && window.innerWidth >= parseInt(breakpointMd.value, 10)), }; @@ -97,7 +96,7 @@ class App extends React.Component { const { isNavOpen } = this.state; this.setState({ isNavOpen: !isNavOpen }); - }; + } onNavSelect = ({ itemId }) => { this.setState({ activeItem: itemId }); @@ -135,72 +134,70 @@ class App extends React.Component { } /> ( - } - avatar={} - showNavToggle - onNavToggle={this.onNavToggle} - /> - )} - sidebar={( - - - Dashboard - Jobs - Schedules - My View - - - Templates - Credentials - Projects - Inventories - Inventory Scripts - - - Organizations - Users - Teams - - - Credential Types - Notifications - Management Jobs - Instance Groups - Applications - Settings - - - )} - /> - )}> - - ()} /> - - - - - - - - - - - - - - - - - - - - + } + avatar={} + showNavToggle + onNavToggle={this.onNavToggle} + /> + )} + sidebar={( + + + Dashboard + Jobs + Schedules + My View + + + Templates + Credentials + Projects + Inventories + Inventory Scripts + + + Organizations + Users + Teams + + + Credential Types + Notifications + Management Jobs + Instance Groups + Applications + Settings + + + )} + /> + )}> + ()} /> + + + + + + + + + + + + + + + + + + + )} /> @@ -209,11 +206,4 @@ class App extends React.Component { } } -const el = document.getElementById('app'); - -api.getRoot() - .then(({ data }) => { - const { custom_logo, custom_login_info } = data; - - render(, el); - }); +export default App; diff --git a/src/index.js b/src/index.js index 0e9f982028..337fdef1da 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,19 @@ +import React from 'react'; +import { render } from 'react-dom'; + import App from './App'; +import api from './api'; import '@patternfly/react-core/dist/styles/base.css'; import '@patternfly/patternfly-next/patternfly.css'; import './app.scss'; -export default App; +const el = document.getElementById('app'); + +api.getRoot() + .then(({ data }) => { + const { custom_logo, custom_login_info } = data; + + render(, el); + }); diff --git a/src/pages/Login.jsx b/src/pages/Login.jsx index 77fb3902a7..a2836c1769 100644 --- a/src/pages/Login.jsx +++ b/src/pages/Login.jsx @@ -26,7 +26,7 @@ class LoginPage extends Component { this.state = { username: '', password: '', - redirect: false, + error: '', loading: false, }; } @@ -49,7 +49,6 @@ class LoginPage extends Component { this.safeSetState({ loading: true }); api.login(username, password) - .then(() => this.safeSetState({ redirect: true })) .catch(error => { if (error.response.status === 401) { this.safeSetState({ error: LOGIN_ERROR_MESSAGE }); @@ -61,10 +60,10 @@ class LoginPage extends Component { } render () { - const { username, password, redirect, loading, error } = this.state; + const { username, password, loading, error } = this.state; const { logo, loginInfo } = this.props; - if (redirect) { + if (api.isAuthenticated()) { return (); }