import { FC } from "react"; import { useForm, Controller } from "react-hook-form"; // ui import { Input, Button } from "@plane/ui"; // icons import { XCircle } from "lucide-react"; // services import { AuthService } from "services/auth.service"; const authService = new AuthService(); // hooks import useToast from "hooks/use-toast"; import useTimer from "hooks/use-timer"; export interface InstanceSetupEmailCodeFormValues { email: string; token: string; } export interface IInstanceSetupEmailCodeForm { email: string; handleNextStep: () => void; moveBack: () => void; } export const InstanceSetupEmailCodeForm: FC = (props) => { const { handleNextStep, email, moveBack } = props; // form info const { control, handleSubmit, reset, formState: { isSubmitting }, } = useForm({ defaultValues: { email, token: "", }, }); // hooks const { setToastAlert } = useToast(); const { timer, setTimer } = useTimer(30); // computed const isResendDisabled = timer > 0 || isSubmitting; const handleEmailCodeFormSubmit = (formValues: InstanceSetupEmailCodeFormValues) => authService .instanceMagicSignIn({ key: `magic_${formValues.email}`, token: formValues.token }) .then(() => { reset(); handleNextStep(); }) .catch((err) => { setToastAlert({ title: "Oops!", type: "error", message: err?.error, }); }); const resendMagicCode = () => { setTimer(30); authService .instanceAdminEmailCode({ email }) .then(() => { // setCodeResending(false); setTimer(30); }) .catch((err) => { setToastAlert({ title: "Oops!", type: "error", message: err?.error, }); }); }; return (

Let’s secure your instance

Paste the code you got at

{email} below.
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test( value ) || "Email address is not valid", }} render={({ field: { value, onChange } }) => (
moveBack()} />
)} />
{timer > 0 ? ( Request new code in {timer}s ) : isSubmitting ? ( "Sending new code..." ) : (
)}
(
)} />
); };