forked from github/plane
fd5b7d20a8
* chore: instance type updated * chore: instance not ready screen added * chore: instance layout added * chore: instance magic sign in endpoint and type added * chore: instance admin password endpoint added * chore: instance setup page added * chore: instance setup form added * chore: instance layout updated * fix: instance admin workflow setup * fix: admin workflow setup --------- Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
106 lines
3.4 KiB
TypeScript
106 lines
3.4 KiB
TypeScript
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";
|
||
|
||
export interface InstanceSetupEmailFormValues {
|
||
email: string;
|
||
}
|
||
|
||
export interface IInstanceSetupEmailForm {
|
||
handleNextStep: (email: string) => void;
|
||
}
|
||
|
||
export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
|
||
const { handleNextStep } = props;
|
||
// form info
|
||
const {
|
||
control,
|
||
handleSubmit,
|
||
setValue,
|
||
reset,
|
||
formState: { isSubmitting },
|
||
} = useForm<InstanceSetupEmailFormValues>({
|
||
defaultValues: {
|
||
email: "",
|
||
},
|
||
});
|
||
// hooks
|
||
const { setToastAlert } = useToast();
|
||
|
||
const handleEmailFormSubmit = (formValues: InstanceSetupEmailFormValues) =>
|
||
authService
|
||
.instanceAdminEmailCode({ email: formValues.email })
|
||
.then(() => {
|
||
reset();
|
||
handleNextStep(formValues.email);
|
||
})
|
||
.catch((err) => {
|
||
setToastAlert({
|
||
title: "Oops!",
|
||
type: "error",
|
||
message: err?.error,
|
||
});
|
||
});
|
||
|
||
return (
|
||
<form onSubmit={handleSubmit(handleEmailFormSubmit)}>
|
||
<div className="pb-2">
|
||
<h1 className="text-center text-2xl sm:text-2.5xl font-semibold text-onboarding-text-100">
|
||
Let’s secure your instance
|
||
</h1>
|
||
<p className="text-center text-sm text-onboarding-text-200 mt-3">
|
||
Explore privacy options. Get AI features. Secure access. <br /> Takes 2 minutes.
|
||
</p>
|
||
|
||
<div className="relative mt-10 w-full sm:w-[360px] mx-auto">
|
||
<Controller
|
||
name="email"
|
||
control={control}
|
||
rules={{
|
||
required: "Email address is required",
|
||
validate: (value) =>
|
||
/^(([^<>()[\]\\.,;:\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 } }) => (
|
||
<div className={`flex items-center relative rounded-md bg-onboarding-background-200`}>
|
||
<Input
|
||
id="email"
|
||
name="email"
|
||
type="email"
|
||
value={value}
|
||
onChange={onChange}
|
||
placeholder="orville.wright@firstflight.com"
|
||
className={`w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12`}
|
||
/>
|
||
{value.length > 0 && (
|
||
<XCircle
|
||
className="h-5 w-5 absolute stroke-custom-text-400 hover:cursor-pointer right-3"
|
||
onClick={() => setValue("email", "")}
|
||
/>
|
||
)}
|
||
</div>
|
||
)}
|
||
/>
|
||
<p className="text-xs text-custom-text-400 mt-0 py-2">
|
||
Use your email address if you are the instance admin. <br /> Use your admin’s e-mail if you are not.
|
||
</p>
|
||
|
||
<Button variant="primary" className="w-full mt-4" size="xl" type="submit" loading={isSubmitting}>
|
||
{isSubmitting ? "Sending code..." : "Send unique code"}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
</form>
|
||
);
|
||
};
|