import { useState, useEffect, useCallback } from "react"; import Link from "next/link"; import { observer } from "mobx-react-lite"; import Image from "next/image"; import { useTheme } from "next-themes"; import { useRouter } from "next/router"; import { Lightbulb } from "lucide-react"; // mobx store import { useMobxStore } from "lib/mobx/store-provider"; // components import { SignInRoot } from "components/account"; // ui import { Loader, Spinner } from "@plane/ui"; // images import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png"; import signInIssues from "public/onboarding/onboarding-issues.svg"; // types import { IUser, IUserSettings } from "types"; export type AuthType = "sign-in" | "sign-up"; export const SignInView = observer(() => { // store const { user: { fetchCurrentUser, fetchCurrentUserSettings }, appConfig: { envConfig }, } = useMobxStore(); // router const router = useRouter(); const { next: next_url } = router.query; // states const [isLoading, setLoading] = useState(false); // next-themes const { resolvedTheme } = useTheme(); const handleSignInRedirection = useCallback( async (user: IUser) => { // if the user is not onboarded, redirect them to the onboarding page if (!user.is_onboarded) { router.push("/onboarding"); return; } // if next_url is provided, redirect the user to that url if (next_url) { router.push(next_url.toString()); return; } // if the user is onboarded, fetch their last workspace details await fetchCurrentUserSettings() .then((userSettings: IUserSettings) => { const workspaceSlug = userSettings?.workspace?.last_workspace_slug || userSettings?.workspace?.fallback_workspace_slug; if (workspaceSlug) router.push(`/${workspaceSlug}`); else router.push("/profile"); }) .catch(() => setLoading(false)); }, [fetchCurrentUserSettings, router, next_url] ); const mutateUserInfo = useCallback(async () => { await fetchCurrentUser().then(async (user) => { await handleSignInRedirection(user); }); }, [fetchCurrentUser, handleSignInRedirection]); useEffect(() => { mutateUserInfo(); }, [mutateUserInfo]); return ( <> {isLoading ? (
Pages gets a facelift! Write anything and use Galileo to help you start.{" "} Learn more