import React, { useEffect, useState, ReactElement } from "react"; import { useRouter } from "next/router"; import Image from "next/image"; import { useTheme } from "next-themes"; import { Controller, useForm } from "react-hook-form"; // hooks import useToast from "hooks/use-toast"; // services import { UserService } from "services/user.service"; // layouts import DefaultLayout from "layouts/default-layout"; // ui import { Button, Input, Spinner } from "@plane/ui"; // images import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png"; // types import { NextPageWithLayout } from "types/app"; type FormData = { password: string; confirmPassword: string; }; // services const userService = new UserService(); const ResetPasswordPage: NextPageWithLayout = () => { const [isLoading, setIsLoading] = useState(true); const router = useRouter(); const { uidb64, token } = router.query; const { setToastAlert } = useToast(); const { setTheme } = useTheme(); const { handleSubmit, control, formState: { errors, isSubmitting }, } = useForm(); const onSubmit = async (formData: FormData) => { if (!uidb64 || !token) return; if (formData.password !== formData.confirmPassword) { setToastAlert({ type: "error", title: "Error!", message: "Passwords do not match.", }); return; } const payload = { new_password: formData.password, confirm_password: formData.confirmPassword, }; await userService .resetPassword(uidb64.toString(), token.toString(), payload) .then(() => { setToastAlert({ type: "success", title: "Success!", message: "Password reset successfully. You can now login with your new password.", }); 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 (
); return ( <>
Plane Logo

Reset your password

( )} />
( )} />
); }; ResetPasswordPage.getLayout = function getLayout(page: ReactElement) { return {page}; }; export default ResetPasswordPage;