2019-08-24 12:38:42 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { browserHistory } from 'react-router';
|
|
|
|
|
|
|
|
const RedirectToUser = ({ username, url = '/:username/sketches' }) => {
|
|
|
|
React.useEffect(() => {
|
|
|
|
if (username == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-09-08 16:43:16 +02:00
|
|
|
|
2019-08-24 12:38:42 +02:00
|
|
|
browserHistory.replace(url.replace(':username', username));
|
|
|
|
}, [username]);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
function mapStateToProps(state) {
|
|
|
|
return {
|
|
|
|
username: state.user ? state.user.username : null,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConnectedRedirectToUser = connect(mapStateToProps)(RedirectToUser);
|
|
|
|
|
2019-09-08 16:43:16 +02:00
|
|
|
const createRedirectWithUsername = url => props => <ConnectedRedirectToUser {...props} url={url} />;
|
2019-08-24 12:38:42 +02:00
|
|
|
|
|
|
|
export default createRedirectWithUsername;
|