Commit e9bbf8a1 authored by Viacheslav Pavlov's avatar Viacheslav Pavlov
Browse files

fixed ssr for cooperator details page, fixed BackButton

parent f9c22c5a
import { UPDATE_HISTORY } from '@gringlobal/client/constants/history';
export const updateHistory = (lastLocation: string) => (dispatch) => {
dispatch({ type: UPDATE_HISTORY, payload: lastLocation });
};
......@@ -3,13 +3,25 @@ import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { withRouter, RouteComponentProps } from 'react-router-dom';
import renderRoutes from '@gringlobal/client/ui/renderRoutes';
// Actions
import { updateHistory } from '@gringlobal/client/action/history';
interface IAppProps extends React.ClassAttributes<any>, RouteComponentProps {
route?: any;
updateHistory: (location: string) => void;
}
class App extends React.Component<IAppProps, any> {
public componentDidUpdate(prevProps: IAppProps) {
const { updateHistory, location: prevLocation } = prevProps;
const { location } = this.props;
if (prevLocation !== null && location !== null) {
if (prevLocation !== location) {
updateHistory(`${prevLocation.pathname}${prevLocation.search ? prevLocation.search : ''}`);
}
}
}
public render() {
const { route: { routes } } = this.props;
return (
......@@ -23,6 +35,7 @@ const mapStateToProps = (state) => ({
});
const mapDispatchToProps = (dispatch) => bindActionCreators({
updateHistory,
}, dispatch);
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(App));
......@@ -18,7 +18,7 @@ const userReducer = (state = initialState, action) => {
switch (action.type) {
case RECEIVE_COOPERATOR: {
const { apiCall } = action.payload;
if (apiCall.data) {
if (apiCall.data && state.cooperators) {
const { data: cooperators } = state.cooperators;
const cooperator = apiCall.data;
const updatedIndex = cooperators && cooperators.content && cooperators.content.findIndex((cooperator) => cooperator.id === cooperator.id) || -1;
......
......@@ -5,28 +5,33 @@ import { WithTranslation, withTranslation } from 'react-i18next';
// Action
import { getCooperatorAction } from 'cooperator/action/public';
// Model
import ApiCall from '@gringlobal/client/model/common/ApiCall';
import Cooperator from '@gringlobal/client/model/gringlobal/Cooperator';
// Ui
import BackButton from '@gringlobal/client/ui/common/button/BackButton';
interface ICooperatorDetailsPage extends React.ClassAttributes<any>, WithTranslation {
cooperator: Cooperator;
cooperator: ApiCall<Cooperator>;
getCooperatorAction: (id) => void;
id: number;
}
class CooperatorDetailsPage extends React.Component<ICooperatorDetailsPage> {
public componentWillMount(): void {
protected static needs = [
({ params: { id } }) => getCooperatorAction(id),
];
public componentDidMount(): void {
const { id, cooperator, getCooperatorAction } = this.props;
if (!cooperator || cooperator.id !== id) {
if (!cooperator || !cooperator.data || cooperator.data.id !== +id) {
getCooperatorAction(id);
}
}
public render() { // TODO add t
public render() {
const { cooperator, t } = this.props;
return cooperator ? (
<div>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment