2024-01-30 14:41:16 +00:00
|
|
|
import React, { useState } from "react";
|
2024-01-19 15:25:03 +00:00
|
|
|
import { observer } from "mobx-react-lite";
|
2024-03-06 13:09:14 +00:00
|
|
|
import Link from "next/link";
|
2023-12-06 08:52:59 +00:00
|
|
|
import { Controller, useForm } from "react-hook-form";
|
2024-01-30 14:41:16 +00:00
|
|
|
import { Eye, EyeOff, XCircle } from "lucide-react";
|
2024-03-19 14:38:35 +00:00
|
|
|
import { IPasswordSignInData } from "@plane/types";
|
2023-12-06 08:52:59 +00:00
|
|
|
// services
|
|
|
|
// ui
|
2024-03-06 08:48:41 +00:00
|
|
|
import { Button, Input, TOAST_TYPE, setToast } from "@plane/ui";
|
2023-12-06 08:52:59 +00:00
|
|
|
// helpers
|
2024-03-19 14:38:35 +00:00
|
|
|
import { checkEmailValidity } from "@/helpers/string.helper";
|
|
|
|
import { AuthService } from "@/services/auth.service";
|
2023-12-06 08:52:59 +00:00
|
|
|
// types
|
|
|
|
|
|
|
|
type Props = {
|
2024-01-19 15:25:03 +00:00
|
|
|
onSubmit: () => Promise<void>;
|
2023-12-06 08:52:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
type TPasswordFormValues = {
|
|
|
|
email: string;
|
|
|
|
password: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultValues: TPasswordFormValues = {
|
|
|
|
email: "",
|
|
|
|
password: "",
|
|
|
|
};
|
|
|
|
|
|
|
|
const authService = new AuthService();
|
|
|
|
|
2024-01-19 15:25:03 +00:00
|
|
|
export const SignUpPasswordForm: React.FC<Props> = observer((props) => {
|
|
|
|
const { onSubmit } = props;
|
2024-01-30 14:41:16 +00:00
|
|
|
// states
|
|
|
|
const [showPassword, setShowPassword] = useState(false);
|
2023-12-06 08:52:59 +00:00
|
|
|
// form info
|
|
|
|
const {
|
|
|
|
control,
|
2024-01-19 15:25:03 +00:00
|
|
|
formState: { errors, isSubmitting, isValid },
|
2023-12-06 08:52:59 +00:00
|
|
|
handleSubmit,
|
|
|
|
} = useForm<TPasswordFormValues>({
|
|
|
|
defaultValues: {
|
|
|
|
...defaultValues,
|
|
|
|
},
|
|
|
|
mode: "onChange",
|
|
|
|
reValidateMode: "onChange",
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleFormSubmit = async (formData: TPasswordFormValues) => {
|
|
|
|
const payload: IPasswordSignInData = {
|
|
|
|
email: formData.email,
|
|
|
|
password: formData.password,
|
|
|
|
};
|
|
|
|
|
|
|
|
await authService
|
|
|
|
.passwordSignIn(payload)
|
2024-01-19 15:25:03 +00:00
|
|
|
.then(async () => await onSubmit())
|
2023-12-06 08:52:59 +00:00
|
|
|
.catch((err) =>
|
2024-03-06 08:48:41 +00:00
|
|
|
setToast({
|
|
|
|
type: TOAST_TYPE.ERROR,
|
2023-12-06 08:52:59 +00:00
|
|
|
title: "Error!",
|
|
|
|
message: err?.error ?? "Something went wrong. Please try again.",
|
|
|
|
})
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-01-19 15:25:03 +00:00
|
|
|
<h1 className="sm:text-2.5xl text-center text-2xl font-medium text-onboarding-text-100">
|
2023-12-06 08:52:59 +00:00
|
|
|
Get on your flight deck
|
|
|
|
</h1>
|
2024-01-19 15:25:03 +00:00
|
|
|
<p className="mt-2.5 text-center text-sm text-onboarding-text-200">
|
|
|
|
Create or join a workspace. Start with your e-mail.
|
|
|
|
</p>
|
|
|
|
<form onSubmit={handleSubmit(handleFormSubmit)} className="mx-auto mt-5 space-y-4 sm:w-96">
|
2023-12-06 08:52:59 +00:00
|
|
|
<div>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="email"
|
|
|
|
rules={{
|
|
|
|
required: "Email is required",
|
|
|
|
validate: (value) => checkEmailValidity(value) || "Email is invalid",
|
|
|
|
}}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2023-12-10 10:18:10 +00:00
|
|
|
<div className="relative flex items-center rounded-md bg-onboarding-background-200">
|
2023-12-06 08:52:59 +00:00
|
|
|
<Input
|
|
|
|
id="email"
|
|
|
|
name="email"
|
|
|
|
type="email"
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
hasError={Boolean(errors.email)}
|
2024-01-19 15:25:03 +00:00
|
|
|
placeholder="name@company.com"
|
2023-12-10 10:18:10 +00:00
|
|
|
className="h-[46px] w-full border border-onboarding-border-100 pr-12 placeholder:text-onboarding-text-400"
|
2023-12-06 08:52:59 +00:00
|
|
|
/>
|
|
|
|
{value.length > 0 && (
|
|
|
|
<XCircle
|
2023-12-10 10:18:10 +00:00
|
|
|
className="absolute right-3 h-5 w-5 stroke-custom-text-400 hover:cursor-pointer"
|
2023-12-06 08:52:59 +00:00
|
|
|
onClick={() => onChange("")}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Controller
|
|
|
|
control={control}
|
|
|
|
name="password"
|
|
|
|
rules={{
|
2024-01-19 15:25:03 +00:00
|
|
|
required: "Password is required",
|
2023-12-06 08:52:59 +00:00
|
|
|
}}
|
|
|
|
render={({ field: { value, onChange } }) => (
|
2024-01-30 14:41:16 +00:00
|
|
|
<div className="relative flex items-center rounded-md bg-onboarding-background-200">
|
|
|
|
<Input
|
|
|
|
type={showPassword ? "text" : "password"}
|
|
|
|
value={value}
|
|
|
|
onChange={onChange}
|
|
|
|
hasError={Boolean(errors.password)}
|
|
|
|
placeholder="Enter password"
|
|
|
|
className="h-[46px] w-full border border-onboarding-border-100 !bg-onboarding-background-200 pr-12 placeholder:text-onboarding-text-400"
|
|
|
|
autoFocus
|
|
|
|
/>
|
|
|
|
{showPassword ? (
|
|
|
|
<EyeOff
|
|
|
|
className="absolute right-3 h-5 w-5 stroke-custom-text-400 hover:cursor-pointer"
|
|
|
|
onClick={() => setShowPassword(false)}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<Eye
|
|
|
|
className="absolute right-3 h-5 w-5 stroke-custom-text-400 hover:cursor-pointer"
|
|
|
|
onClick={() => setShowPassword(true)}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</div>
|
2023-12-06 08:52:59 +00:00
|
|
|
)}
|
|
|
|
/>
|
2024-03-06 13:09:14 +00:00
|
|
|
<p className="mt-2 pb-3 text-xs text-onboarding-text-200">
|
2024-01-19 15:25:03 +00:00
|
|
|
This password will continue to be your account{"'"}s password.
|
|
|
|
</p>
|
2023-12-06 08:52:59 +00:00
|
|
|
</div>
|
2024-01-19 15:25:03 +00:00
|
|
|
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={!isValid} loading={isSubmitting}>
|
|
|
|
Create account
|
2023-12-06 08:52:59 +00:00
|
|
|
</Button>
|
|
|
|
<p className="text-xs text-onboarding-text-200">
|
|
|
|
When you click the button above, you agree with our{" "}
|
|
|
|
<Link href="https://plane.so/terms-and-conditions" target="_blank" rel="noopener noreferrer">
|
|
|
|
<span className="font-semibold underline">terms and conditions of service.</span>
|
|
|
|
</Link>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
</>
|
|
|
|
);
|
2024-01-19 15:25:03 +00:00
|
|
|
});
|