chore: updated sign-in workflows for cloud and self-hosted instances (#2994)

* chore: update onboarding workflow

* dev: update user count tasks

* fix: forgot password endpoint

* dev: instance and onboarding updates

* chore: update sign-in workflow for cloud and self-hosted instances (#2993)

* chore: updated auth services

* chore: new signin workflow updated

* chore: updated content

* chore: instance admin setup

* dev: update instance verification task

* dev: run the instance verification task every 4 hours

* dev: update migrations

* chore: update latest features image

---------

Co-authored-by: pablohashescobar <nikhilschacko@gmail.com>
This commit is contained in:
Aaryan Khandelwal 2023-12-06 14:22:59 +05:30 committed by sriram veeraghanta
parent f481957818
commit be2cf2e842
53 changed files with 1017 additions and 1368 deletions

View file

@ -38,7 +38,7 @@ export const GithubLoginButton: FC<GithubLoginButtonProps> = (props) => {
setLoginCallBackURL(`${origin}/` as any);
}, []);
return (
<div className="w-full flex justify-center items-center">
<div className="w-full">
<Link
href={`https://github.com/login/oauth/authorize?client_id=${clientId}&redirect_uri=${loginCallBackURL}&scope=read:user,user:email`}
>

View file

@ -16,6 +16,7 @@ type Props = {
email: string;
handleStepChange: (step: ESignInSteps) => void;
handleSignInRedirection: () => Promise<void>;
isOnboarded: boolean;
};
type TCreatePasswordFormValues = {
@ -32,7 +33,7 @@ const defaultValues: TCreatePasswordFormValues = {
const authService = new AuthService();
export const CreatePasswordForm: React.FC<Props> = (props) => {
const { email, handleSignInRedirection } = props;
const { email, handleSignInRedirection, isOnboarded } = props;
// toast alert
const { setToastAlert } = useToast();
// form info
@ -76,9 +77,8 @@ export const CreatePasswordForm: React.FC<Props> = (props) => {
return (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Let{"'"}s get a new password
Get on your flight deck
</h1>
<form onSubmit={handleSubmit(handleCreatePassword)} className="mt-11 sm:w-96 mx-auto space-y-4">
<Controller
control={control}
@ -97,37 +97,32 @@ export const CreatePasswordForm: React.FC<Props> = (props) => {
ref={ref}
hasError={Boolean(errors.email)}
placeholder="orville.wright@firstflight.com"
className="w-full h-[46px] text-onboarding-text-400 border border-onboarding-border-100 pr-12"
className="w-full h-[46px] text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
disabled
/>
)}
/>
<div>
<Controller
control={control}
name="password"
rules={{
required: "Password is required",
}}
render={({ field: { value, onChange, ref } }) => (
<Input
type="password"
value={value}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.password)}
placeholder="Create password"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
minLength={8}
/>
)}
/>
<p className="text-xs text-onboarding-text-200 mt-3 pb-2">
Whatever you choose now will be your account{"'"}s password until you change it.
</p>
</div>
<Controller
control={control}
name="password"
rules={{
required: "Password is required",
}}
render={({ field: { value, onChange, ref } }) => (
<Input
type="password"
value={value}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.password)}
placeholder="Choose password"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
minLength={8}
/>
)}
/>
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={!isValid} loading={isSubmitting}>
{isSubmitting ? "Submitting..." : "Go to workspace"}
{isOnboarded ? "Go to workspace" : "Set up workspace"}
</Button>
<p className="text-xs text-onboarding-text-200">
When you click the button above, you agree with our{" "}

View file

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import { Controller, useForm } from "react-hook-form";
import { XCircle } from "lucide-react";
// services
@ -10,7 +10,7 @@ import { Button, Input } from "@plane/ui";
// helpers
import { checkEmailValidity } from "helpers/string.helper";
// types
import { IEmailCheckData, TEmailCheckTypes } from "types/auth";
import { IEmailCheckData } from "types/auth";
// constants
import { ESignInSteps } from "components/account";
@ -19,7 +19,7 @@ type Props = {
updateEmail: (email: string) => void;
};
type TEmailCodeFormValues = {
type TEmailFormValues = {
email: string;
};
@ -27,17 +27,14 @@ const authService = new AuthService();
export const EmailForm: React.FC<Props> = (props) => {
const { handleStepChange, updateEmail } = props;
// states
const [isCheckingEmail, setIsCheckingEmail] = useState<TEmailCheckTypes | null>(null);
const { setToastAlert } = useToast();
const {
control,
formState: { errors, isValid },
formState: { errors, isSubmitting, isValid },
handleSubmit,
watch,
} = useForm<TEmailCodeFormValues>({
} = useForm<TEmailFormValues>({
defaultValues: {
email: "",
},
@ -45,31 +42,21 @@ export const EmailForm: React.FC<Props> = (props) => {
reValidateMode: "onChange",
});
const handleEmailCheck = async (type: TEmailCheckTypes) => {
setIsCheckingEmail(type);
const email = watch("email");
const handleFormSubmit = async (data: TEmailFormValues) => {
const payload: IEmailCheckData = {
email,
type,
email: data.email,
};
// update the global email state
updateEmail(email);
updateEmail(data.email);
await authService
.emailCheck(payload)
.then((res) => {
// if type is magic_code, send the user to magic sign in
if (type === "magic_code") handleStepChange(ESignInSteps.UNIQUE_CODE);
// if type is password, check if the user has a password set
if (type === "password") {
// if password is autoset, send them to set new password link
if (res.is_password_autoset) handleStepChange(ESignInSteps.SET_PASSWORD_LINK);
// if password is not autoset, send them to password form
else handleStepChange(ESignInSteps.PASSWORD);
}
// if the password has been autoset, send the user to magic sign-in
if (res.is_password_autoset) handleStepChange(ESignInSteps.UNIQUE_CODE);
// if the password has not been autoset, send them to password sign-in
else handleStepChange(ESignInSteps.PASSWORD);
})
.catch((err) =>
setToastAlert({
@ -77,8 +64,7 @@ export const EmailForm: React.FC<Props> = (props) => {
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
})
)
.finally(() => setIsCheckingEmail(null));
);
};
return (
@ -86,11 +72,11 @@ export const EmailForm: React.FC<Props> = (props) => {
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Get on your flight deck
</h1>
<p className="text-center text-sm text-onboarding-text-200 mt-3">
Sign in with the email you used to sign up for Plane
<p className="text-center text-sm text-onboarding-text-200 mt-2.5">
Create or join a workspace. Start with your e-mail.
</p>
<form onSubmit={handleSubmit(() => {})} className="mt-5 sm:w-96 mx-auto">
<form onSubmit={handleSubmit(handleFormSubmit)} className="mt-8 sm:w-96 mx-auto space-y-4">
<div className="space-y-1">
<Controller
control={control}
@ -122,30 +108,9 @@ export const EmailForm: React.FC<Props> = (props) => {
)}
/>
</div>
<div className="grid grid-cols-2 gap-2.5 mt-4">
<Button
type="button"
variant="primary"
className="w-full"
size="xl"
onClick={() => handleEmailCheck("magic_code")}
disabled={!isValid}
loading={Boolean(isCheckingEmail)}
>
{isCheckingEmail === "magic_code" ? "Sending code..." : "Send unique code"}
</Button>
<Button
type="button"
variant="outline-primary"
className="w-full"
size="xl"
onClick={() => handleEmailCheck("password")}
disabled={!isValid}
loading={Boolean(isCheckingEmail)}
>
{isCheckingEmail === "password" ? "Loading..." : "Use password"}
</Button>
</div>
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={!isValid} loading={isSubmitting}>
Continue
</Button>
</form>
</>
);

View file

@ -2,7 +2,8 @@ export * from "./create-password";
export * from "./email-form";
export * from "./o-auth-options";
export * from "./optional-set-password";
export * from "./unique-code";
export * from "./password";
export * from "./root";
export * from "./self-hosted-sign-in";
export * from "./set-password-link";
export * from "./unique-code";

View file

@ -3,24 +3,20 @@ import { observer } from "mobx-react-lite";
import { useMobxStore } from "lib/mobx/store-provider";
// services
import { AuthService } from "services/auth.service";
import { UserService } from "services/user.service";
// hooks
import useToast from "hooks/use-toast";
// components
import { ESignInSteps, GithubLoginButton, GoogleLoginButton } from "components/account";
import { GithubLoginButton, GoogleLoginButton } from "components/account";
type Props = {
updateEmail: (email: string) => void;
handleStepChange: (step: ESignInSteps) => void;
handleSignInRedirection: () => Promise<void>;
};
// services
const authService = new AuthService();
const userService = new UserService();
export const OAuthOptions: React.FC<Props> = observer((props) => {
const { updateEmail, handleStepChange, handleSignInRedirection } = props;
const { handleSignInRedirection } = props;
// toast alert
const { setToastAlert } = useToast();
// mobx store
@ -38,14 +34,7 @@ export const OAuthOptions: React.FC<Props> = observer((props) => {
};
const response = await authService.socialAuth(socialAuthPayload);
if (response) {
const currentUser = await userService.currentUser();
updateEmail(currentUser.email);
if (currentUser.is_password_autoset) handleStepChange(ESignInSteps.OPTIONAL_SET_PASSWORD);
else handleSignInRedirection();
}
if (response) handleSignInRedirection();
} else throw Error("Cant find credentials");
} catch (err: any) {
setToastAlert({
@ -66,14 +55,7 @@ export const OAuthOptions: React.FC<Props> = observer((props) => {
};
const response = await authService.socialAuth(socialAuthPayload);
if (response) {
const currentUser = await userService.currentUser();
updateEmail(currentUser.email);
if (currentUser.is_password_autoset) handleStepChange(ESignInSteps.OPTIONAL_SET_PASSWORD);
else handleSignInRedirection();
}
if (response) handleSignInRedirection();
} else throw Error("Cant find credentials");
} catch (err: any) {
setToastAlert({
@ -87,11 +69,11 @@ export const OAuthOptions: React.FC<Props> = observer((props) => {
return (
<>
<div className="flex sm:w-96 items-center mt-4 mx-auto">
<hr className={`border-onboarding-border-100 w-full`} />
<hr className="border-onboarding-border-100 w-full" />
<p className="text-center text-sm text-onboarding-text-400 mx-3 flex-shrink-0">Or continue with</p>
<hr className={`border-onboarding-border-100 w-full`} />
<hr className="border-onboarding-border-100 w-full" />
</div>
<div className="flex flex-col items-center justify-center gap-4 pt-7 sm:flex-row sm:w-96 mx-auto overflow-hidden">
<div className="flex flex-col sm:flex-row items-center gap-2 pt-7 sm:w-96 mx-auto overflow-hidden">
{envConfig?.google_client_id && (
<GoogleLoginButton clientId={envConfig?.google_client_id} handleSignIn={handleGoogleSignIn} />
)}

View file

@ -12,13 +12,14 @@ type Props = {
email: string;
handleStepChange: (step: ESignInSteps) => void;
handleSignInRedirection: () => Promise<void>;
isOnboarded: boolean;
};
export const OptionalSetPasswordForm: React.FC<Props> = (props) => {
const { email, handleStepChange, handleSignInRedirection } = props;
const { email, handleStepChange, handleSignInRedirection, isOnboarded } = props;
// states
const [isGoingToWorkspace, setIsGoingToWorkspace] = useState(false);
// form info
const {
control,
formState: { errors, isValid },
@ -39,8 +40,8 @@ export const OptionalSetPasswordForm: React.FC<Props> = (props) => {
return (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">Set a password</h1>
<p className="text-center text-sm text-onboarding-text-200 px-20 mt-3">
If you{"'"}d to do away with codes, set a password here
<p className="text-center text-sm text-onboarding-text-200 px-20 mt-2.5">
If you{"'"}d like to do away with codes, set a password here.
</p>
<form className="mt-5 sm:w-96 mx-auto space-y-4">
@ -86,11 +87,13 @@ export const OptionalSetPasswordForm: React.FC<Props> = (props) => {
disabled={!isValid}
loading={isGoingToWorkspace}
>
{isGoingToWorkspace ? "Going to app..." : "Go to workspace"}
{isOnboarded ? "Go to workspace" : "Set up workspace"}
</Button>
</div>
<p className="text-xs text-onboarding-text-200">
When you click <span className="text-custom-primary-100">Go to workspace</span> above, you agree with our{" "}
When you click{" "}
<span className="text-custom-primary-100">{isOnboarded ? "Go to workspace" : "Set up workspace"}</span> 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>

View file

@ -11,7 +11,7 @@ import { Button, Input } from "@plane/ui";
// helpers
import { checkEmailValidity } from "helpers/string.helper";
// types
import { IEmailCheckData, IPasswordSignInData } from "types/auth";
import { IPasswordSignInData } from "types/auth";
// constants
import { ESignInSteps } from "components/account";
@ -37,6 +37,7 @@ const authService = new AuthService();
export const PasswordForm: React.FC<Props> = (props) => {
const { email, updateEmail, handleStepChange, handleSignInRedirection } = props;
// states
const [isSendingUniqueCode, setIsSendingUniqueCode] = useState(false);
const [isSendingResetPasswordLink, setIsSendingResetPasswordLink] = useState(false);
// toast alert
const { setToastAlert } = useToast();
@ -46,7 +47,6 @@ export const PasswordForm: React.FC<Props> = (props) => {
formState: { dirtyFields, errors, isSubmitting, isValid },
getValues,
handleSubmit,
reset,
setError,
} = useForm<TPasswordFormValues>({
defaultValues: {
@ -57,7 +57,9 @@ export const PasswordForm: React.FC<Props> = (props) => {
reValidateMode: "onChange",
});
const handlePasswordSignIn = async (formData: TPasswordFormValues) => {
const handleFormSubmit = async (formData: TPasswordFormValues) => {
updateEmail(formData.email);
const payload: IPasswordSignInData = {
email: formData.email,
password: formData.password,
@ -75,36 +77,6 @@ export const PasswordForm: React.FC<Props> = (props) => {
);
};
const handleEmailCheck = async (formData: TPasswordFormValues) => {
const payload: IEmailCheckData = {
email: formData.email,
type: "password",
};
await authService
.emailCheck(payload)
.then((res) => {
if (res.is_password_autoset) handleStepChange(ESignInSteps.SET_PASSWORD_LINK);
else
reset({
email: formData.email,
password: "",
});
})
.catch((err) =>
setToastAlert({
type: "error",
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
})
);
};
const handleFormSubmit = async (formData: TPasswordFormValues) => {
if (dirtyFields.email) await handleEmailCheck(formData);
else await handlePasswordSignIn(formData);
};
const handleForgotPassword = async () => {
const emailFormValue = getValues("email");
@ -130,6 +102,31 @@ export const PasswordForm: React.FC<Props> = (props) => {
.finally(() => setIsSendingResetPasswordLink(false));
};
const handleSendUniqueCode = async () => {
const emailFormValue = getValues("email");
const isEmailValid = checkEmailValidity(emailFormValue);
if (!isEmailValid) {
setError("email", { message: "Email is invalid" });
return;
}
setIsSendingUniqueCode(true);
await authService
.generateUniqueCode({ email: emailFormValue })
.then(() => handleStepChange(ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD))
.catch((err) =>
setToastAlert({
type: "error",
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
})
)
.finally(() => setIsSendingUniqueCode(false));
};
return (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-semibold text-onboarding-text-100">
@ -151,13 +148,7 @@ export const PasswordForm: React.FC<Props> = (props) => {
name="email"
type="email"
value={value}
onChange={(e) => {
updateEmail(e.target.value);
onChange(e.target.value);
}}
onBlur={() => {
if (dirtyFields.email) handleEmailCheck(getValues());
}}
onChange={onChange}
hasError={Boolean(errors.email)}
placeholder="orville.wright@firstflight.com"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
@ -186,7 +177,7 @@ export const PasswordForm: React.FC<Props> = (props) => {
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"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
/>
)}
/>
@ -199,15 +190,34 @@ export const PasswordForm: React.FC<Props> = (props) => {
}`}
disabled={isSendingResetPasswordLink}
>
{isSendingResetPasswordLink ? "Sending link..." : "Forgot your password?"}
{isSendingResetPasswordLink ? "Sending link" : "Forgot your password?"}
</button>
</div>
</div>
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={!isValid} loading={isSubmitting}>
{isSubmitting ? "Signing in..." : "Go to workspace"}
</Button>
<div className="grid sm:grid-cols-2 gap-2.5">
<Button
type="button"
onClick={handleSendUniqueCode}
variant="primary"
className="w-full"
size="xl"
loading={isSendingUniqueCode}
>
{isSendingUniqueCode ? "Sending code" : "Use unique code"}
</Button>
<Button
type="submit"
variant="outline-primary"
className="w-full"
size="xl"
disabled={!isValid}
loading={isSubmitting}
>
Go to workspace
</Button>
</div>
<p className="text-xs text-onboarding-text-200">
When you click the button above, you agree with our{" "}
When you click <span className="text-custom-primary-100">Go to workspace</span> 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>

View file

@ -1,7 +1,11 @@
import React, { useState } from "react";
import { observer } from "mobx-react-lite";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// hooks
import useSignInRedirection from "hooks/use-sign-in-redirection";
// components
import { LatestFeatureBlock } from "components/common";
import {
EmailForm,
UniqueCodeForm,
@ -10,6 +14,7 @@ import {
OAuthOptions,
OptionalSetPasswordForm,
CreatePasswordForm,
SelfHostedSignInForm,
} from "components/account";
export enum ESignInSteps {
@ -19,64 +24,96 @@ export enum ESignInSteps {
UNIQUE_CODE = "UNIQUE_CODE",
OPTIONAL_SET_PASSWORD = "OPTIONAL_SET_PASSWORD",
CREATE_PASSWORD = "CREATE_PASSWORD",
USE_UNIQUE_CODE_FROM_PASSWORD = "USE_UNIQUE_CODE_FROM_PASSWORD",
}
const OAUTH_HIDDEN_STEPS = [ESignInSteps.OPTIONAL_SET_PASSWORD, ESignInSteps.CREATE_PASSWORD];
export const SignInRoot = () => {
export const SignInRoot = observer(() => {
// states
const [signInStep, setSignInStep] = useState<ESignInSteps>(ESignInSteps.EMAIL);
const [email, setEmail] = useState("");
const [isOnboarded, setIsOnboarded] = useState(false);
// sign in redirection hook
const { handleRedirection } = useSignInRedirection();
// mobx store
const {
appConfig: { envConfig },
} = useMobxStore();
const isOAuthEnabled = envConfig && (envConfig.google_client_id || envConfig.github_client_id);
return (
<>
<div className="mx-auto flex flex-col">
{signInStep === ESignInSteps.EMAIL && (
<EmailForm handleStepChange={(step) => setSignInStep(step)} updateEmail={(newEmail) => setEmail(newEmail)} />
)}
{signInStep === ESignInSteps.PASSWORD && (
<PasswordForm
{envConfig?.is_self_managed ? (
<SelfHostedSignInForm
email={email}
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
)}
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
)}
{signInStep === ESignInSteps.UNIQUE_CODE && (
<UniqueCodeForm
email={email}
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
)}
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
<OptionalSetPasswordForm
email={email}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
)}
{signInStep === ESignInSteps.CREATE_PASSWORD && (
<CreatePasswordForm
email={email}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
) : (
<>
{signInStep === ESignInSteps.EMAIL && (
<EmailForm
handleStepChange={(step) => setSignInStep(step)}
updateEmail={(newEmail) => setEmail(newEmail)}
/>
)}
{signInStep === ESignInSteps.PASSWORD && (
<PasswordForm
email={email}
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
)}
{signInStep === ESignInSteps.SET_PASSWORD_LINK && (
<SetPasswordLink email={email} updateEmail={(newEmail) => setEmail(newEmail)} />
)}
{signInStep === ESignInSteps.USE_UNIQUE_CODE_FROM_PASSWORD && (
<UniqueCodeForm
email={email}
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
submitButtonLabel="Go to workspace"
showTermsAndConditions
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
/>
)}
{signInStep === ESignInSteps.UNIQUE_CODE && (
<UniqueCodeForm
email={email}
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
updateUserOnboardingStatus={(value) => setIsOnboarded(value)}
/>
)}
{signInStep === ESignInSteps.OPTIONAL_SET_PASSWORD && (
<OptionalSetPasswordForm
email={email}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
isOnboarded={isOnboarded}
/>
)}
{signInStep === ESignInSteps.CREATE_PASSWORD && (
<CreatePasswordForm
email={email}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
isOnboarded={isOnboarded}
/>
)}
</>
)}
</div>
{!OAUTH_HIDDEN_STEPS.includes(signInStep) && (
<OAuthOptions
updateEmail={(newEmail) => setEmail(newEmail)}
handleStepChange={(step) => setSignInStep(step)}
handleSignInRedirection={handleRedirection}
/>
{isOAuthEnabled && !OAUTH_HIDDEN_STEPS.includes(signInStep) && (
<OAuthOptions handleSignInRedirection={handleRedirection} />
)}
<LatestFeatureBlock />
</>
);
};
});

View file

@ -0,0 +1,139 @@
import React from "react";
import Link from "next/link";
import { Controller, useForm } from "react-hook-form";
import { XCircle } from "lucide-react";
// services
import { AuthService } from "services/auth.service";
// hooks
import useToast from "hooks/use-toast";
// ui
import { Button, Input } from "@plane/ui";
// helpers
import { checkEmailValidity } from "helpers/string.helper";
// types
import { IPasswordSignInData } from "types/auth";
type Props = {
email: string;
updateEmail: (email: string) => void;
handleSignInRedirection: () => Promise<void>;
};
type TPasswordFormValues = {
email: string;
password: string;
};
const defaultValues: TPasswordFormValues = {
email: "",
password: "",
};
const authService = new AuthService();
export const SelfHostedSignInForm: React.FC<Props> = (props) => {
const { email, updateEmail, handleSignInRedirection } = props;
// toast alert
const { setToastAlert } = useToast();
// form info
const {
control,
formState: { dirtyFields, errors, isSubmitting },
handleSubmit,
} = useForm<TPasswordFormValues>({
defaultValues: {
...defaultValues,
email,
},
mode: "onChange",
reValidateMode: "onChange",
});
const handleFormSubmit = async (formData: TPasswordFormValues) => {
const payload: IPasswordSignInData = {
email: formData.email,
password: formData.password,
};
updateEmail(formData.email);
await authService
.passwordSignIn(payload)
.then(async () => await handleSignInRedirection())
.catch((err) =>
setToastAlert({
type: "error",
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
})
);
};
return (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-semibold text-onboarding-text-100">
Get on your flight deck
</h1>
<form onSubmit={handleSubmit(handleFormSubmit)} className="mt-11 sm:w-96 mx-auto space-y-4">
<div>
<Controller
control={control}
name="email"
rules={{
required: "Email is required",
validate: (value) => checkEmailValidity(value) || "Email is invalid",
}}
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}
hasError={Boolean(errors.email)}
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={() => onChange("")}
/>
)}
</div>
)}
/>
</div>
<div>
<Controller
control={control}
name="password"
rules={{
required: dirtyFields.email ? false : "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"
/>
)}
/>
</div>
<Button type="submit" variant="primary" className="w-full" size="xl" loading={isSubmitting}>
Go to workspace
</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>
</>
);
};

View file

@ -1,7 +1,5 @@
import React, { useState } from "react";
import Link from "next/link";
import React from "react";
import { Controller, useForm } from "react-hook-form";
import { XCircle } from "lucide-react";
// services
import { AuthService } from "services/auth.service";
// hooks
@ -22,14 +20,12 @@ const authService = new AuthService();
export const SetPasswordLink: React.FC<Props> = (props) => {
const { email, updateEmail } = props;
// states
const [isSendingNewLink, setIsSendingNewLink] = useState(false);
const { setToastAlert } = useToast();
const {
control,
formState: { errors, isValid },
formState: { errors, isSubmitting, isValid },
handleSubmit,
} = useForm({
defaultValues: {
@ -40,17 +36,14 @@ export const SetPasswordLink: React.FC<Props> = (props) => {
});
const handleSendNewLink = async (formData: { email: string }) => {
setIsSendingNewLink(true);
updateEmail(formData.email);
const payload: IEmailCheckData = {
email: formData.email,
type: "password",
};
await authService
.emailCheck(payload)
.sendResetPasswordLink(payload)
.then(() =>
setToastAlert({
type: "success",
@ -64,8 +57,7 @@ export const SetPasswordLink: React.FC<Props> = (props) => {
title: "Error!",
message: err?.error ?? "Something went wrong. Please try again.",
})
)
.finally(() => setIsSendingNewLink(false));
);
};
return (
@ -73,7 +65,7 @@ export const SetPasswordLink: React.FC<Props> = (props) => {
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Get on your flight deck
</h1>
<p className="text-center text-sm text-onboarding-text-200 px-20 mt-3">
<p className="text-center text-sm text-onboarding-text-200 px-20 mt-2.5">
We have sent a link to <span className="font-semibold text-custom-primary-100">{email},</span> so you can set a
password
</p>
@ -87,45 +79,24 @@ export const SetPasswordLink: React.FC<Props> = (props) => {
required: "Email is required",
validate: (value) => checkEmailValidity(value) || "Email is invalid",
}}
render={({ field: { value, onChange, ref } }) => (
<div className="flex items-center relative rounded-md bg-onboarding-background-200">
<Input
id="email"
name="email"
type="email"
value={value}
onChange={onChange}
ref={ref}
hasError={Boolean(errors.email)}
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={() => onChange("")}
/>
)}
</div>
render={({ field: { value, onChange } }) => (
<Input
id="email"
name="email"
type="email"
value={value}
onChange={onChange}
hasError={Boolean(errors.email)}
placeholder="orville.wright@firstflight.com"
className="w-full h-[46px] text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
disabled
/>
)}
/>
</div>
<Button
type="submit"
variant="primary"
className="w-full"
size="xl"
disabled={!isValid}
loading={isSendingNewLink}
>
{isSendingNewLink ? "Sending new link..." : "Get link again"}
<Button type="submit" variant="primary" className="w-full" size="xl" disabled={!isValid} loading={isSubmitting}>
{isSubmitting ? "Sending new link" : "Get link again"}
</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>
</>
);

View file

@ -22,6 +22,9 @@ type Props = {
updateEmail: (email: string) => void;
handleStepChange: (step: ESignInSteps) => void;
handleSignInRedirection: () => Promise<void>;
submitButtonLabel?: string;
showTermsAndConditions?: boolean;
updateUserOnboardingStatus: (value: boolean) => void;
};
type TUniqueCodeFormValues = {
@ -39,7 +42,15 @@ const authService = new AuthService();
const userService = new UserService();
export const UniqueCodeForm: React.FC<Props> = (props) => {
const { email, updateEmail, handleStepChange, handleSignInRedirection } = props;
const {
email,
updateEmail,
handleStepChange,
handleSignInRedirection,
submitButtonLabel = "Continue",
showTermsAndConditions = false,
updateUserOnboardingStatus,
} = props;
// states
const [isRequestingNewCode, setIsRequestingNewCode] = useState(false);
// toast alert
@ -74,6 +85,8 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
.then(async () => {
const currentUser = await userService.currentUser();
updateUserOnboardingStatus(currentUser.is_onboarded);
if (currentUser.is_password_autoset) handleStepChange(ESignInSteps.OPTIONAL_SET_PASSWORD);
else await handleSignInRedirection();
})
@ -86,15 +99,15 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
);
};
const handleSendNewLink = async (formData: TUniqueCodeFormValues) => {
const handleSendNewCode = async (formData: TUniqueCodeFormValues) => {
const payload: IEmailCheckData = {
email: formData.email,
type: "magic_code",
};
await authService
.emailCheck(payload)
.generateUniqueCode(payload)
.then(() => {
setResendCodeTimer(30);
setToastAlert({
type: "success",
title: "Success!",
@ -116,25 +129,30 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
};
const handleFormSubmit = async (formData: TUniqueCodeFormValues) => {
if (dirtyFields.email) await handleSendNewLink(formData);
updateEmail(formData.email);
if (dirtyFields.email) await handleSendNewCode(formData);
else await handleUniqueCodeSignIn(formData);
};
const handleRequestNewCode = async () => {
setIsRequestingNewCode(true);
await handleSendNewLink(getValues())
await handleSendNewCode(getValues())
.then(() => setResendCodeTimer(30))
.finally(() => setIsRequestingNewCode(false));
};
const isRequestNewCodeDisabled = isRequestingNewCode || resendTimerCode > 0;
const hasEmailChanged = dirtyFields.email;
return (
<>
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">Moving to the runway</h1>
<p className="text-center text-sm text-onboarding-text-200 mt-3">
Paste the code you got at <span className="font-semibold text-custom-primary-100">{email}</span> below
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Get on your flight deck
</h1>
<p className="text-center text-sm text-onboarding-text-200 mt-2.5">
Paste the code you got at <span className="font-semibold text-custom-primary-100">{email}</span> below.
</p>
<form onSubmit={handleSubmit(handleFormSubmit)} className="mt-5 sm:w-96 mx-auto space-y-4">
@ -153,12 +171,9 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
name="email"
type="email"
value={value}
onChange={(e) => {
updateEmail(e.target.value);
onChange(e.target.value);
}}
onChange={onChange}
onBlur={() => {
if (dirtyFields.email) handleSendNewLink(getValues());
if (hasEmailChanged) handleSendNewCode(getValues());
}}
ref={ref}
hasError={Boolean(errors.email)}
@ -174,7 +189,7 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
</div>
)}
/>
{dirtyFields.email && (
{hasEmailChanged && (
<button
type="submit"
className="text-xs text-onboarding-text-300 mt-1.5 flex items-center gap-1 outline-none bg-transparent border-none"
@ -188,7 +203,7 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
control={control}
name="token"
rules={{
required: dirtyFields.email ? false : "Code is required",
required: hasEmailChanged ? false : "Code is required",
}}
render={({ field: { value, onChange } }) => (
<Input
@ -196,7 +211,7 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
onChange={onChange}
hasError={Boolean(errors.token)}
placeholder="gets-sets-flys"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
/>
)}
/>
@ -214,7 +229,7 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
{resendTimerCode > 0
? `Request new code in ${resendTimerCode}s`
: isRequestingNewCode
? "Requesting new code..."
? "Requesting new code"
: "Request new code"}
</button>
</div>
@ -224,17 +239,19 @@ export const UniqueCodeForm: React.FC<Props> = (props) => {
variant="primary"
className="w-full"
size="xl"
disabled={!isValid || dirtyFields.email}
disabled={!isValid || hasEmailChanged}
loading={isSubmitting}
>
{isSubmitting ? "Signing in..." : "Confirm"}
{submitButtonLabel}
</Button>
<p className="text-xs text-onboarding-text-200">
When you click Confirm 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>
{showTermsAndConditions && (
<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>
</>
);

View file

@ -25,7 +25,7 @@ export const LatestFeatureBlock = () => {
<Image
src={latestFeatures}
alt="Plane Issues"
className={`rounded-md h-full ml-8 -mt-2 ${
className={`rounded-md h-full ml-10 -mt-2 ${
resolvedTheme === "dark" ? "bg-onboarding-background-100" : "bg-custom-primary-70"
} `}
/>

View file

@ -17,10 +17,10 @@ export const InstanceNotReady = () => {
<div className="h-full bg-onboarding-gradient-100 md:w-2/3 sm:w-4/5 px-4 pt-4 rounded-t-md mx-auto shadow-sm border-x border-t border-custom-border-100">
<div className="relative px-7 sm:px-0 bg-onboarding-gradient-200 h-full rounded-t-md">
<div className="flex items-center py-10 justify-center">
<Image src={planeLogo} className="h-44 w-full" alt="Plane logo" />
<Image src={planeLogo} className="h-[44px] w-full" alt="Plane logo" />
</div>
<div className="mt-20">
<Image src={instanceNotReady} className="h-56 w-full" alt="Instance not ready" />
<Image src={instanceNotReady} className="w-full" alt="Instance not ready" />
</div>
<div className="flex flex-col gap-5 items-center py-12 pb-20 w-full">
<h3 className="text-2xl font-medium">Your Plane instance isn{"'"}t ready yet</h3>

View file

@ -55,7 +55,7 @@ export const InstanceSetupDone = () => {
</p>
</div>
<Button size="lg" prependIcon={<UserCog2 />} onClick={redirectToGodMode} loading={isRedirecting}>
{isRedirecting ? "Redirecting..." : "Go to God Mode"}
Go to God Mode
</Button>
</div>
</div>

View file

@ -1,160 +0,0 @@
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<IInstanceSetupEmailCodeForm> = (props) => {
const { handleNextStep, email, moveBack } = props;
// states
const [isResendingCode, setIsResendingCode] = useState(false);
// form info
const {
control,
handleSubmit,
reset,
formState: { isSubmitting },
} = useForm<InstanceSetupEmailCodeFormValues>({
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 (
<form onSubmit={handleSubmit(handleEmailCodeFormSubmit)}>
<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">
Paste the code you got at
<br />
<span className="text-custom-primary-100 font-semibold">{email}</span> below.
</p>
<div className="relative mt-5 w-full sm:w-96 mx-auto space-y-4">
<div>
<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}
disabled
placeholder="orville.wright@firstflight.com"
className={`w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12`}
/>
<XCircle
className="h-5 w-5 absolute stroke-custom-text-400 hover:cursor-pointer right-3"
onClick={() => moveBack()}
/>
</div>
)}
/>
<div className="w-full text-right">
<button
type="button"
onClick={resendMagicCode}
className={`text-xs ${
isResendDisabled ? "text-onboarding-text-300" : "text-onboarding-text-200 hover:text-custom-primary-100"
}`}
disabled={isResendDisabled}
>
{timer > 0
? `Request new code in ${timer}s`
: isSubmitting
? "Requesting new code..."
: "Request new code"}
</button>
</div>
</div>
<Controller
name="token"
control={control}
rules={{ required: true }}
render={({ field: { value, onChange } }) => (
<div className={`flex items-center relative rounded-md bg-onboarding-background-200 mb-4`}>
<Input
id="token"
name="token"
type="text"
value={value}
onChange={onChange}
placeholder="gets-sets-fays"
className="border-onboarding-border-100 h-[46px] w-full "
/>
</div>
)}
/>
<Button variant="primary" className="w-full" size="xl" type="submit" loading={isSubmitting}>
{isSubmitting ? "Verifying..." : "Next step"}
</Button>
</div>
</form>
);
};

View file

@ -1,3 +1,2 @@
export * from "./email-code-form";
export * from "./email-form";
export * from "./root";
export * from "./sign-in-form";

View file

@ -1,126 +0,0 @@
import React from "react";
import Link from "next/link";
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();
export interface InstanceSetupPasswordFormValues {
email: string;
password: string;
}
export interface IInstanceSetupPasswordForm {
email: string;
onNextStep: () => void;
resetSteps: () => void;
}
export const InstanceSetupPasswordForm: React.FC<IInstanceSetupPasswordForm> = (props) => {
const { onNextStep, email, resetSteps } = props;
// form info
const {
control,
handleSubmit,
formState: { errors, isSubmitting },
} = useForm<InstanceSetupPasswordFormValues>({
defaultValues: {
email,
password: "",
},
mode: "onChange",
reValidateMode: "onChange",
});
const handlePasswordSubmit = (formData: InstanceSetupPasswordFormValues) =>
authService.setInstanceAdminPassword({ password: formData.password }).then(() => {
onNextStep();
});
return (
<form onSubmit={handleSubmit(handlePasswordSubmit)}>
<div className="pb-2">
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Moving to the runway
</h1>
<p className="text-center text-sm text-onboarding-text-200 mt-3">
Let{"'"}s set a password so you can do away with codes.
</p>
<div className="relative mt-5 w-full sm:w-96 mx-auto space-y-4">
<Controller
control={control}
name="email"
rules={{
required: "Email 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`}
/>
<XCircle
className="h-5 w-5 absolute stroke-custom-text-400 hover:cursor-pointer right-3"
onClick={() => resetSteps()}
/>
</div>
)}
/>
<div>
<Controller
control={control}
name="password"
rules={{
required: "Password is required",
minLength: {
value: 8,
message: "Minimum 8 characters required",
},
}}
render={({ field: { value, onChange } }) => (
<div className={`flex items-center relative rounded-md bg-onboarding-background-200`}>
<Input
id="password"
type="password"
name="password"
value={value}
onChange={onChange}
hasError={Boolean(errors.password)}
placeholder="Enter your password..."
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
/>
</div>
)}
/>
<p className="text-xs mt-3 text-onboarding-text-200 pb-2">
Whatever you choose now will be your account{"'"}s password
</p>
</div>
<Button variant="primary" className="w-full mt-4" size="xl" type="submit" loading={isSubmitting}>
{isSubmitting ? "Submitting..." : "Next step"}
</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>
</div>
</div>
</form>
);
};

View file

@ -1,63 +1,25 @@
import { useState } from "react";
// components
import { InstanceSetupEmailCodeForm } from "./email-code-form";
import { InstanceSetupEmailForm } from "./email-form";
import { InstanceSetupPasswordForm } from "./password-form";
import { LatestFeatureBlock } from "components/common";
import { InstanceSetupDone } from "components/instance";
import { InstanceSetupDone, InstanceSetupSignInForm } from "components/instance";
export enum EInstanceSetupSteps {
EMAIL = "EMAIL",
VERIFY_CODE = "VERIFY_CODE",
PASSWORD = "PASSWORD",
SIGN_IN = "SIGN_IN",
DONE = "DONE",
}
export const InstanceSetupFormRoot = () => {
// states
const [setupStep, setSetupStep] = useState(EInstanceSetupSteps.EMAIL);
const [email, setEmail] = useState<string>("");
const [setupStep, setSetupStep] = useState(EInstanceSetupSteps.SIGN_IN);
return (
<>
{setupStep === EInstanceSetupSteps.DONE ? (
<InstanceSetupDone />
) : (
{setupStep === EInstanceSetupSteps.DONE && <InstanceSetupDone />}
{setupStep === EInstanceSetupSteps.SIGN_IN && (
<div className="h-full bg-onboarding-gradient-100 md:w-2/3 sm:w-4/5 px-4 pt-4 rounded-t-md mx-auto shadow-sm border-x border-t border-custom-border-200">
<div className="bg-onboarding-gradient-200 h-full pt-24 pb-56 rounded-t-md overflow-auto">
<div className="mx-auto flex flex-col">
{setupStep === EInstanceSetupSteps.EMAIL && (
<InstanceSetupEmailForm
handleNextStep={(email) => {
setEmail(email);
setSetupStep(EInstanceSetupSteps.VERIFY_CODE);
}}
/>
)}
{setupStep === EInstanceSetupSteps.VERIFY_CODE && (
<InstanceSetupEmailCodeForm
email={email}
handleNextStep={() => {
setSetupStep(EInstanceSetupSteps.PASSWORD);
}}
moveBack={() => {
setSetupStep(EInstanceSetupSteps.EMAIL);
}}
/>
)}
{setupStep === EInstanceSetupSteps.PASSWORD && (
<InstanceSetupPasswordForm
email={email}
onNextStep={() => {
setSetupStep(EInstanceSetupSteps.DONE);
}}
resetSteps={() => {
setSetupStep(EInstanceSetupSteps.EMAIL);
}}
/>
)}
<InstanceSetupSignInForm handleNextStep={() => setSetupStep(EInstanceSetupSteps.DONE)} />
</div>
<LatestFeatureBlock />
</div>

View file

@ -1,5 +1,7 @@
import { FC } from "react";
import { useForm, Controller } from "react-hook-form";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// ui
import { Input, Button } from "@plane/ui";
// icons
@ -9,37 +11,48 @@ import { AuthService } from "services/auth.service";
const authService = new AuthService();
// hooks
import useToast from "hooks/use-toast";
// helpers
import { checkEmailValidity } from "helpers/string.helper";
export interface InstanceSetupEmailFormValues {
interface InstanceSetupEmailFormValues {
email: string;
password: string;
}
export interface IInstanceSetupEmailForm {
handleNextStep: (email: string) => void;
}
export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
export const InstanceSetupSignInForm: FC<IInstanceSetupEmailForm> = (props) => {
const { handleNextStep } = props;
const {
user: { fetchCurrentUser },
} = useMobxStore();
// form info
const {
control,
formState: { errors, isSubmitting },
handleSubmit,
setValue,
reset,
formState: { isSubmitting },
} = useForm<InstanceSetupEmailFormValues>({
defaultValues: {
email: "",
password: "",
},
});
// hooks
const { setToastAlert } = useToast();
const handleEmailFormSubmit = (formValues: InstanceSetupEmailFormValues) =>
authService
.instanceAdminEmailCode({ email: formValues.email })
.then(() => {
reset();
const handleFormSubmit = async (formValues: InstanceSetupEmailFormValues) => {
const payload = {
email: formValues.email,
password: formValues.password,
};
await authService
.instanceAdminSignIn(payload)
.then(async () => {
await fetchCurrentUser();
handleNextStep(formValues.email);
})
.catch((err) => {
@ -49,9 +62,10 @@ export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
message: err?.error ?? "Something went wrong. Please try again.",
});
});
};
return (
<form onSubmit={handleSubmit(handleEmailFormSubmit)}>
<form onSubmit={handleSubmit(handleFormSubmit)}>
<h1 className="text-center text-2xl sm:text-2.5xl font-medium text-onboarding-text-100">
Let{"'"}s secure your instance
</h1>
@ -66,13 +80,10 @@ export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
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",
validate: (value) => checkEmailValidity(value) || "Email is invalid",
}}
render={({ field: { value, onChange } }) => (
<div className={`flex items-center relative rounded-md bg-onboarding-background-200`}>
<div className="flex items-center relative rounded-md bg-onboarding-background-200">
<Input
id="email"
name="email"
@ -80,7 +91,7 @@ export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
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`}
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
/>
{value.length > 0 && (
<XCircle
@ -91,11 +102,28 @@ export const InstanceSetupEmailForm: FC<IInstanceSetupEmailForm> = (props) => {
</div>
)}
/>
<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"
/>
)}
/>
<p className="text-xs text-custom-text-200 pb-2">
Use your email address if you are the instance admin. <br /> Use your admins e-mail if you are not.
</p>
<Button variant="primary" className="w-full" size="xl" type="submit" loading={isSubmitting}>
{isSubmitting ? "Sending code..." : "Send unique code"}
{isSubmitting ? "Signing in..." : "Sign in"}
</Button>
</div>
</form>

View file

@ -1,9 +1,6 @@
import { useEffect } from "react";
import Link from "next/link";
import { observer } from "mobx-react-lite";
import Image from "next/image";
import { useTheme } from "next-themes";
import { Lightbulb } from "lucide-react";
// mobx store
import { useMobxStore } from "lib/mobx/store-provider";
// hooks
@ -14,7 +11,6 @@ import { SignInRoot } from "components/account";
import { Loader, Spinner } from "@plane/ui";
// images
import BluePlaneLogoWithoutText from "public/plane-logos/blue-without-text.png";
import latestFeatures from "public/onboarding/onboarding-pages.svg";
export type AuthType = "sign-in" | "sign-up";
@ -24,8 +20,6 @@ export const SignInView = observer(() => {
user: { currentUser },
appConfig: { envConfig },
} = useMobxStore();
// next-themes
const { resolvedTheme } = useTheme();
// sign in redirection hook
const { isRedirecting, handleRedirection } = useSignInRedirection();
@ -66,30 +60,7 @@ export const SignInView = observer(() => {
</div>
</div>
) : (
<>
<SignInRoot />
<div className="flex py-2 bg-onboarding-background-100 border border-onboarding-border-200 mx-auto rounded-[3.5px] sm:w-96 mt-16">
<Lightbulb className="h-7 w-7 mr-2 mx-3" />
<p className="text-sm text-left text-onboarding-text-100">
Pages gets a facelift! Write anything and use Galileo to help you start.{" "}
<Link href="https://plane.so/changelog" target="_blank" rel="noopener noreferrer">
<span className="font-medium text-sm underline hover:cursor-pointer">Learn more</span>
</Link>
</p>
</div>
<div className="border border-onboarding-border-200 sm:w-96 sm:h-52 object-cover mt-8 mx-auto rounded-md bg-onboarding-background-100 overflow-hidden">
<div className="h-[90%]">
<Image
src={latestFeatures}
alt="Plane Issues"
className={`rounded-md h-full ml-8 -mt-2 ${
resolvedTheme === "dark" ? "bg-onboarding-background-100" : "bg-custom-primary-70"
} `}
/>
</div>
</div>
</>
<SignInRoot />
)}
</div>
</div>

View file

@ -1,4 +1,4 @@
import { FC, ReactNode, useEffect } from "react";
import { FC, ReactNode } from "react";
import useSWR from "swr";
@ -18,7 +18,7 @@ type Props = {
const InstanceLayout: FC<Props> = observer(({ children }) => {
// store
const {
instance: { fetchInstanceInfo, instance, createInstance },
instance: { fetchInstanceInfo, instance },
} = useMobxStore();
const router = useRouter();
@ -28,12 +28,6 @@ const InstanceLayout: FC<Props> = observer(({ children }) => {
revalidateOnFocus: false,
});
useEffect(() => {
if (instance?.is_activated === false) {
createInstance();
}
}, [instance?.is_activated, createInstance]);
return (
<div className="h-screen w-full overflow-hidden">
{instance ? (

View file

@ -109,7 +109,7 @@ const HomePage: NextPageWithLayout = () => {
ref={ref}
hasError={Boolean(errors.email)}
placeholder="orville.wright@firstflight.com"
className="w-full h-[46px] text-onboarding-text-400 border border-onboarding-border-100 pr-12"
className="w-full h-[46px] text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
disabled
/>
)}
@ -128,7 +128,7 @@ const HomePage: NextPageWithLayout = () => {
onChange={onChange}
hasError={Boolean(errors.password)}
placeholder="Choose password"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12"
className="w-full h-[46px] placeholder:text-onboarding-text-400 border border-onboarding-border-100 pr-12 !bg-onboarding-background-200"
minLength={8}
/>
)}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 528 KiB

After

Width:  |  Height:  |  Size: 2.6 MiB

Before After
Before After

View file

@ -3,16 +3,20 @@ import { APIService } from "services/api.service";
// helpers
import { API_BASE_URL } from "helpers/common.helper";
// types
import { IEmailCheckData, ILoginTokenResponse, IMagicSignInData, IPasswordSignInData } from "types/auth";
import {
IEmailCheckData,
IEmailCheckResponse,
ILoginTokenResponse,
IMagicSignInData,
IPasswordSignInData,
} from "types/auth";
export class AuthService extends APIService {
constructor() {
super(API_BASE_URL);
}
async emailCheck(data: IEmailCheckData): Promise<{
is_password_autoset: boolean;
}> {
async emailCheck(data: IEmailCheckData): Promise<IEmailCheckResponse> {
return this.post("/api/email-check/", data, { headers: {} })
.then((response) => response?.data)
.catch((error) => {
@ -80,18 +84,6 @@ export class AuthService extends APIService {
});
}
async setInstanceAdminPassword(data: any): Promise<any> {
return this.post("/api/licenses/instances/admins/set-password/", data)
.then((response) => {
this.setAccessToken(response?.data?.access_token);
this.setRefreshToken(response?.data?.refresh_token);
return response?.data;
})
.catch((error) => {
throw error?.response?.data;
});
}
async socialAuth(data: any): Promise<ILoginTokenResponse> {
return this.post("/api/social-auth/", data, { headers: {} })
.then((response) => {
@ -104,7 +96,7 @@ export class AuthService extends APIService {
});
}
async emailCode(data: any): Promise<any> {
async generateUniqueCode(data: { email: string }): Promise<any> {
return this.post("/api/magic-generate/", data, { headers: {} })
.then((response) => response?.data)
.catch((error) => {
@ -112,14 +104,6 @@ export class AuthService extends APIService {
});
}
async instanceAdminEmailCode(data: any): Promise<any> {
return this.post("/api/licenses/instances/admins/magic-generate/", data, { headers: {} })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
async magicSignIn(data: IMagicSignInData): Promise<any> {
return await this.post("/api/magic-sign-in/", data, { headers: {} })
.then((response) => {
@ -134,14 +118,18 @@ export class AuthService extends APIService {
});
}
async instanceMagicSignIn(data: any): Promise<any> {
const response = await this.post("/api/licenses/instances/admins/magic-sign-in/", data, { headers: {} });
if (response?.status === 200) {
this.setAccessToken(response?.data?.access_token);
this.setRefreshToken(response?.data?.refresh_token);
return response?.data;
}
throw response.response.data;
async instanceAdminSignIn(data: IPasswordSignInData): Promise<ILoginTokenResponse> {
return await this.post("/api/licenses/instances/admins/sign-in/", data, { headers: {} })
.then((response) => {
if (response?.status === 200) {
this.setAccessToken(response?.data?.access_token);
this.setRefreshToken(response?.data?.refresh_token);
return response?.data;
}
})
.catch((error) => {
throw error?.response?.data;
});
}
async signOut(): Promise<any> {

View file

@ -22,14 +22,6 @@ export class InstanceService extends APIService {
});
}
async createInstance(): Promise<IInstance> {
return this.post("/api/licenses/instances/", {}, { headers: {} })
.then((response) => response.data)
.catch((error) => {
throw error;
});
}
async getInstanceAdmins(): Promise<IInstanceAdmin[]> {
return this.get("/api/licenses/instances/admins/")
.then((response) => response.data)

View file

@ -17,7 +17,6 @@ export interface IInstanceStore {
formattedConfig: IFormattedInstanceConfiguration | null;
// action
fetchInstanceInfo: () => Promise<IInstance>;
createInstance: () => Promise<IInstance>;
fetchInstanceAdmins: () => Promise<IInstanceAdmin[]>;
updateInstanceInfo: (data: Partial<IInstance>) => Promise<IInstance>;
fetchInstanceConfigurations: () => Promise<any>;
@ -46,7 +45,6 @@ export class InstanceStore implements IInstanceStore {
formattedConfig: computed,
// actions
fetchInstanceInfo: action,
createInstance: action,
fetchInstanceAdmins: action,
updateInstanceInfo: action,
fetchInstanceConfigurations: action,
@ -86,22 +84,6 @@ export class InstanceStore implements IInstanceStore {
}
};
/**
* Creating new Instance In case of no instance found
*/
createInstance = async () => {
try {
const instance = await this.instanceService.createInstance();
runInAction(() => {
this.instance = instance;
});
return instance;
} catch (error) {
console.log("Error while creating the instance");
throw error;
}
};
/**
* fetch instance admins from API
*/

1
web/types/app.d.ts vendored
View file

@ -14,4 +14,5 @@ export interface IAppConfig {
posthog_host: string | null;
has_openai_configured: boolean;
has_unsplash_configured: boolean;
is_self_managed: boolean;
}

8
web/types/auth.d.ts vendored
View file

@ -2,12 +2,16 @@ export type TEmailCheckTypes = "magic_code" | "password";
export interface IEmailCheckData {
email: string;
type: TEmailCheckTypes;
}
export interface IEmailCheckResponse {
is_password_autoset: boolean;
is_existing: boolean;
}
export interface ILoginTokenResponse {
access_token: string;
refresh_toke: string;
refresh_token: string;
}
export interface IMagicSignInData {