feat(ui): login redirect to /me (#11166)

pull/11227/head
Delmer 2019-01-17 12:02:05 -05:00 committed by GitHub
parent eef66bd7ab
commit 6e0635861e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 45 additions and 10 deletions

View File

@ -22,7 +22,14 @@ export class Logout extends PureComponent<Props> {
private handleSignOut = async () => {
await logout()
this.props.router.push('/')
const {query} = this.props.location
let returnTo = ''
if (query && query.returnTo) {
returnTo = `?returnTo=${query.returnTo}`
}
this.props.router.push(`/signin${returnTo}`)
}
}

View File

@ -62,8 +62,22 @@ export class Signin extends PureComponent<Props, State> {
try {
await getMe()
} catch (error) {
const {
location: {pathname},
} = this.props
clearInterval(this.intervalID)
this.props.router.push('/signin')
if (pathname.startsWith('/signin')) {
return
}
let returnTo = ''
if (pathname !== '/') {
returnTo = `?returnTo=${pathname}`
}
this.props.router.push(`/signin${returnTo}`)
}
}
}

View File

@ -1,14 +1,15 @@
// Libraries
import React, {SFC} from 'react'
import {Link} from 'react-router'
import {withRouter, WithRouterProps} from 'react-router'
// Components
import {Button, ComponentSize} from 'src/clockface'
const LogoutButton: SFC = () => (
<Link to={`/logout`}>
const LogoutButton: SFC<WithRouterProps> = props => (
<Link to={`/logout?returnTo=${props.location.pathname}`}>
<Button text="Logout" size={ComponentSize.ExtraSmall} />
</Link>
)
export default LogoutButton
export default withRouter<{}>(LogoutButton)

View File

@ -103,12 +103,12 @@ class SigninForm extends PureComponent<Props, State> {
}
private handleSignIn = async (): Promise<void> => {
const {notify, router} = this.props
const {notify} = this.props
const {username, password} = this.state
try {
await signin({username, password})
router.push('/dashboards')
this.handleRedirect()
} catch (error) {
const message = get(error, 'data.msg', '')
@ -119,6 +119,17 @@ class SigninForm extends PureComponent<Props, State> {
notify({...copy.SigninError, message})
}
}
private handleRedirect() {
const {router} = this.props
const {query} = this.props.location
if (query && query.returnTo) {
router.push(query.returnTo)
} else {
router.push('/me')
}
}
}
const mstp = ({links}) => ({

View File

@ -122,7 +122,7 @@ class OnboardingWizard extends PureComponent<Props> {
private handleExit = () => {
const {router, onCompleteSetup} = this.props
onCompleteSetup()
router.push(`/`)
router.push(`/me`)
}
private get onboardingStepProps(): OnboardingStepProps {

View File

@ -12,6 +12,7 @@ import SplashPage from 'src/shared/components/splash_page/SplashPage'
import SigninForm from 'src/onboarding/components/SigninForm'
import {Spinner} from 'src/clockface'
import {RemoteDataState} from 'src/types'
import Notifications from 'src/shared/components/notifications/Notifications'
interface State {
status: RemoteDataState
@ -39,6 +40,7 @@ class SigninPage extends PureComponent<WithRouterProps, State> {
public render() {
return (
<Spinner loading={this.state.status}>
<Notifications inPresentationMode={true} />
<SplashPage panelWidthPixels={300}>
<SplashPage.Panel>
<SplashPage.Logo />

View File

@ -32,7 +32,7 @@ class SideNav extends PureComponent<Props> {
public render() {
const {isHidden, me} = this.props
const {location} = this.props
if (isHidden) {
return null
}
@ -48,7 +48,7 @@ class SideNav extends PureComponent<Props> {
>
<NavMenu.SubItem
title="Logout"
link="/logout"
link={`/logout?returnTo=${location.pathname}`}
location={location.pathname}
highlightWhen={[]}
/>