openreplay/frontend/app/components/hocs/withSiteIdRouter.js
Shekar Siri 2ed5cac986
Webpack upgrade and dependency cleanup (#523)
* change(ui) - webpack update
* change(ui) - api optimize and other fixes
2022-06-03 16:47:38 +02:00

30 lines
No EOL
866 B
JavaScript

import React from 'react';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { withSiteId } from 'App/routes';
import { setSiteId } from 'Duck/site';
export default BaseComponent =>
@withRouter
@connect((state, props) => ({
urlSiteId: props.match.params.siteId,
siteId: state.getIn([ 'site', 'siteId' ]),
}), {
setSiteId,
})
class extends React.PureComponent {
push = (location) => {
const { history, siteId } = this.props;
if (typeof location === 'string') {
history.push(withSiteId(location, siteId));
} else if (typeof location === 'object'){
history.push({ ...location, pathname: withSiteId(location.pathname, siteId) });
}
}
render() {
const { history, ...other } = this.props
return <BaseComponent { ...other } history={ { ...history, push: this.push } } />
}
}