Skip to content

Commit

Permalink
Use useNavigate instead of accessing window.__navigate (#3904)
Browse files Browse the repository at this point in the history
* Use useNavigate instead of accessing window.__navigate

* Release notes

* Update packages/desktop-client/src/components/manager/ConfigServer.tsx

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
joel-jeremy and coderabbitai[bot] authored Dec 5, 2024
1 parent 501c865 commit 2c0bd6b
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 9 deletions.
9 changes: 6 additions & 3 deletions packages/desktop-client/src/components/LoggedInUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useSelector } from 'react-redux';
import { type State } from 'loot-core/src/client/state-types';

import { useActions } from '../hooks/useActions';
import { useNavigate } from '../hooks/useNavigate';
import { theme, styles } from '../style';

import { Button } from './common/Button2';
Expand Down Expand Up @@ -38,9 +39,11 @@ export function LoggedInUser({
getUserData().then(() => setLoading(false));
}, []);

const navigate = useNavigate();

async function onChangePassword() {
await closeBudget();
window.__navigate('/change-password');
navigate('/change-password');
}

async function onMenuSelect(type) {
Expand All @@ -52,14 +55,14 @@ export function LoggedInUser({
break;
case 'sign-in':
await closeBudget();
window.__navigate('/login');
navigate('/login');
break;
case 'sign-out':
signOut();
break;
case 'config-server':
await closeBudget();
window.__navigate('/config-server');
navigate('/config-server');
break;
default:
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ export function ConfigServer() {
async function onCreateTestFile() {
await setServerUrl(null);
await createBudget({ testMode: true });
window.__navigate('/');
}

return (
Expand Down Expand Up @@ -250,7 +249,10 @@ export function ConfigServer() {
<Button
variant="primary"
style={{ marginLeft: 15 }}
onPress={onCreateTestFile}
onPress={async () => {
await onCreateTestFile();
navigate('/');
}}
>
{t('Create test file')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux';

import { importBudget } from 'loot-core/src/client/actions/budgets';

import { useNavigate } from '../../../hooks/useNavigate';
import { styles, theme } from '../../../style';
import { Block } from '../../common/Block';
import { ButtonWithLoading } from '../../common/Button2';
Expand All @@ -31,7 +32,7 @@ function getErrorMessage(error: string): string {

export function ImportActualModal() {
const { t } = useTranslation();

const navigate = useNavigate();
const dispatch = useDispatch();
const [error, setError] = useState<string | null>(null);
const [importing, setImporting] = useState(false);
Expand All @@ -46,6 +47,7 @@ export function ImportActualModal() {
setError(null);
try {
await dispatch(importBudget(res[0], 'actual'));
navigate('/budget');
} catch (err) {
setError(err.message);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux';

import { importBudget } from 'loot-core/src/client/actions/budgets';

import { useNavigate } from '../../../hooks/useNavigate';
import { styles, theme } from '../../../style';
import { Block } from '../../common/Block';
import { ButtonWithLoading } from '../../common/Button2';
Expand All @@ -23,7 +24,7 @@ function getErrorMessage(error: string): string {

export function ImportYNAB4Modal() {
const { t } = useTranslation();

const navigate = useNavigate();
const dispatch = useDispatch();
const [error, setError] = useState<string | null>(null);
const [importing, setImporting] = useState(false);
Expand All @@ -38,6 +39,7 @@ export function ImportYNAB4Modal() {
setError(null);
try {
await dispatch(importBudget(res[0], 'ynab4'));
navigate('/budget');
} catch (err) {
setError(err.message);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDispatch } from 'react-redux';

import { importBudget } from 'loot-core/src/client/actions/budgets';

import { useNavigate } from '../../../hooks/useNavigate';
import { styles, theme } from '../../../style';
import { Block } from '../../common/Block';
import { ButtonWithLoading } from '../../common/Button2';
Expand All @@ -26,7 +27,7 @@ function getErrorMessage(error: string): string {

export function ImportYNAB5Modal() {
const { t } = useTranslation();

const navigate = useNavigate();
const dispatch = useDispatch();
const [error, setError] = useState<string | null>(null);
const [importing, setImporting] = useState(false);
Expand All @@ -41,6 +42,7 @@ export function ImportYNAB5Modal() {
setError(null);
try {
await dispatch(importBudget(res[0], 'ynab5'));
navigate('/budget');
} catch (err) {
setError(err.message);
} finally {
Expand Down
1 change: 0 additions & 1 deletion packages/loot-core/src/client/actions/budgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ export function importBudget(
dispatch(closeModal());

await dispatch(loadPrefs());
window.__navigate('/budget');
};
}

Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3904.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [joel-jeremy]
---

Use useNavigate instead of accessing window.__navigate

0 comments on commit 2c0bd6b

Please sign in to comment.