Skip to content
Snippets Groups Projects
Unverified Commit 0b706c5e authored by Jed Fox's avatar Jed Fox
Browse files

Update the server button in the corner to take the user to the “change server”...

Update the server button in the corner to take the user to the “change server” page if none is configured
parent 17793f10
No related branches found
No related tags found
No related merge requests found
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withRouter } from 'react-router'; import { useHistory, withRouter } from 'react-router';
import * as actions from 'loot-core/src/client/actions'; import * as actions from 'loot-core/src/client/actions';
import { import {
View, View,
...@@ -10,9 +10,9 @@ import { ...@@ -10,9 +10,9 @@ import {
Menu Menu
} from 'loot-design/src/components/common'; } from 'loot-design/src/components/common';
import { colors } from 'loot-design/src/style'; import { colors } from 'loot-design/src/style';
import useServerURL from '../hooks/useServerURL';
function LoggedInUser({ function LoggedInUser({
history,
files, files,
budgetId, budgetId,
userData, userData,
...@@ -26,6 +26,8 @@ function LoggedInUser({ ...@@ -26,6 +26,8 @@ function LoggedInUser({
}) { }) {
let [loading, setLoading] = useState(true); let [loading, setLoading] = useState(true);
let [menuOpen, setMenuOpen] = useState(false); let [menuOpen, setMenuOpen] = useState(false);
const url = useServerURL();
const history = useHistory();
useEffect(() => { useEffect(() => {
getUserData().then(() => setLoading(false)); getUserData().then(() => setLoading(false));
...@@ -33,7 +35,7 @@ function LoggedInUser({ ...@@ -33,7 +35,7 @@ function LoggedInUser({
async function onChangePassword() { async function onChangePassword() {
await closeBudget(); await closeBudget();
window.__history.push('/change-password'); history.push('/change-password');
} }
function onMenuSelect(type) { function onMenuSelect(type) {
...@@ -51,7 +53,11 @@ function LoggedInUser({ ...@@ -51,7 +53,11 @@ function LoggedInUser({
} }
function onClick() { function onClick() {
setMenuOpen(true); if (url) {
setMenuOpen(true);
} else {
history.push('/config-server');
}
} }
if (loading) { if (loading) {
...@@ -68,7 +74,7 @@ function LoggedInUser({ ...@@ -68,7 +74,7 @@ function LoggedInUser({
return ( return (
<View style={[{ flexDirection: 'row', alignItems: 'center' }, style]}> <View style={[{ flexDirection: 'row', alignItems: 'center' }, style]}>
<Button bare onClick={onClick} style={{ color }}> <Button bare onClick={onClick} style={{ color }}>
Server {url ? 'Server' : 'No server'}
</Button> </Button>
{menuOpen && ( {menuOpen && (
...@@ -82,7 +88,7 @@ function LoggedInUser({ ...@@ -82,7 +88,7 @@ function LoggedInUser({
items={[ items={[
{ name: 'change-password', text: 'Change password' }, { name: 'change-password', text: 'Change password' },
{ name: 'sign-out', text: 'Sign out' } { name: 'sign-out', text: 'Sign out' }
].filter(x => x)} ]}
/> />
</Tooltip> </Tooltip>
)} )}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment