import React, { useEffect } from "react"; import Link from "next/link"; import { Controller, useForm } from "react-hook-form"; // services import { AuthService } from "services/authentication.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/accounts"; type Props = { email: string; handleStepChange: (step: ESignInSteps) => void; handleSignInRedirection: () => Promise; isOnboarded: boolean; }; 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, isOnboarded } = props; // toast alert const { setToastAlert } = useToast(); // form info const { control, formState: { errors, isSubmitting, isValid }, setFocus, 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.", }) ); }; useEffect(() => { setFocus("password"); }, [setFocus]); return ( <>

Get on your flight deck

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

When you click the button above, you agree with our{" "} terms and conditions of service.

); };