2019-08-24 10:38:42 +00: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 14:43:16 +00:00
|
|
|
|
2019-08-24 10:38:42 +00: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 14:43:16 +00:00
|
|
|
const createRedirectWithUsername = url => props => <ConnectedRedirectToUser {...props} url={url} />;
|
2019-08-24 10:38:42 +00:00
|
|
|
|
|
|
|
export default createRedirectWithUsername;
|