From bde9d5fbf4a45cea084b1ec6cb38ef5edbff5902 Mon Sep 17 00:00:00 2001 From: "codegen-sh[bot]" <131295404+codegen-sh[bot]@users.noreply.github.com> Date: Tue, 1 Apr 2025 17:37:22 -0700 Subject: [PATCH] Move post-login redirect logic to AuthenticatedLayout (#8864) * Move post-login redirect logic to AuthenticatedLayout * Applied automatic fixes * fix typography * Restore Login/index.tsx --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor --- app/components/AuthenticatedLayout.tsx | 15 ++++++++++++++- app/scenes/Home.tsx | 9 +-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/components/AuthenticatedLayout.tsx b/app/components/AuthenticatedLayout.tsx index c51a16b545..c167fa42af 100644 --- a/app/components/AuthenticatedLayout.tsx +++ b/app/components/AuthenticatedLayout.tsx @@ -1,7 +1,13 @@ import { AnimatePresence } from "framer-motion"; import { observer } from "mobx-react"; import * as React from "react"; -import { Switch, Route, useLocation, matchPath } from "react-router-dom"; +import { + Switch, + Route, + useLocation, + matchPath, + Redirect, +} from "react-router-dom"; import { TeamPreference } from "@shared/types"; import ErrorSuspended from "~/scenes/Errors/ErrorSuspended"; import Layout from "~/components/Layout"; @@ -10,6 +16,7 @@ import Sidebar from "~/components/Sidebar"; import SidebarRight from "~/components/Sidebar/Right"; import SettingsSidebar from "~/components/Sidebar/Settings"; import useCurrentTeam from "~/hooks/useCurrentTeam"; +import { usePostLoginPath } from "~/hooks/useLastVisitedPath"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; import history from "~/utils/history"; @@ -48,6 +55,7 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => { const can = usePolicy(ui.activeDocumentId); const canCollection = usePolicy(ui.activeCollectionId); const team = useCurrentTeam(); + const [spendPostLoginPath] = usePostLoginPath(); const goToSearch = (ev: KeyboardEvent) => { if (!ev.metaKey && !ev.ctrlKey) { @@ -72,6 +80,11 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => { return ; } + const postLoginPath = spendPostLoginPath(); + if (postLoginPath) { + return ; + } + const sidebar = ( diff --git a/app/scenes/Home.tsx b/app/scenes/Home.tsx index b2c5d27cdc..9ac150d9cc 100644 --- a/app/scenes/Home.tsx +++ b/app/scenes/Home.tsx @@ -2,7 +2,7 @@ import { observer } from "mobx-react"; import { HomeIcon } from "outline-icons"; import * as React from "react"; import { useTranslation } from "react-i18next"; -import { Switch, Route, Redirect } from "react-router-dom"; +import { Switch, Route } from "react-router-dom"; import styled from "styled-components"; import { s } from "@shared/styles"; import { Action } from "~/components/Actions"; @@ -18,7 +18,6 @@ import Tab from "~/components/Tab"; import Tabs from "~/components/Tabs"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useCurrentUser from "~/hooks/useCurrentUser"; -import { usePostLoginPath } from "~/hooks/useLastVisitedPath"; import { usePinnedDocuments } from "~/hooks/usePinnedDocuments"; import usePolicy from "~/hooks/usePolicy"; import useStores from "~/hooks/useStores"; @@ -29,16 +28,10 @@ function Home() { const team = useCurrentTeam(); const user = useCurrentUser(); const { t } = useTranslation(); - const [spendPostLoginPath] = usePostLoginPath(); const userId = user?.id; const { pins, count } = usePinnedDocuments("home"); const can = usePolicy(team); - const postLoginPath = spendPostLoginPath(); - if (postLoginPath) { - return ; - } - return ( }