mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-04 04:29:40 +05:30
52 lines
1.2 KiB
React
52 lines
1.2 KiB
React
|
import { Component, PropTypes } from 'react';
|
||
|
import { Redirect } from 'react-router-dom';
|
||
|
|
||
|
import authFlow from 'services/authFlow';
|
||
|
|
||
|
export default class AuthFlowRouteContents extends Component {
|
||
|
static propTypes = {
|
||
|
component: PropTypes.any,
|
||
|
routerProps: PropTypes.object
|
||
|
};
|
||
|
|
||
|
state = {
|
||
|
component: null
|
||
|
};
|
||
|
|
||
|
componentDidMount() {
|
||
|
this.handleProps(this.props);
|
||
|
}
|
||
|
|
||
|
componentWillReceiveProps(nextProps) {
|
||
|
this.handleProps(nextProps);
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
return this.state.component;
|
||
|
}
|
||
|
|
||
|
handleProps(props) {
|
||
|
const {routerProps} = props;
|
||
|
|
||
|
authFlow.handleRequest({
|
||
|
path: routerProps.location.pathname,
|
||
|
params: routerProps.match.params,
|
||
|
query: routerProps.location.query
|
||
|
}, this.onRedirect.bind(this), this.onRouteAllowed.bind(this, props));
|
||
|
}
|
||
|
|
||
|
onRedirect(path) {
|
||
|
this.setState({
|
||
|
component: <Redirect to={path} />
|
||
|
});
|
||
|
}
|
||
|
|
||
|
onRouteAllowed(props) {
|
||
|
const {component: Component} = props;
|
||
|
|
||
|
this.setState({
|
||
|
component: <Component {...props.routerProps} />
|
||
|
});
|
||
|
}
|
||
|
}
|