forked from github/plane
1e152c666c
* chore: moved app & space from apps to root * chore: modified workspace configuration * chore: modified dockerfiles for space and web * chore: modified icons for space * feat: updated files for new svg icons supported by next-images * chore: added /spaces base path for next * chore: added compose config for space * chore: updated husky configuration * chore: updated workflows for new configuration * chore: changed app name to web * fix: resolved build errors with web * chore: reset file tracing root for both projects * chore: added nginx config for deploy * fix: eslint and tsconfig settings for space app * husky setup fixes based on new dir * eslint fixes * prettier formatting --------- Co-authored-by: Henit Chobisa <chobisa.henit@gmail.com>
107 lines
2.8 KiB
TypeScript
107 lines
2.8 KiB
TypeScript
import React, { useEffect, useState } from "react";
|
|
|
|
import Image from "next/image";
|
|
import { useRouter } from "next/router";
|
|
|
|
// next-themes
|
|
import { useTheme } from "next-themes";
|
|
// services
|
|
import authenticationService from "services/authentication.service";
|
|
// hooks
|
|
import useUserAuth from "hooks/use-user-auth";
|
|
import useToast from "hooks/use-toast";
|
|
// layouts
|
|
import DefaultLayout from "layouts/default-layout";
|
|
// components
|
|
import { EmailPasswordForm } from "components/account";
|
|
// ui
|
|
import { Spinner } from "components/ui";
|
|
// images
|
|
import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png";
|
|
// types
|
|
import type { NextPage } from "next";
|
|
type EmailPasswordFormValues = {
|
|
email: string;
|
|
password?: string;
|
|
medium?: string;
|
|
};
|
|
|
|
const SignUp: NextPage = () => {
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
const router = useRouter();
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
const { setTheme } = useTheme();
|
|
|
|
const { mutateUser } = useUserAuth("sign-in");
|
|
|
|
const handleSignUp = async (formData: EmailPasswordFormValues) => {
|
|
const payload = {
|
|
email: formData.email,
|
|
password: formData.password ?? "",
|
|
};
|
|
|
|
await authenticationService
|
|
.emailSignUp(payload)
|
|
.then(async (response) => {
|
|
setToastAlert({
|
|
type: "success",
|
|
title: "Success!",
|
|
message: "Account created successfully.",
|
|
});
|
|
|
|
if (response) await mutateUser();
|
|
router.push("/");
|
|
})
|
|
.catch((err) =>
|
|
setToastAlert({
|
|
type: "error",
|
|
title: "Error!",
|
|
message:
|
|
err?.error ||
|
|
"Something went wrong. Please try again later or contact the support team.",
|
|
})
|
|
);
|
|
};
|
|
|
|
useEffect(() => {
|
|
setTheme("system");
|
|
}, [setTheme]);
|
|
|
|
useEffect(() => {
|
|
if (parseInt(process.env.NEXT_PUBLIC_ENABLE_OAUTH || "0")) router.push("/");
|
|
else setIsLoading(false);
|
|
}, [router]);
|
|
|
|
if (isLoading)
|
|
return (
|
|
<div className="grid place-items-center h-screen w-full">
|
|
<Spinner />
|
|
</div>
|
|
);
|
|
|
|
return (
|
|
<DefaultLayout>
|
|
<>
|
|
<div className="hidden sm:block sm:fixed border-r-[0.5px] border-custom-border-200 h-screen w-[0.5px] top-0 left-20 lg:left-32" />
|
|
<div className="fixed grid place-items-center bg-custom-background-100 sm:py-5 top-11 sm:top-12 left-7 sm:left-16 lg:left-28">
|
|
<div className="grid place-items-center bg-custom-background-100">
|
|
<div className="h-[30px] w-[30px]">
|
|
<Image src={BluePlaneLogoWithoutText} alt="Plane Logo" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</>
|
|
<div className="grid place-items-center h-full w-full overflow-y-auto py-5 px-7">
|
|
<div>
|
|
<EmailPasswordForm onSubmit={handleSignUp} />
|
|
</div>
|
|
</div>
|
|
</DefaultLayout>
|
|
);
|
|
};
|
|
|
|
export default SignUp;
|