Introduce account preferences to remember user's previous location (#4126)

This commit is contained in:
Apoorv Mishra
2022-09-18 18:31:47 +05:30
committed by GitHub
parent b68e58fad5
commit 6502b108e3
17 changed files with 156 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ import PageTitle from "~/components/PageTitle";
import TeamLogo from "~/components/TeamLogo";
import Text from "~/components/Text";
import env from "~/env";
import useLastVisitedPath from "~/hooks/useLastVisitedPath";
import useQuery from "~/hooks/useQuery";
import useStores from "~/hooks/useStores";
import isCloudHosted from "~/utils/isCloudHosted";
@@ -62,6 +63,9 @@ function Login({ children }: Props) {
const [error, setError] = React.useState(null);
const [emailLinkSentTo, setEmailLinkSentTo] = React.useState("");
const isCreate = location.pathname === "/create";
const rememberLastPath = !!auth.user?.preferences?.rememberLastPath;
const [lastVisitedPath] = useLastVisitedPath();
const handleReset = React.useCallback(() => {
setEmailLinkSentTo("");
}, []);
@@ -91,6 +95,14 @@ function Login({ children }: Props) {
}
}, [query]);
if (
auth.authenticated &&
rememberLastPath &&
lastVisitedPath !== location.pathname
) {
return <Redirect to={lastVisitedPath} />;
}
if (auth.authenticated && auth.team?.defaultCollectionId) {
return <Redirect to={`/collection/${auth.team?.defaultCollectionId}`} />;
}