2023-11-29 15:03:08 +00:00
|
|
|
|
import { FC } from "react";
|
|
|
|
|
import { useForm, Controller } from "react-hook-form";
|
2023-12-06 08:52:59 +00:00
|
|
|
|
// mobx store
|
|
|
|
|
import { useMobxStore } from "lib/mobx/store-provider";
|
2023-11-29 15:03:08 +00:00
|
|
|
|
// 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";
|
2023-12-06 08:52:59 +00:00
|
|
|
|
// helpers
|
|
|
|
|
import { checkEmailValidity } from "helpers/string.helper";
|
2023-11-29 15:03:08 +00:00
|
|
|
|
|
2023-12-06 08:52:59 +00:00
|
|
|
|
interface InstanceSetupEmailFormValues {
|
2023-11-29 15:03:08 +00:00
|
|
|
|
email: string;
|
2023-12-06 08:52:59 +00:00
|
|
|
|
password: string;
|
2023-11-29 15:03:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface IInstanceSetupEmailForm {
|
|
|
|
|
handleNextStep: (email: string) => void;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-06 08:52:59 +00:00
|
|
|
|
export const InstanceSetupSignInForm: FC<IInstanceSetupEmailForm> = (props) => {
|
2023-11-29 15:03:08 +00:00
|
|
|
|
const { handleNextStep } = props;
|
2023-12-06 08:52:59 +00:00
|
|
|
|
const {
|
|
|
|
|
user: { fetchCurrentUser },
|
|
|
|
|
} = useMobxStore();
|
2023-11-29 15:03:08 +00:00
|
|
|
|
// form info
|
|
|
|
|
const {
|
|
|
|
|
control,
|
2023-12-06 08:52:59 +00:00
|
|
|
|
formState: { errors, isSubmitting },
|
2023-11-29 15:03:08 +00:00
|
|
|
|
handleSubmit,
|
|
|
|
|
setValue,
|
|
|
|
|
} = useForm<InstanceSetupEmailFormValues>({
|
|
|
|
|
defaultValues: {
|
|
|
|
|
email: "",
|
2023-12-06 08:52:59 +00:00
|
|
|
|
password: "",
|
2023-11-29 15:03:08 +00:00
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
// hooks
|
|
|
|
|
const { setToastAlert } = useToast();
|
|
|
|
|
|
2023-12-06 08:52:59 +00:00
|
|
|
|
const handleFormSubmit = async (formValues: InstanceSetupEmailFormValues) => {
|
|
|
|
|
const payload = {
|
|
|
|
|
email: formValues.email,
|
|
|
|
|
password: formValues.password,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
await authService
|
|
|
|
|
.instanceAdminSignIn(payload)
|
|
|
|
|
.then(async () => {
|
|
|
|
|
await fetchCurrentUser();
|
2023-11-29 15:03:08 +00:00
|
|
|
|
handleNextStep(formValues.email);
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
setToastAlert({
|
|
|
|
|
type: "error",
|
2023-12-01 10:20:01 +00:00
|
|
|
|
title: "Error!",
|
|
|
|
|
message: err?.error ?? "Something went wrong. Please try again.",
|
2023-11-29 15:03:08 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2023-12-06 08:52:59 +00:00
|
|
|
|
};
|
2023-11-29 15:03:08 +00:00
|
|
|
|
|
|
|
|
|
return (
|
2023-12-06 08:52:59 +00:00
|
|
|
|
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
2023-12-01 10:20:01 +00:00
|
|
|
|
<h1 className="text-center text-2xl sm:text-2.5xl font-medium 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-5 w-full sm:w-96 mx-auto space-y-4">
|
|
|
|
|
<Controller
|
|
|
|
|
name="email"
|
|
|
|
|
control={control}
|
|
|
|
|
rules={{
|
|
|
|
|
required: "Email address is required",
|
2023-12-06 08:52:59 +00:00
|
|
|
|
validate: (value) => checkEmailValidity(value) || "Email is invalid",
|
2023-12-01 10:20:01 +00:00
|
|
|
|
}}
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2023-12-06 08:52:59 +00:00
|
|
|
|
<div className="flex items-center relative rounded-md bg-onboarding-background-200">
|
2023-12-01 10:20:01 +00:00
|
|
|
|
<Input
|
|
|
|
|
id="email"
|
|
|
|
|
name="email"
|
|
|
|
|
type="email"
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
placeholder="orville.wright@firstflight.com"
|
2023-12-06 08:52:59 +00:00
|
|
|
|
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
|
2023-12-01 10:20:01 +00:00
|
|
|
|
/>
|
|
|
|
|
{value.length > 0 && (
|
|
|
|
|
<XCircle
|
|
|
|
|
className="h-5 w-5 absolute stroke-custom-text-400 hover:cursor-pointer right-3"
|
|
|
|
|
onClick={() => setValue("email", "")}
|
2023-11-29 15:03:08 +00:00
|
|
|
|
/>
|
2023-12-01 10:20:01 +00:00
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2023-12-06 08:52:59 +00:00
|
|
|
|
<Controller
|
|
|
|
|
control={control}
|
|
|
|
|
name="password"
|
|
|
|
|
rules={{
|
|
|
|
|
required: "Password is required",
|
|
|
|
|
}}
|
|
|
|
|
render={({ field: { value, onChange } }) => (
|
|
|
|
|
<Input
|
|
|
|
|
type="password"
|
|
|
|
|
value={value}
|
|
|
|
|
onChange={onChange}
|
|
|
|
|
hasError={Boolean(errors.password)}
|
|
|
|
|
placeholder="Enter password"
|
|
|
|
|
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
2023-12-01 10:20:01 +00:00
|
|
|
|
<p className="text-xs text-custom-text-200 pb-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" size="xl" type="submit" loading={isSubmitting}>
|
2023-12-06 08:52:59 +00:00
|
|
|
|
{isSubmitting ? "Signing in..." : "Sign in"}
|
2023-12-01 10:20:01 +00:00
|
|
|
|
</Button>
|
2023-11-29 15:03:08 +00:00
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
);
|
|
|
|
|
};
|