From c34eba35468b75b72821af23faf456d5cec7864e Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Mon, 25 Nov 2024 20:16:42 -0800 Subject: [PATCH 1/3] Use useNavigate instead of accessing window.__navigate --- packages/desktop-client/src/components/LoggedInUser.tsx | 9 ++++++--- .../src/components/manager/ConfigServer.tsx | 6 ++++-- .../src/components/modals/manager/ImportActualModal.tsx | 4 +++- .../src/components/modals/manager/ImportYNAB4Modal.tsx | 4 +++- .../src/components/modals/manager/ImportYNAB5Modal.tsx | 4 +++- packages/loot-core/src/client/actions/budgets.ts | 1 - 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/desktop-client/src/components/LoggedInUser.tsx b/packages/desktop-client/src/components/LoggedInUser.tsx index ec7df311bbf..8ad160f2294 100644 --- a/packages/desktop-client/src/components/LoggedInUser.tsx +++ b/packages/desktop-client/src/components/LoggedInUser.tsx @@ -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'; @@ -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) { @@ -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: } diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx index 44b13d2e61a..a1c43d739e6 100644 --- a/packages/desktop-client/src/components/manager/ConfigServer.tsx +++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx @@ -111,7 +111,6 @@ export function ConfigServer() { async function onCreateTestFile() { await setServerUrl(null); await createBudget({ testMode: true }); - window.__navigate('/'); } return ( @@ -250,7 +249,10 @@ export function ConfigServer() { diff --git a/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx b/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx index d1041250caf..ac31b5757b2 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportActualModal.tsx @@ -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'; @@ -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(null); const [importing, setImporting] = useState(false); @@ -46,6 +47,7 @@ export function ImportActualModal() { setError(null); try { await dispatch(importBudget(res[0], 'actual')); + navigate('/budget'); } catch (err) { setError(err.message); } finally { diff --git a/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx b/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx index 3d02baa794a..2c0a52b9318 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportYNAB4Modal.tsx @@ -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'; @@ -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(null); const [importing, setImporting] = useState(false); @@ -38,6 +39,7 @@ export function ImportYNAB4Modal() { setError(null); try { await dispatch(importBudget(res[0], 'ynab4')); + navigate('/budget'); } catch (err) { setError(err.message); } finally { diff --git a/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx b/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx index a17d9ab74b5..98ee2f49fac 100644 --- a/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx +++ b/packages/desktop-client/src/components/modals/manager/ImportYNAB5Modal.tsx @@ -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'; @@ -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(null); const [importing, setImporting] = useState(false); @@ -41,6 +42,7 @@ export function ImportYNAB5Modal() { setError(null); try { await dispatch(importBudget(res[0], 'ynab5')); + navigate('/budget'); } catch (err) { setError(err.message); } finally { diff --git a/packages/loot-core/src/client/actions/budgets.ts b/packages/loot-core/src/client/actions/budgets.ts index 96dc92434a2..5ce240a64b8 100644 --- a/packages/loot-core/src/client/actions/budgets.ts +++ b/packages/loot-core/src/client/actions/budgets.ts @@ -161,7 +161,6 @@ export function importBudget( dispatch(closeModal()); await dispatch(loadPrefs()); - window.__navigate('/budget'); }; } From ba964402d4be08834a84ed4606c61c32f2154d83 Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Mon, 25 Nov 2024 20:17:31 -0800 Subject: [PATCH 2/3] Release notes --- upcoming-release-notes/3904.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/3904.md diff --git a/upcoming-release-notes/3904.md b/upcoming-release-notes/3904.md new file mode 100644 index 00000000000..2dcbcab90c9 --- /dev/null +++ b/upcoming-release-notes/3904.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [joel-jeremy] +--- + +Use useNavigate instead of accessing window.__navigate From aba6e97fb65d48860cdb1858b2524966d977e3a6 Mon Sep 17 00:00:00 2001 From: Joel Jeremy Marquez Date: Tue, 26 Nov 2024 13:31:36 -0800 Subject: [PATCH 3/3] Update packages/desktop-client/src/components/manager/ConfigServer.tsx Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../desktop-client/src/components/manager/ConfigServer.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/manager/ConfigServer.tsx b/packages/desktop-client/src/components/manager/ConfigServer.tsx index a1c43d739e6..e69e4e16f2b 100644 --- a/packages/desktop-client/src/components/manager/ConfigServer.tsx +++ b/packages/desktop-client/src/components/manager/ConfigServer.tsx @@ -249,8 +249,8 @@ export function ConfigServer() {