import React from "react"; import { useRouter } from "next/router"; import Image from "next/image"; // react-hook-form import { 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 { Input, SecondaryButton } from "components/ui"; // icons import Logo from "public/logo.png"; // types import type { NextPage } from "next"; type FormData = { password: string; confirmPassword: string; }; const ResetPasswordPage: NextPage = () => { const router = useRouter(); const { uidb64, token } = router.query; const { setToastAlert } = useToast(); const { register, handleSubmit, 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.", }) ); }; return (
Plane Web Logo

Reset your password

{isSubmitting ? "Resetting..." : "Reset"}
); }; export default ResetPasswordPage;