mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
9b4aebc385
* chore: show message if dragging unjoined project (#1763) * fix: invalid project selection in create issue modal (#1766) * style: sidebar project list improvement (#1767) * fix: comment reaction mutation (#1768) * fix: user profiles n plus 1 (#1765) * fix: bulk issue import (#1773) * style: profile activity (#1771) * style: profile activity comment log styling * chore: profile feed activity refactor * style: sidebar project list * chore: add non existing states for project entities (#1770) * fix: notification read status being toggled when click on link (#1769) * fix: custom theme persisting after signing out (#1780) * fix: custom theme persistence * chore: remove console logs * fix: build error * fix: change theme from command k --------- Co-authored-by: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com> Co-authored-by: Dakshesh Jain <65905942+dakshesh14@users.noreply.github.com> Co-authored-by: Anmol Singh Bhatia <121005188+anmolsinghbhatia@users.noreply.github.com>
109 lines
3.4 KiB
TypeScript
109 lines
3.4 KiB
TypeScript
import React, { useState, useEffect } from "react";
|
|
|
|
import { useRouter } from "next/router";
|
|
|
|
// next-themes
|
|
import { useTheme } from "next-themes";
|
|
// layouts
|
|
import DefaultLayout from "layouts/default-layout";
|
|
// services
|
|
import authenticationService from "services/authentication.service";
|
|
// hooks
|
|
import useUserAuth from "hooks/use-user-auth";
|
|
import useToast from "hooks/use-toast";
|
|
// types
|
|
import type { NextPage } from "next";
|
|
|
|
const MagicSignIn: NextPage = () => {
|
|
const router = useRouter();
|
|
const { password, key } = router.query;
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
const { setTheme } = useTheme();
|
|
|
|
const { mutateUser } = useUserAuth("sign-in");
|
|
|
|
const [isSigningIn, setIsSigningIn] = useState(false);
|
|
const [errorSigningIn, setErrorSignIn] = useState<string | undefined>();
|
|
|
|
useEffect(() => {
|
|
setTheme("system");
|
|
}, [setTheme]);
|
|
|
|
useEffect(() => {
|
|
setIsSigningIn(() => false);
|
|
setErrorSignIn(() => undefined);
|
|
if (!password || !key) {
|
|
setErrorSignIn("URL is invalid");
|
|
return;
|
|
} else {
|
|
setIsSigningIn(() => true);
|
|
authenticationService
|
|
.magicSignIn({ token: password, key })
|
|
.then(async (res) => {
|
|
setIsSigningIn(false);
|
|
await mutateUser();
|
|
})
|
|
.catch((err) => {
|
|
setErrorSignIn(err.response.data.error);
|
|
setIsSigningIn(false);
|
|
});
|
|
}
|
|
}, [password, key, mutateUser, router]);
|
|
|
|
return (
|
|
<DefaultLayout>
|
|
<div className="h-screen w-full overflow-auto bg-custom-background-90">
|
|
{isSigningIn ? (
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-3">
|
|
<h2 className="text-4xl font-medium">Signing you in...</h2>
|
|
<p className="text-sm font-medium text-custom-text-200">
|
|
Please wait while we are preparing your take off.
|
|
</p>
|
|
</div>
|
|
) : errorSigningIn ? (
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-3">
|
|
<h2 className="text-4xl font-medium">Error</h2>
|
|
<div className="text-sm font-medium text-custom-text-200 flex gap-2">
|
|
<div>{errorSigningIn}.</div>
|
|
<span
|
|
className="cursor-pointer underline"
|
|
onClick={() => {
|
|
authenticationService
|
|
.emailCode({ email: (key as string).split("_")[1] })
|
|
.then(() => {
|
|
setToastAlert({
|
|
type: "success",
|
|
title: "Email sent",
|
|
message: "A new link/code has been send to you.",
|
|
});
|
|
})
|
|
.catch(() => {
|
|
setToastAlert({
|
|
type: "error",
|
|
title: "Error",
|
|
message: "Unable to send email.",
|
|
});
|
|
});
|
|
}}
|
|
>
|
|
Send link again?
|
|
</span>
|
|
</div>
|
|
</div>
|
|
) : (
|
|
<div className="flex h-full w-full flex-col items-center justify-center gap-y-2">
|
|
<h2 className="text-4xl font-medium">Success</h2>
|
|
<p className="text-sm font-medium text-custom-text-200">
|
|
Redirecting you to the app...
|
|
</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</DefaultLayout>
|
|
);
|
|
};
|
|
|
|
export default MagicSignIn;
|