diff options
Diffstat (limited to 'src/components/settings/navigation/SettingsNavigation.js')
-rw-r--r-- | src/components/settings/navigation/SettingsNavigation.js | 46 |
1 files changed, 18 insertions, 28 deletions
diff --git a/src/components/settings/navigation/SettingsNavigation.js b/src/components/settings/navigation/SettingsNavigation.js index 953760fec..e8370d2ef 100644 --- a/src/components/settings/navigation/SettingsNavigation.js +++ b/src/components/settings/navigation/SettingsNavigation.js | |||
@@ -57,40 +57,34 @@ class SettingsNavigation extends Component { | |||
57 | workspaceCount: PropTypes.number.isRequired, | 57 | workspaceCount: PropTypes.number.isRequired, |
58 | }; | 58 | }; |
59 | 59 | ||
60 | handleLoginLogout() { | 60 | handleLogout() { |
61 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); | ||
62 | const isUsingWithoutAccount = | 61 | const isUsingWithoutAccount = |
63 | this.props.stores.settings.app.server === LOCAL_SERVER; | 62 | this.props.stores.settings.app.server === LOCAL_SERVER; |
64 | 63 | ||
65 | if (isLoggedIn) { | 64 | // Remove current auth token |
66 | // Remove current auth token | 65 | localStorage.removeItem('authToken'); |
67 | localStorage.removeItem('authToken'); | ||
68 | 66 | ||
69 | if (isUsingWithoutAccount) { | 67 | if (isUsingWithoutAccount) { |
70 | // Reset server back to Ferdi API | 68 | // Reset server back to Ferdi API |
71 | this.props.actions.settings.update({ | 69 | this.props.actions.settings.update({ |
72 | type: 'app', | 70 | type: 'app', |
73 | data: { | 71 | data: { |
74 | server: LIVE_FERDI_API, | 72 | server: LIVE_FERDI_API, |
75 | }, | 73 | }, |
76 | }); | 74 | }); |
77 | } | ||
78 | this.props.stores.user.isLoggingOut = true; | ||
79 | } | 75 | } |
76 | this.props.stores.user.isLoggingOut = true; | ||
80 | 77 | ||
81 | this.props.stores.router.push('/auth/welcome'); | 78 | this.props.stores.router.push('/auth/welcome'); |
82 | 79 | ||
83 | if (isLoggedIn) { | 80 | // Reload Ferdi, otherwise many settings won't sync correctly with the server |
84 | // Reload Ferdi, otherwise many settings won't sync correctly with the server | 81 | // after logging into another account |
85 | // after logging into another account | 82 | window.location.reload(); |
86 | window.location.reload(); | ||
87 | } | ||
88 | } | 83 | } |
89 | 84 | ||
90 | render() { | 85 | render() { |
91 | const { serviceCount, workspaceCount, stores } = this.props; | 86 | const { serviceCount, workspaceCount, stores } = this.props; |
92 | const { intl } = this.props; | 87 | const { intl } = this.props; |
93 | const isLoggedIn = Boolean(localStorage.getItem('authToken')); | ||
94 | const isUsingWithoutAccount = stores.settings.app.server === LOCAL_SERVER; | 88 | const isUsingWithoutAccount = stores.settings.app.server === LOCAL_SERVER; |
95 | const isUsingFranzServer = stores.settings.app.server === LIVE_FRANZ_API; | 89 | const isUsingFranzServer = stores.settings.app.server === LIVE_FRANZ_API; |
96 | 90 | ||
@@ -107,7 +101,6 @@ class SettingsNavigation extends Component { | |||
107 | to="/settings/services" | 101 | to="/settings/services" |
108 | className="settings-navigation__link" | 102 | className="settings-navigation__link" |
109 | activeClassName="is-active" | 103 | activeClassName="is-active" |
110 | disabled={!isLoggedIn} | ||
111 | > | 104 | > |
112 | {intl.formatMessage(messages.yourServices)}{' '} | 105 | {intl.formatMessage(messages.yourServices)}{' '} |
113 | <span className="badge">{serviceCount}</span> | 106 | <span className="badge">{serviceCount}</span> |
@@ -116,7 +109,6 @@ class SettingsNavigation extends Component { | |||
116 | to="/settings/workspaces" | 109 | to="/settings/workspaces" |
117 | className="settings-navigation__link" | 110 | className="settings-navigation__link" |
118 | activeClassName="is-active" | 111 | activeClassName="is-active" |
119 | disabled={!isLoggedIn} | ||
120 | > | 112 | > |
121 | {intl.formatMessage(messages.yourWorkspaces)}{' '} | 113 | {intl.formatMessage(messages.yourWorkspaces)}{' '} |
122 | <span className="badge">{workspaceCount}</span> | 114 | <span className="badge">{workspaceCount}</span> |
@@ -126,7 +118,6 @@ class SettingsNavigation extends Component { | |||
126 | to="/settings/user" | 118 | to="/settings/user" |
127 | className="settings-navigation__link" | 119 | className="settings-navigation__link" |
128 | activeClassName="is-active" | 120 | activeClassName="is-active" |
129 | disabled={!isLoggedIn} | ||
130 | > | 121 | > |
131 | {intl.formatMessage(messages.account)} | 122 | {intl.formatMessage(messages.account)} |
132 | </Link> | 123 | </Link> |
@@ -136,7 +127,6 @@ class SettingsNavigation extends Component { | |||
136 | to="/settings/team" | 127 | to="/settings/team" |
137 | className="settings-navigation__link" | 128 | className="settings-navigation__link" |
138 | activeClassName="is-active" | 129 | activeClassName="is-active" |
139 | disabled={!isLoggedIn} | ||
140 | > | 130 | > |
141 | {intl.formatMessage(messages.team)} | 131 | {intl.formatMessage(messages.team)} |
142 | </Link> | 132 | </Link> |
@@ -158,11 +148,11 @@ class SettingsNavigation extends Component { | |||
158 | <span className="settings-navigation__expander" /> | 148 | <span className="settings-navigation__expander" /> |
159 | <button | 149 | <button |
160 | type="button" | 150 | type="button" |
161 | to={isLoggedIn ? '/auth/logout' : '/auth/welcome'} | 151 | to='/auth/logout' |
162 | className="settings-navigation__link" | 152 | className="settings-navigation__link" |
163 | onClick={this.handleLoginLogout.bind(this)} | 153 | onClick={this.handleLogout.bind(this)} |
164 | > | 154 | > |
165 | {isLoggedIn && !isUsingWithoutAccount | 155 | {!isUsingWithoutAccount |
166 | ? intl.formatMessage(messages.logout) | 156 | ? intl.formatMessage(messages.logout) |
167 | : 'Exit session'} | 157 | : 'Exit session'} |
168 | </button> | 158 | </button> |