mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: banner redirect handling the email
This commit is contained in:
parent
f0faf028c2
commit
c04caaf74d
@ -88,7 +88,7 @@ export const AuthRoot: FC<TAuthRoot> = observer((props) => {
|
|||||||
setAuthStep(EAuthSteps.PASSWORD);
|
setAuthStep(EAuthSteps.PASSWORD);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
const errorhandler = authErrorHandler(error?.error_code.toString());
|
const errorhandler = authErrorHandler(error?.error_code.toString(), data?.email || undefined);
|
||||||
if (errorhandler?.type === EErrorAlertType.BANNER_ALERT) {
|
if (errorhandler?.type === EErrorAlertType.BANNER_ALERT) {
|
||||||
setErrorInfo(errorhandler);
|
setErrorInfo(errorhandler);
|
||||||
return;
|
return;
|
||||||
|
@ -356,7 +356,7 @@ export const ProfileSetup: React.FC<Props> = observer((props) => {
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
hasError={Boolean(errors.first_name)}
|
hasError={Boolean(errors.first_name)}
|
||||||
placeholder="RWilbur"
|
placeholder="Wilbur"
|
||||||
className="w-full border-onboarding-border-100"
|
className="w-full border-onboarding-border-100"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -72,27 +72,29 @@ export type TAuthErrorInfo = {
|
|||||||
message: ReactNode;
|
message: ReactNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
const errorCodeMessages: { [key in EAuthenticationErrorCodes]: { title: string; message: ReactNode } } = {
|
const errorCodeMessages: {
|
||||||
|
[key in EAuthenticationErrorCodes]: { title: string; message: (email?: string | undefined) => ReactNode };
|
||||||
|
} = {
|
||||||
[EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED]: {
|
[EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED]: {
|
||||||
title: `Instance not configured`,
|
title: `Instance not configured`,
|
||||||
message: `Instance not configured. Please contact your administrator.`,
|
message: () => `Instance not configured. Please contact your administrator.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.SIGNUP_DISABLED]: {
|
[EAuthenticationErrorCodes.SIGNUP_DISABLED]: {
|
||||||
title: `Sign up disabled`,
|
title: `Sign up disabled`,
|
||||||
message: `Sign up disabled. Please contact your administrator.`,
|
message: () => `Sign up disabled. Please contact your administrator.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_PASSWORD]: {
|
[EAuthenticationErrorCodes.INVALID_PASSWORD]: {
|
||||||
title: `Invalid password`,
|
title: `Invalid password`,
|
||||||
message: `Invalid password. Please try again.`,
|
message: () => `Invalid password. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.USER_ALREADY_EXIST]: {
|
[EAuthenticationErrorCodes.USER_ALREADY_EXIST]: {
|
||||||
title: `User already exists`,
|
title: `User already exists`,
|
||||||
message: (
|
message: (email = undefined) => (
|
||||||
<div>
|
<div>
|
||||||
Your account is already registered.
|
Your account is already registered.
|
||||||
<Link
|
<Link
|
||||||
className="underline underline-offset-4 font-medium hover:font-bold transition-all"
|
className="underline underline-offset-4 font-medium hover:font-bold transition-all"
|
||||||
href={`/accounts/sign-in`}
|
href={`/accounts/sign-in${email ? `?email=${email}` : ``}`}
|
||||||
>
|
>
|
||||||
Sign In
|
Sign In
|
||||||
</Link>
|
</Link>
|
||||||
@ -102,10 +104,13 @@ const errorCodeMessages: { [key in EAuthenticationErrorCodes]: { title: string;
|
|||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.USER_DOES_NOT_EXIST]: {
|
[EAuthenticationErrorCodes.USER_DOES_NOT_EXIST]: {
|
||||||
title: `User does not exist`,
|
title: `User does not exist`,
|
||||||
message: (
|
message: (email = undefined) => (
|
||||||
<div>
|
<div>
|
||||||
No account found.
|
No account found.
|
||||||
<Link className="underline underline-offset-4 font-medium hover:font-bold transition-all" href={`/`}>
|
<Link
|
||||||
|
className="underline underline-offset-4 font-medium hover:font-bold transition-all"
|
||||||
|
href={`/${email ? `?email=${email}` : ``}`}
|
||||||
|
>
|
||||||
Create one
|
Create one
|
||||||
</Link>
|
</Link>
|
||||||
to get started.
|
to get started.
|
||||||
@ -114,123 +119,126 @@ const errorCodeMessages: { [key in EAuthenticationErrorCodes]: { title: string;
|
|||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN]: {
|
[EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_IN]: {
|
||||||
title: `Authentication failed`,
|
title: `Authentication failed`,
|
||||||
message: `Authentication failed. Please try again.`,
|
message: () => `Authentication failed. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP]: {
|
[EAuthenticationErrorCodes.AUTHENTICATION_FAILED_SIGN_UP]: {
|
||||||
title: `Authentication failed`,
|
title: `Authentication failed`,
|
||||||
message: `Authentication failed. Please try again.`,
|
message: () => `Authentication failed. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.SMTP_NOT_CONFIGURED]: {
|
[EAuthenticationErrorCodes.SMTP_NOT_CONFIGURED]: {
|
||||||
title: `SMTP not configured`,
|
title: `SMTP not configured`,
|
||||||
message: `SMTP not configured. Please contact your administrator.`,
|
message: () => `SMTP not configured. Please contact your administrator.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE]: {
|
[EAuthenticationErrorCodes.INVALID_MAGIC_CODE]: {
|
||||||
title: `Authentication failed`,
|
title: `Authentication failed`,
|
||||||
message: `Invalid magic code. Please try again.`,
|
message: () => `Invalid magic code. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE]: {
|
[EAuthenticationErrorCodes.EXPIRED_MAGIC_CODE]: {
|
||||||
title: `Expired magic code`,
|
title: `Expired magic code`,
|
||||||
message: `Expired magic code. Please try again.`,
|
message: () => `Expired magic code. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED]: {
|
[EAuthenticationErrorCodes.GOOGLE_NOT_CONFIGURED]: {
|
||||||
title: `Google not configured`,
|
title: `Google not configured`,
|
||||||
message: `Google not configured. Please contact your administrator.`,
|
message: () => `Google not configured. Please contact your administrator.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED]: {
|
[EAuthenticationErrorCodes.GITHUB_NOT_CONFIGURED]: {
|
||||||
title: `GitHub not configured`,
|
title: `GitHub not configured`,
|
||||||
message: `GitHub not configured. Please contact your administrator.`,
|
message: () => `GitHub not configured. Please contact your administrator.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_EMAIL]: {
|
[EAuthenticationErrorCodes.INVALID_EMAIL]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.EMAIL_REQUIRED]: {
|
[EAuthenticationErrorCodes.EMAIL_REQUIRED]: {
|
||||||
title: `Email required`,
|
title: `Email required`,
|
||||||
message: `Email required. Please try again.`,
|
message: () => `Email required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_IN]: {
|
[EAuthenticationErrorCodes.REQUIRED_EMAIL_PASSWORD_SIGN_IN]: {
|
||||||
title: `Email and password required`,
|
title: `Email and password required`,
|
||||||
message: `Email and password required. Please try again.`,
|
message: () => `Email and password required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN]: {
|
[EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_IN]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_UP]: {
|
[EAuthenticationErrorCodes.INVALID_EMAIL_SIGN_UP]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN]: {
|
[EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_IN]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_UP]: {
|
[EAuthenticationErrorCodes.INVALID_EMAIL_MAGIC_SIGN_UP]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.GITHUB_OAUTH_PROVIDER_ERROR]: {
|
[EAuthenticationErrorCodes.GITHUB_OAUTH_PROVIDER_ERROR]: {
|
||||||
title: `GitHub OAuth provider error`,
|
title: `GitHub OAuth provider error`,
|
||||||
message: `GitHub OAuth provider error. Please try again.`,
|
message: () => `GitHub OAuth provider error. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR]: {
|
[EAuthenticationErrorCodes.GOOGLE_OAUTH_PROVIDER_ERROR]: {
|
||||||
title: `Google OAuth provider error`,
|
title: `Google OAuth provider error`,
|
||||||
message: `Google OAuth provider error. Please try again.`,
|
message: () => `Google OAuth provider error. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED]: {
|
[EAuthenticationErrorCodes.MAGIC_SIGN_IN_EMAIL_CODE_REQUIRED]: {
|
||||||
title: `Email and code required`,
|
title: `Email and code required`,
|
||||||
message: `Email and code required. Please try again.`,
|
message: () => `Email and code required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED]: {
|
[EAuthenticationErrorCodes.MAGIC_SIGN_UP_EMAIL_CODE_REQUIRED]: {
|
||||||
title: `Email and code required`,
|
title: `Email and code required`,
|
||||||
message: `Email and code required. Please try again.`,
|
message: () => `Email and code required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_PASSWORD_TOKEN]: {
|
[EAuthenticationErrorCodes.INVALID_PASSWORD_TOKEN]: {
|
||||||
title: `Invalid password token`,
|
title: `Invalid password token`,
|
||||||
message: `Invalid password token. Please try again.`,
|
message: () => `Invalid password token. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.EXPIRED_PASSWORD_TOKEN]: {
|
[EAuthenticationErrorCodes.EXPIRED_PASSWORD_TOKEN]: {
|
||||||
title: `Expired password token`,
|
title: `Expired password token`,
|
||||||
message: `Expired password token. Please try again.`,
|
message: () => `Expired password token. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD]: {
|
[EAuthenticationErrorCodes.INCORRECT_OLD_PASSWORD]: {
|
||||||
title: `Incorrect old password`,
|
title: `Incorrect old password`,
|
||||||
message: `Incorrect old password. Please try again.`,
|
message: () => `Incorrect old password. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_NEW_PASSWORD]: {
|
[EAuthenticationErrorCodes.INVALID_NEW_PASSWORD]: {
|
||||||
title: `Invalid new password`,
|
title: `Invalid new password`,
|
||||||
message: `Invalid new password. Please try again.`,
|
message: () => `Invalid new password. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.PASSWORD_ALREADY_SET]: {
|
[EAuthenticationErrorCodes.PASSWORD_ALREADY_SET]: {
|
||||||
title: `Password already set`,
|
title: `Password already set`,
|
||||||
message: `Password already set. Please try again.`,
|
message: () => `Password already set. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.ADMIN_ALREADY_EXIST]: {
|
[EAuthenticationErrorCodes.ADMIN_ALREADY_EXIST]: {
|
||||||
title: `Admin already exists`,
|
title: `Admin already exists`,
|
||||||
message: `Admin already exists. Please try again.`,
|
message: () => `Admin already exists. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME]: {
|
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME]: {
|
||||||
title: `Email, password and first name required`,
|
title: `Email, password and first name required`,
|
||||||
message: `Email, password and first name required. Please try again.`,
|
message: () => `Email, password and first name required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_ADMIN_EMAIL]: {
|
[EAuthenticationErrorCodes.INVALID_ADMIN_EMAIL]: {
|
||||||
title: `Invalid email`,
|
title: `Invalid email`,
|
||||||
message: `Invalid email. Please try again.`,
|
message: () => `Invalid email. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.INVALID_ADMIN_PASSWORD]: {
|
[EAuthenticationErrorCodes.INVALID_ADMIN_PASSWORD]: {
|
||||||
title: `Invalid password`,
|
title: `Invalid password`,
|
||||||
message: `Invalid password. Please try again.`,
|
message: () => `Invalid password. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD]: {
|
[EAuthenticationErrorCodes.REQUIRED_ADMIN_EMAIL_PASSWORD]: {
|
||||||
title: `Email and password required`,
|
title: `Email and password required`,
|
||||||
message: `Email and password required. Please try again.`,
|
message: () => `Email and password required. Please try again.`,
|
||||||
},
|
},
|
||||||
[EAuthenticationErrorCodes.ADMIN_AUTHENTICATION_FAILED]: {
|
[EAuthenticationErrorCodes.ADMIN_AUTHENTICATION_FAILED]: {
|
||||||
title: `Authentication failed`,
|
title: `Authentication failed`,
|
||||||
message: `Authentication failed. Please try again.`,
|
message: () => `Authentication failed. Please try again.`,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const authErrorHandler = (errorCode: EAuthenticationErrorCodes): TAuthErrorInfo | undefined => {
|
export const authErrorHandler = (
|
||||||
|
errorCode: EAuthenticationErrorCodes,
|
||||||
|
email?: string | undefined
|
||||||
|
): TAuthErrorInfo | undefined => {
|
||||||
const toastAlertErrorCodes = [
|
const toastAlertErrorCodes = [
|
||||||
EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED,
|
EAuthenticationErrorCodes.INSTANCE_NOT_CONFIGURED,
|
||||||
EAuthenticationErrorCodes.SIGNUP_DISABLED,
|
EAuthenticationErrorCodes.SIGNUP_DISABLED,
|
||||||
@ -275,7 +283,7 @@ export const authErrorHandler = (errorCode: EAuthenticationErrorCodes): TAuthErr
|
|||||||
type: EErrorAlertType.TOAST_ALERT,
|
type: EErrorAlertType.TOAST_ALERT,
|
||||||
code: errorCode,
|
code: errorCode,
|
||||||
title: errorCodeMessages[errorCode]?.title || "Error",
|
title: errorCodeMessages[errorCode]?.title || "Error",
|
||||||
message: errorCodeMessages[errorCode]?.message || "Something went wrong. Please try again.",
|
message: errorCodeMessages[errorCode]?.message(email) || "Something went wrong. Please try again.",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (bannerAlertErrorCodes.includes(errorCode))
|
if (bannerAlertErrorCodes.includes(errorCode))
|
||||||
@ -283,7 +291,7 @@ export const authErrorHandler = (errorCode: EAuthenticationErrorCodes): TAuthErr
|
|||||||
type: EErrorAlertType.BANNER_ALERT,
|
type: EErrorAlertType.BANNER_ALERT,
|
||||||
code: errorCode,
|
code: errorCode,
|
||||||
title: errorCodeMessages[errorCode]?.title || "Error",
|
title: errorCodeMessages[errorCode]?.title || "Error",
|
||||||
message: errorCodeMessages[errorCode]?.message || "Something went wrong. Please try again.",
|
message: errorCodeMessages[errorCode]?.message(email) || "Something went wrong. Please try again.",
|
||||||
};
|
};
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
|
Loading…
Reference in New Issue
Block a user