import React from "react"; import { Controller, useForm } from "react-hook-form"; // services import { AuthService } from "services/auth.service"; // hooks import useToast from "hooks/use-toast"; // ui import { Button, Input } from "@plane/ui"; // helpers import { checkEmailValidity } from "helpers/string.helper"; // constants import { ESignInSteps } from "components/account"; type Props = { email: string; handleStepChange: (step: ESignInSteps) => void; handleSignInRedirection: () => Promise; }; type TCreatePasswordFormValues = { email: string; password: string; }; const defaultValues: TCreatePasswordFormValues = { email: "", password: "", }; // services const authService = new AuthService(); export const CreatePasswordForm: React.FC = (props) => { const { email, handleSignInRedirection } = props; // toast alert const { setToastAlert } = useToast(); // form info const { control, formState: { errors, isSubmitting, isValid }, handleSubmit, } = useForm({ defaultValues: { ...defaultValues, email, }, mode: "onChange", reValidateMode: "onChange", }); const handleCreatePassword = async (formData: TCreatePasswordFormValues) => { const payload = { password: formData.password, }; await authService .setPassword(payload) .then(async () => { setToastAlert({ type: "success", title: "Success!", message: "Password created successfully.", }); await handleSignInRedirection(); }) .catch((err) => setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }) ); }; return ( <>

Let{"'"}s get a new password

checkEmailValidity(value) || "Email is invalid", }} render={({ field: { value, onChange, ref } }) => ( )} />
( )} />

Whatever you choose now will be your account{"'"}s password until you change it.

); };