Introduce account preferences to remember user's previous location (#4126)
This commit is contained in:
@@ -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}`} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user