From 38cc4fec1a0d1b8afd210a460dc04f1f2819ee5f Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 24 May 2019 09:44:24 +1000 Subject: [PATCH] Profile and logout buttons are disabled when logged out --- src/components/panels/common_links.jsx | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/components/panels/common_links.jsx b/src/components/panels/common_links.jsx index eb3b474..11f2e37 100644 --- a/src/components/panels/common_links.jsx +++ b/src/components/panels/common_links.jsx @@ -1,5 +1,6 @@ import React from 'react'; import { withRouter, Link } from 'react-router-dom'; +import { connect } from 'react-redux'; import Logout from './logout.jsx'; @@ -12,26 +13,57 @@ class CommonLinks extends React.Component { } render() { + //render extra stuff let Extra; - if (this.props.extra) { Extra = this.props.extra; } else { Extra = () => null; } + //disable the profile link when logged out + let ProfileLink; + if (this.props.loggedIn) { + ProfileLink = () =>

Go to your profile

; + } else { + ProfileLink = () => null; + } + + //disable the logout button when logged out + let LogoutLink; + if (this.props.loggedIn) { + LogoutLink = () => this.props.history.push('/')} />; + } else { + LogoutLink = () => null; + } + + return (

Return home

-

Go to your profile

+

Go to the game ladder

- this.props.history.push('/')} /> +
); } } +function mapStoreToProps(store) { + return { + loggedIn: store.account.id !== 0 + } +} + +function mapDispatchToProps(dispatch) { + return { + // + } +} + +CommonLinks = connect(mapStoreToProps, mapDispatchToProps)(CommonLinks); + export default withRouter(CommonLinks); \ No newline at end of file