2024-01-19 15:25:03 +00:00
|
|
|
import { ReactElement } from "react";
|
|
|
|
import Image from "next/image";
|
2024-05-08 17:31:20 +00:00
|
|
|
import Link from "next/link";
|
2024-01-19 15:25:03 +00:00
|
|
|
import { useRouter } from "next/router";
|
2024-05-08 17:31:20 +00:00
|
|
|
import { useTheme } from "next-themes";
|
2024-01-19 15:25:03 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2024-05-08 17:31:20 +00:00
|
|
|
// icons
|
|
|
|
import { CircleCheck } from "lucide-react";
|
|
|
|
// ui
|
|
|
|
import { Button, Input, TOAST_TYPE, getButtonStyling, setToast } from "@plane/ui";
|
|
|
|
// components
|
2024-03-19 14:38:35 +00:00
|
|
|
import { PageHead } from "@/components/core";
|
2024-05-08 17:31:20 +00:00
|
|
|
// constants
|
|
|
|
import { FORGOT_PASS_LINK, NAVIGATE_TO_SIGNUP } from "@/constants/event-tracker";
|
|
|
|
// helpers
|
|
|
|
import { EPageTypes } from "@/helpers/authentication.helper";
|
|
|
|
import { cn } from "@/helpers/common.helper";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { checkEmailValidity } from "@/helpers/string.helper";
|
2024-05-08 17:31:20 +00:00
|
|
|
// hooks
|
2024-03-19 14:38:35 +00:00
|
|
|
import { useEventTracker } from "@/hooks/store";
|
|
|
|
import useTimer from "@/hooks/use-timer";
|
2024-05-08 17:31:20 +00:00
|
|
|
// layouts
|
2024-03-19 14:38:35 +00:00
|
|
|
import DefaultLayout from "@/layouts/default-layout";
|
2024-05-08 17:31:20 +00:00
|
|
|
// lib
|
2024-03-19 14:38:35 +00:00
|
|
|
import { NextPageWithLayout } from "@/lib/types";
|
2024-05-08 17:31:20 +00:00
|
|
|
// wrappers
|
|
|
|
import { AuthenticationWrapper } from "@/lib/wrappers";
|
|
|
|
// services
|
2024-03-19 14:38:35 +00:00
|
|
|
import { AuthService } from "@/services/auth.service";
|
2024-01-19 15:25:03 +00:00
|
|
|
// images
|
2024-05-08 17:31:20 +00:00
|
|
|
import PlaneBackgroundPatternDark from "public/auth/background-pattern-dark.svg";
|
|
|
|
import PlaneBackgroundPattern from "public/auth/background-pattern.svg";
|
2024-05-23 09:15:40 +00:00
|
|
|
import BlackHorizontalLogo from "public/plane-logos/black-horizontal-with-blue-logo.png";
|
|
|
|
import WhiteHorizontalLogo from "public/plane-logos/white-horizontal-with-blue-logo.png";
|
2024-01-19 15:25:03 +00:00
|
|
|
|
|
|
|
type TForgotPasswordFormValues = {
|
|
|
|
email: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultValues: TForgotPasswordFormValues = {
|
|
|
|
email: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
// services
|
|
|
|
const authService = new AuthService();
|
|
|
|
|
|
|
|
const ForgotPasswordPage: NextPageWithLayout = () => {
|
|
|
|
// router
|
|
|
|
const router = useRouter();
|
|
|
|
const { email } = router.query;
|
2024-02-09 10:52:08 +00:00
|
|
|
// store hooks
|
|
|
|
const { captureEvent } = useEventTracker();
|
2024-05-08 17:31:20 +00:00
|
|
|
// hooks
|
|
|
|
const { resolvedTheme } = useTheme();
|
2024-01-19 15:25:03 +00:00
|
|
|
// timer
|
|
|
|
const { timer: resendTimerCode, setTimer: setResendCodeTimer } = useTimer(0);
|
2024-05-08 17:31:20 +00:00
|
|
|
|
2024-01-19 15:25:03 +00:00
|
|
|
// form info
|
|
|
|
const {
|
|
|
|
control,
|
|
|
|
formState: { errors, isSubmitting, isValid },
|
|
|
|
handleSubmit,
|
|
|
|
} = useForm<TForgotPasswordFormValues>({
|
|
|
|
defaultValues: {
|
|
|
|
...defaultValues,
|
|
|
|
email: email?.toString() ?? "",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleForgotPassword = async (formData: TForgotPasswordFormValues) => {
|
|
|
|
await authService
|
|
|
|
.sendResetPasswordLink({
|
|
|
|
email: formData.email,
|
|
|
|
})
|
|
|
|
.then(() => {
|
2024-02-09 10:52:08 +00:00
|
|
|
captureEvent(FORGOT_PASS_LINK, {
|
|
|
|
state: "SUCCESS",
|
|
|
|
});
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.SUCCESS,
|
2024-01-19 15:25:03 +00:00
|
|
|
title: "Email sent",
|
|
|
|
message:
|
|
|
|
"Check your inbox for a link to reset your password. If it doesn't appear within a few minutes, check your spam folder.",
|
|
|
|
});
|
|
|
|
setResendCodeTimer(30);
|
|
|
|
})
|
2024-02-09 10:52:08 +00:00
|
|
|
.catch((err) => {
|
|
|
|
captureEvent(FORGOT_PASS_LINK, {
|
|
|
|
state: "FAILED",
|
|
|
|
});
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.ERROR,
|
2024-01-19 15:25:03 +00:00
|
|
|
title: "Error!",
|
|
|
|
message: err?.error ?? "Something went wrong. Please try again.",
|
2024-02-09 10:52:08 +00:00
|
|
|
});
|
|
|
|
});
|
2024-01-19 15:25:03 +00:00
|
|
|
};
|
|
|
|
|
2024-05-22 13:19:58 +00:00
|
|
|
const logo = resolvedTheme === "light" ? BlackHorizontalLogo : WhiteHorizontalLogo;
|
|
|
|
|
2024-01-19 15:25:03 +00:00
|
|
|
return (
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="relative w-screen h-screen overflow-hidden">
|
2024-05-22 13:19:58 +00:00
|
|
|
<PageHead title="Forgot Password - Plane" />
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="absolute inset-0 z-0">
|
|
|
|
<Image
|
|
|
|
src={resolvedTheme === "dark" ? PlaneBackgroundPatternDark : PlaneBackgroundPattern}
|
|
|
|
className="w-full h-full object-cover"
|
|
|
|
alt="Plane background pattern"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="relative z-10 w-screen h-screen overflow-hidden overflow-y-auto flex flex-col">
|
|
|
|
<div className="container mx-auto px-10 lg:px-0 flex-shrink-0 relative flex items-center justify-between pb-4 transition-all">
|
2024-02-20 08:06:38 +00:00
|
|
|
<div className="flex items-center gap-x-2 py-10">
|
2024-05-22 13:19:58 +00:00
|
|
|
<Link href={`/`} className="h-[30px] w-[133px]">
|
|
|
|
<Image src={logo} alt="Plane logo" />
|
|
|
|
</Link>
|
2024-02-20 08:06:38 +00:00
|
|
|
</div>
|
2024-05-16 18:05:53 +00:00
|
|
|
<div className="flex flex-col items-end sm:items-center sm:gap-2 sm:flex-row text-center text-sm font-medium text-onboarding-text-300">
|
2024-05-08 17:31:20 +00:00
|
|
|
New to Plane?{" "}
|
|
|
|
<Link
|
|
|
|
href="/"
|
|
|
|
onClick={() => captureEvent(NAVIGATE_TO_SIGNUP, {})}
|
|
|
|
className="font-semibold text-custom-primary-100 hover:underline"
|
|
|
|
>
|
|
|
|
Create an account
|
|
|
|
</Link>
|
|
|
|
</div>
|
2024-01-19 15:25:03 +00:00
|
|
|
</div>
|
2024-05-08 17:31:20 +00:00
|
|
|
<div className="flex-grow container mx-auto max-w-lg px-10 lg:max-w-md lg:px-5 py-10 lg:pt-28 transition-all">
|
|
|
|
<div className="relative flex flex-col space-y-6">
|
|
|
|
<div className="text-center space-y-1 py-4">
|
|
|
|
<h3 className="flex gap-4 justify-center text-3xl font-bold text-onboarding-text-100">
|
|
|
|
Reset your password
|
|
|
|
</h3>
|
|
|
|
<p className="font-medium text-onboarding-text-400">
|
|
|
|
Enter your user account{"'"}s verified email address and we will send you a password reset link.
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<form onSubmit={handleSubmit(handleForgotPassword)} className="mt-5 space-y-4">
|
|
|
|
<div className="space-y-1">
|
|
|
|
<label className="text-sm text-onboarding-text-300 font-medium" htmlFor="email">
|
|
|
|
Email
|
|
|
|
</label>
|
2024-02-20 08:06:38 +00:00
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="email"
|
|
|
|
rules={{
|
|
|
|
required: "Email is required",
|
|
|
|
validate: (value) => checkEmailValidity(value) || "Email is invalid",
|
|
|
|
}}
|
|
|
|
render={({ field: { value, onChange, ref } }) => (
|
|
|
|
<Input
|
|
|
|
id="email"
|
|
|
|
name="email"
|
|
|
|
type="email"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
ref={ref}
|
|
|
|
hasError={Boolean(errors.email)}
|
|
|
|
placeholder="name@company.com"
|
|
|
|
className="h-[46px] w-full border border-onboarding-border-100 !bg-onboarding-background-200 pr-12 placeholder:text-onboarding-text-400"
|
2024-05-08 17:31:20 +00:00
|
|
|
disabled={resendTimerCode > 0}
|
2024-02-20 08:06:38 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2024-05-08 17:31:20 +00:00
|
|
|
{resendTimerCode > 0 && (
|
|
|
|
<p className="flex w-full items-start px-1 gap-1 text-xs font-medium text-green-700">
|
|
|
|
<CircleCheck height={12} width={12} className="mt-0.5" />
|
|
|
|
We sent the reset link to your email address
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
type="submit"
|
|
|
|
variant="primary"
|
|
|
|
className="w-full"
|
|
|
|
size="lg"
|
|
|
|
disabled={!isValid}
|
|
|
|
loading={isSubmitting || resendTimerCode > 0}
|
|
|
|
>
|
|
|
|
{resendTimerCode > 0 ? `Resend in ${resendTimerCode} seconds` : "Send reset link"}
|
|
|
|
</Button>
|
2024-05-22 12:01:56 +00:00
|
|
|
<Link href="/" className={cn("w-full", getButtonStyling("link-neutral", "lg"))}>
|
2024-05-08 17:31:20 +00:00
|
|
|
Back to sign in
|
|
|
|
</Link>
|
|
|
|
</form>
|
2024-01-19 15:25:03 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-05-08 17:31:20 +00:00
|
|
|
</div>
|
2024-01-19 15:25:03 +00:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ForgotPasswordPage.getLayout = function getLayout(page: ReactElement) {
|
2024-05-08 17:31:20 +00:00
|
|
|
return (
|
|
|
|
<DefaultLayout>
|
|
|
|
<AuthenticationWrapper pageType={EPageTypes.NON_AUTHENTICATED}>{page}</AuthenticationWrapper>
|
|
|
|
</DefaultLayout>
|
|
|
|
);
|
2024-01-19 15:25:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export default ForgotPasswordPage;
|