Skip to content

Commit bde9d5f

Browse files
Move post-login redirect logic to AuthenticatedLayout (outline#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 <tom.moor@gmail.com>
1 parent 70bb878 commit bde9d5f

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

app/components/AuthenticatedLayout.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { AnimatePresence } from "framer-motion";
22
import { observer } from "mobx-react";
33
import * as React from "react";
4-
import { Switch, Route, useLocation, matchPath } from "react-router-dom";
4+
import {
5+
Switch,
6+
Route,
7+
useLocation,
8+
matchPath,
9+
Redirect,
10+
} from "react-router-dom";
511
import { TeamPreference } from "@shared/types";
612
import ErrorSuspended from "~/scenes/Errors/ErrorSuspended";
713
import Layout from "~/components/Layout";
@@ -10,6 +16,7 @@ import Sidebar from "~/components/Sidebar";
1016
import SidebarRight from "~/components/Sidebar/Right";
1117
import SettingsSidebar from "~/components/Sidebar/Settings";
1218
import useCurrentTeam from "~/hooks/useCurrentTeam";
19+
import { usePostLoginPath } from "~/hooks/useLastVisitedPath";
1320
import usePolicy from "~/hooks/usePolicy";
1421
import useStores from "~/hooks/useStores";
1522
import history from "~/utils/history";
@@ -48,6 +55,7 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => {
4855
const can = usePolicy(ui.activeDocumentId);
4956
const canCollection = usePolicy(ui.activeCollectionId);
5057
const team = useCurrentTeam();
58+
const [spendPostLoginPath] = usePostLoginPath();
5159

5260
const goToSearch = (ev: KeyboardEvent) => {
5361
if (!ev.metaKey && !ev.ctrlKey) {
@@ -72,6 +80,11 @@ const AuthenticatedLayout: React.FC = ({ children }: Props) => {
7280
return <ErrorSuspended />;
7381
}
7482

83+
const postLoginPath = spendPostLoginPath();
84+
if (postLoginPath) {
85+
return <Redirect to={postLoginPath} />;
86+
}
87+
7588
const sidebar = (
7689
<Fade>
7790
<Switch>

app/scenes/Home.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { observer } from "mobx-react";
22
import { HomeIcon } from "outline-icons";
33
import * as React from "react";
44
import { useTranslation } from "react-i18next";
5-
import { Switch, Route, Redirect } from "react-router-dom";
5+
import { Switch, Route } from "react-router-dom";
66
import styled from "styled-components";
77
import { s } from "@shared/styles";
88
import { Action } from "~/components/Actions";
@@ -18,7 +18,6 @@ import Tab from "~/components/Tab";
1818
import Tabs from "~/components/Tabs";
1919
import useCurrentTeam from "~/hooks/useCurrentTeam";
2020
import useCurrentUser from "~/hooks/useCurrentUser";
21-
import { usePostLoginPath } from "~/hooks/useLastVisitedPath";
2221
import { usePinnedDocuments } from "~/hooks/usePinnedDocuments";
2322
import usePolicy from "~/hooks/usePolicy";
2423
import useStores from "~/hooks/useStores";
@@ -29,16 +28,10 @@ function Home() {
2928
const team = useCurrentTeam();
3029
const user = useCurrentUser();
3130
const { t } = useTranslation();
32-
const [spendPostLoginPath] = usePostLoginPath();
3331
const userId = user?.id;
3432
const { pins, count } = usePinnedDocuments("home");
3533
const can = usePolicy(team);
3634

37-
const postLoginPath = spendPostLoginPath();
38-
if (postLoginPath) {
39-
return <Redirect to={postLoginPath} />;
40-
}
41-
4235
return (
4336
<Scene
4437
icon={<HomeIcon />}

0 commit comments

Comments
 (0)