2024-05-16 04:03:43 +05:30
|
|
|
"use client";
|
2025-09-17 18:52:35 +05:30
|
|
|
import { useEffect } from "react";
|
2024-06-20 14:08:52 +05:30
|
|
|
import { observer } from "mobx-react";
|
2025-09-17 18:52:35 +05:30
|
|
|
import { useSearchParams, useRouter } from "next/navigation";
|
|
|
|
|
// plane imports
|
|
|
|
|
import { isValidNextPath } from "@plane/utils";
|
2024-05-14 14:26:54 +05:30
|
|
|
// components
|
2025-08-15 13:12:36 +05:30
|
|
|
import { UserLoggedIn } from "@/components/account/user-logged-in";
|
|
|
|
|
import { LogoSpinner } from "@/components/common/logo-spinner";
|
2024-05-14 14:26:54 +05:30
|
|
|
import { AuthView } from "@/components/views";
|
2024-05-16 04:03:43 +05:30
|
|
|
// hooks
|
2025-08-15 13:12:36 +05:30
|
|
|
import { useUser } from "@/hooks/store/use-user";
|
2024-05-14 14:26:54 +05:30
|
|
|
|
2024-05-23 14:27:16 +05:30
|
|
|
const HomePage = observer(() => {
|
2025-08-06 22:32:52 +05:30
|
|
|
const { data: currentUser, isAuthenticated, isInitializing } = useUser();
|
2025-09-17 18:52:35 +05:30
|
|
|
const searchParams = useSearchParams();
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
const nextPath = searchParams.get("next_path");
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (currentUser && isAuthenticated && nextPath && isValidNextPath(nextPath)) {
|
|
|
|
|
router.replace(nextPath);
|
|
|
|
|
}
|
|
|
|
|
}, [currentUser, isAuthenticated, nextPath, router]);
|
2024-05-14 14:26:54 +05:30
|
|
|
|
2025-08-06 22:32:52 +05:30
|
|
|
if (isInitializing)
|
2025-08-06 22:24:47 +05:30
|
|
|
return (
|
2025-08-06 22:32:52 +05:30
|
|
|
<div className="flex h-screen min-h-[500px] w-full justify-center items-center">
|
2025-08-06 22:24:47 +05:30
|
|
|
<LogoSpinner />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2024-05-16 04:03:43 +05:30
|
|
|
|
2025-09-17 18:52:35 +05:30
|
|
|
if (currentUser && isAuthenticated) {
|
|
|
|
|
if (nextPath && isValidNextPath(nextPath)) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex h-screen min-h-[500px] w-full justify-center items-center">
|
|
|
|
|
<LogoSpinner />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return <UserLoggedIn />;
|
|
|
|
|
}
|
2024-05-14 14:26:54 +05:30
|
|
|
|
2024-05-15 02:25:38 +05:30
|
|
|
return <AuthView />;
|
2024-05-23 14:27:16 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default HomePage;
|