2023-05-28 07:18:23 -05:00
|
|
|
import { PureComponent } from 'react';
|
2023-05-28 09:38:10 -05:00
|
|
|
|
2017-01-02 18:15:42 -06:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-05-28 09:38:10 -05:00
|
|
|
|
2023-10-19 12:44:55 -05:00
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
|
2023-05-08 20:11:56 -05:00
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
2023-10-19 12:44:55 -05:00
|
|
|
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
2017-01-02 18:15:42 -06:00
|
|
|
|
2023-10-19 12:44:55 -05:00
|
|
|
class ColumnBackButtonSlim extends PureComponent {
|
2017-01-02 18:15:42 -06:00
|
|
|
|
2023-10-19 12:44:55 -05:00
|
|
|
static propTypes = {
|
|
|
|
...WithRouterPropTypes,
|
2017-05-12 07:44:10 -05:00
|
|
|
};
|
2017-01-02 18:15:42 -06:00
|
|
|
|
2023-05-25 12:14:51 -05:00
|
|
|
handleClick = () => {
|
2023-10-19 12:44:55 -05:00
|
|
|
const { location, history } = this.props;
|
2023-05-25 12:14:51 -05:00
|
|
|
|
|
|
|
// Check if there is a previous page in the app to go back to per https://stackoverflow.com/a/70532858/9703201
|
|
|
|
// When upgrading to V6, check `location.key !== 'default'` instead per https://github.com/remix-run/history/blob/main/docs/api-reference.md#location
|
2023-10-19 12:44:55 -05:00
|
|
|
if (location.key) {
|
|
|
|
history.goBack();
|
2018-05-23 07:17:05 -05:00
|
|
|
} else {
|
2023-10-19 12:44:55 -05:00
|
|
|
history.push('/');
|
2017-07-07 01:27:52 -05:00
|
|
|
}
|
2023-02-03 13:52:07 -06:00
|
|
|
};
|
2017-01-02 18:15:42 -06:00
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
2017-04-22 21:26:55 -05:00
|
|
|
<div className='column-back-button--slim'>
|
2023-04-04 09:33:44 -05:00
|
|
|
<div role='button' tabIndex={0} onClick={this.handleClick} className='column-back-button column-back-button--slim-button'>
|
2019-09-09 09:41:41 -05:00
|
|
|
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
|
2017-01-02 18:15:42 -06:00
|
|
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-04-21 13:05:35 -05:00
|
|
|
}
|
2023-10-19 12:44:55 -05:00
|
|
|
|
|
|
|
export default withRouter(ColumnBackButtonSlim);
|