2016-08-24 15:09:42 +02:00
|
|
|
/**
|
2017-03-18 17:34:00 +01:00
|
|
|
*
|
|
|
|
* LeftMenuLink
|
|
|
|
*
|
|
|
|
*/
|
2016-08-24 15:09:42 +02:00
|
|
|
|
2017-09-26 16:36:28 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { startsWith } from 'lodash';
|
2017-09-20 11:12:04 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2017-08-17 15:39:09 +02:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2017-08-21 15:12:53 +02:00
|
|
|
import { Link } from 'react-router-dom';
|
2017-08-17 15:39:09 +02:00
|
|
|
|
|
|
|
import styles from './styles.scss';
|
2016-08-24 15:09:42 +02:00
|
|
|
|
|
|
|
class LeftMenuLink extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
|
|
|
render() {
|
2017-07-21 18:15:43 +02:00
|
|
|
// We need to create our own active url checker,
|
|
|
|
// because of the two levels router.
|
2017-09-26 16:36:28 +02:00
|
|
|
const isLinkActive = startsWith(window.location.pathname.replace('/admin', ''), this.props.destination);
|
2017-07-21 18:15:43 +02:00
|
|
|
|
2016-08-24 15:09:42 +02:00
|
|
|
return (
|
2017-08-17 15:03:03 +02:00
|
|
|
<li className={styles.item}>
|
2017-11-27 17:27:16 +01:00
|
|
|
<Link
|
|
|
|
className={`${styles.link} ${isLinkActive ? styles.linkActive : ''}`}
|
|
|
|
to={{
|
|
|
|
pathname: this.props.destination,
|
2017-12-05 15:28:31 +01:00
|
|
|
search: this.props.source ? `?source=${this.props.source}` : '',
|
2017-11-27 17:27:16 +01:00
|
|
|
}}
|
|
|
|
>
|
2017-07-21 18:15:43 +02:00
|
|
|
<i className={`${styles.linkIcon} fa-${this.props.icon} fa`}></i>
|
2017-09-14 11:10:05 +02:00
|
|
|
<FormattedMessage
|
|
|
|
id={this.props.label}
|
|
|
|
defaultMessage='{label}'
|
|
|
|
values={{
|
|
|
|
label: this.props.label,
|
|
|
|
}}
|
|
|
|
className={styles.linkLabel}
|
|
|
|
/>
|
2016-08-25 10:47:15 +02:00
|
|
|
</Link>
|
2016-08-24 15:09:42 +02:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
LeftMenuLink.propTypes = {
|
2017-09-20 11:12:04 +02:00
|
|
|
destination: PropTypes.string.isRequired,
|
|
|
|
icon: PropTypes.string.isRequired,
|
|
|
|
label: PropTypes.string.isRequired,
|
2017-11-27 17:27:16 +01:00
|
|
|
source: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
LeftMenuLink.defaultProps = {
|
|
|
|
source: '',
|
2016-08-24 15:09:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export default LeftMenuLink;
|