Update index that wraps signin instead of signinpage

pull/10616/head
Palak Bhojani 2019-01-09 14:22:41 -08:00
parent 3813ac7dc9
commit 5b20852b40
5 changed files with 23 additions and 41 deletions
ui/src

View File

@ -9,9 +9,6 @@ import {trySources} from 'src/onboarding/apis'
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
import {getMe} from 'src/shared/apis/v2/user' import {getMe} from 'src/shared/apis/v2/user'
// Utils
import {AuthContext} from 'src/utils/auth'
// Types // Types
import {RemoteDataState} from 'src/types' import {RemoteDataState} from 'src/types'
@ -44,21 +41,23 @@ export class Signin extends PureComponent<Props, State> {
const isSourcesAllowed = await trySources() const isSourcesAllowed = await trySources()
const isUserSignedIn = isSourcesAllowed const isUserSignedIn = isSourcesAllowed
this.setState({loading: RemoteDataState.Done, isUserSignedIn}) this.setState({loading: RemoteDataState.Done, isUserSignedIn})
this.checkForLogin()
this.intervalID = setInterval(this.checkForLogin, FETCH_WAIT)
if (!isUserSignedIn) { if (!isUserSignedIn) {
this.props.router.push('/signin') this.props.router.push('/signin')
} }
} }
public componentWillUnmount() {
clearInterval(this.intervalID)
}
public render() { public render() {
if (this.isLoading) { if (this.isLoading) {
return <div className="page-spinner" /> return <div className="page-spinner" />
} }
return ( return this.props.children && React.cloneElement(this.props.children)
<AuthContext.Provider value={{onSignInUser: this.handleSignInUser}}>
{this.props.children && React.cloneElement(this.props.children)}
</AuthContext.Provider>
)
} }
private get isLoading(): boolean { private get isLoading(): boolean {
@ -69,12 +68,6 @@ export class Signin extends PureComponent<Props, State> {
) )
} }
private handleSignInUser = () => {
this.intervalID = setInterval(this.checkForLogin, FETCH_WAIT)
this.setState({isUserSignedIn: true})
this.props.router.push('/dashboards')
}
private checkForLogin = async () => { private checkForLogin = async () => {
try { try {
await getMe() await getMe()

View File

@ -89,8 +89,8 @@ class Root extends PureComponent {
path="/onboarding/:stepID/:substepID" path="/onboarding/:stepID/:substepID"
component={OnboardingWizardPage} component={OnboardingWizardPage}
/> />
<Route component={Signin}>
<Route path="/signin" component={SigninPage} /> <Route path="/signin" component={SigninPage} />
<Route component={Signin}>
<Route component={GetMe}> <Route component={GetMe}>
<Route component={GetOrganizations}> <Route component={GetOrganizations}>
<Route component={App}> <Route component={App}>

View File

@ -1,5 +1,6 @@
// Libraries // Libraries
import React, {PureComponent, ChangeEvent} from 'react' import React, {PureComponent, ChangeEvent} from 'react'
import {withRouter, WithRouterProps} from 'react-router'
import {connect} from 'react-redux' import {connect} from 'react-redux'
import _, {get} from 'lodash' import _, {get} from 'lodash'
@ -31,10 +32,9 @@ import * as copy from 'src/shared/copy/notifications'
import {Links} from 'src/types/v2/links' import {Links} from 'src/types/v2/links'
import {Notification, NotificationFunc} from 'src/types' import {Notification, NotificationFunc} from 'src/types'
export interface Props { export interface OwnProps {
links: Links links: Links
notify: (message: Notification | NotificationFunc) => void notify: (message: Notification | NotificationFunc) => void
onSignInUser: () => void
} }
interface State { interface State {
@ -42,6 +42,8 @@ interface State {
password: string password: string
} }
type Props = OwnProps & WithRouterProps
@ErrorHandling @ErrorHandling
class SigninForm extends PureComponent<Props, State> { class SigninForm extends PureComponent<Props, State> {
public state: State = { public state: State = {
@ -101,11 +103,12 @@ class SigninForm extends PureComponent<Props, State> {
} }
private handleSignIn = async (): Promise<void> => { private handleSignIn = async (): Promise<void> => {
const {notify, onSignInUser} = this.props const {notify, router} = this.props
const {username, password} = this.state const {username, password} = this.state
try { try {
await signin({username, password}) await signin({username, password})
onSignInUser() router.push('/dashboards')
} catch (error) { } catch (error) {
const message = get(error, 'data.msg', '') const message = get(error, 'data.msg', '')
@ -129,4 +132,4 @@ const mdtp = {
export default connect( export default connect(
mstp, mstp,
mdtp mdtp
)(SigninForm) )(withRouter(SigninForm))

View File

@ -7,24 +7,17 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
import SplashPage from 'src/shared/components/splash_page/SplashPage' import SplashPage from 'src/shared/components/splash_page/SplashPage'
import SigninForm from 'src/onboarding/components/SigninForm' import SigninForm from 'src/onboarding/components/SigninForm'
// Utils
import {AuthContext} from 'src/utils/auth'
@ErrorHandling @ErrorHandling
class SigninPage extends PureComponent<{}> { class SigninPage extends PureComponent<{}> {
public render() { public render() {
return ( return (
<AuthContext.Consumer>
{({onSignInUser}) => (
<SplashPage panelWidthPixels={300}> <SplashPage panelWidthPixels={300}>
<SplashPage.Panel> <SplashPage.Panel>
<SplashPage.Logo /> <SplashPage.Logo />
<SplashPage.Header title="InfluxData" /> <SplashPage.Header title="InfluxData" />
<SigninForm onSignInUser={onSignInUser} /> <SigninForm />
</SplashPage.Panel> </SplashPage.Panel>
</SplashPage> </SplashPage>
)}
</AuthContext.Consumer>
) )
} }
} }

View File

@ -1,7 +0,0 @@
import React from 'react'
export interface SigninProps {
onSignInUser: () => void
}
export const AuthContext = React.createContext<SigninProps>(null)