Commit 592fffb6 authored by Elias Nahum's avatar Elias Nahum

Fix go back from deleted permalink

parent 0e1fa22f
......@@ -108,7 +108,7 @@ export function emitCloseRightHandSide() {
dispatch(closeRightHandSide());
}
export async function emitPostFocusEvent(postId) {
export async function emitPostFocusEvent(postId, returnTo = '') {
loadChannelsForCurrentUser();
const {data} = await getPostThread(postId)(dispatch, getState);
......@@ -116,7 +116,8 @@ export async function emitPostFocusEvent(postId) {
const channelId = data.posts[data.order[0]].channel_id;
const channel = ChannelStore.getChannelById(channelId);
if (!channel) {
browserHistory.push('/error?type=' + ErrorPageTypes.PERMALINK_NOT_FOUND);
browserHistory.push(`/error?type=${ErrorPageTypes.PERMALINK_NOT_FOUND}&returnTo=${returnTo}`);
return;
}
if (channel && channel.type === Constants.DM_CHANNEL) {
......@@ -127,7 +128,7 @@ export async function emitPostFocusEvent(postId) {
await doFocusPost(channelId, postId, data);
} else {
browserHistory.push('/error?type=' + ErrorPageTypes.PERMALINK_NOT_FOUND);
browserHistory.push(`/error?type=${ErrorPageTypes.PERMALINK_NOT_FOUND}&returnTo=${returnTo}`);
}
}
......
......@@ -6,6 +6,8 @@ import React from 'react';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
import {ErrorPageTypes} from 'utils/constants.jsx';
import ErrorTitle from './error_title.jsx';
import ErrorMessage from './error_message.jsx';
......@@ -28,6 +30,28 @@ export default class ErrorPage extends React.PureComponent {
const title = params.get('title');
const message = params.get('message');
const service = params.get('service');
const returnTo = params.get('returnTo');
let backButton;
if (type === ErrorPageTypes.PERMALINK_NOT_FOUND && returnTo) {
backButton = (
<Link to={returnTo}>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to Mattermost'
/>
</Link>
);
} else {
backButton = (
<Link to='/'>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to Mattermost'
/>
</Link>
);
}
return (
<div className='container-fluid'>
......@@ -46,12 +70,7 @@ export default class ErrorPage extends React.PureComponent {
message={message}
service={service}
/>
<Link to='/'>
<FormattedMessage
id='error.generic.link'
defaultMessage='Back to Mattermost'
/>
</Link>
{backButton}
</div>
</div>
);
......
......@@ -9,9 +9,8 @@ import {uploadFile} from 'actions/file_actions.jsx';
import FileUpload from './file_upload.jsx';
function mapStateToProps(state, ownProps) {
function mapStateToProps(state) {
return {
...ownProps,
currentChannelId: getCurrentChannelId(state),
uploadFile
};
......
......@@ -97,6 +97,7 @@ export default class NeedsTeam extends React.Component {
this.state = {
team,
returnTo: '',
finishedFetchingChannels: false
};
}
......@@ -105,6 +106,10 @@ export default class NeedsTeam extends React.Component {
if (this.props.match.params.team !== nextProps.match.params.team) {
this.setState({team: this.updateCurrentTeam(nextProps)});
}
if (this.props.location.pathname !== nextProps.location.pathname && nextProps.location.pathname.includes('/pl/')) {
this.setState({returnTo: this.props.location.pathname});
}
}
updateCurrentTeam(props) {
......@@ -264,7 +269,12 @@ export default class NeedsTeam extends React.Component {
<Switch>
<Route
path={`${this.props.match.url}/pl/:postid`}
component={PermalinkView}
render={(props) => (
<PermalinkView
{...props}
returnTo={this.state.returnTo}
/>
)}
/>
<Route
path={'/:team/:path(channels|messages)/:identifier'}
......
......@@ -3,6 +3,7 @@
import $ from 'jquery';
import React from 'react';
import PropTypes from 'prop-types';
import {FormattedMessage} from 'react-intl';
import {Link} from 'react-router-dom';
......@@ -13,6 +14,10 @@ import PostView from 'components/post_view';
import * as GlobalActions from 'actions/global_actions.jsx';
export default class PermalinkView extends React.PureComponent {
static propTypes = {
returnTo: PropTypes.string.isRequired
};
constructor(props) {
super(props);
......@@ -28,7 +33,7 @@ export default class PermalinkView extends React.PureComponent {
doPermalinkEvent(props) {
const postId = props.match.params.postid;
GlobalActions.emitPostFocusEvent(postId);
GlobalActions.emitPostFocusEvent(postId, this.props.returnTo);
}
getStateFromStores(props) {
......
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