import { FC, useState } 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; // states const [isResendingCode, setIsResendingCode] = useState(false); // 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 || isResendingCode; const handleEmailCodeFormSubmit = async (formValues: InstanceSetupEmailCodeFormValues) => await authService .instanceMagicSignIn({ key: `magic_${formValues.email}`, token: formValues.token }) .then(() => { reset(); handleNextStep(); }) .catch((err) => { setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }); }); const resendMagicCode = async () => { setIsResendingCode(true); await authService .instanceAdminEmailCode({ email }) .then(() => setTimer(30)) .catch((err) => { setToastAlert({ type: "error", title: "Error!", message: err?.error ?? "Something went wrong. Please try again.", }); }) .finally(() => setIsResendingCode(false)); }; 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()} />
)} />
(
)} />
); };