* refactor admin settings feature * separated save-restart bar to separate component * created new CE dir to facilitate code split * created separate ee dir and exporting everything we have in ce file. * little mod * minor fix * splitting settings types config * using object literals for category types instead of enums * CE: support use of component for each category * minor style fix * authentication page UI changes implemented * github signup doc url added back * removed comments * routing updates * made subcategories listing in left pane optional * added muted saml to auth listing * added breadcrumbs and enabled button * created separate component for auth page and auth config * added callout and disconnect components * updated breadcrumbs component * minor updates to common components * updated warning callout and added icon * ce: test cases fixed * updated test file name * warning banner callout added on auth page * updated callout banner for form login * CE: Split config files * CE: moved the window declaration in EE file as its dependency will be updated in EE * CE: Splitting ApiConstants and SocialLogin constants * CE: split login page * CE: moved getSocialLoginButtonProps func to EE file as it's dependencies will be updated in EE * added key icon * CE: created a factory class to share social auths list * Minor style fix for social btns * Updated the third party auth styles * Small fixes to styling * ce: splitting forms constants * breadcrumbs implemented for all pages in admin settings * Settings breadcrumbs separated * splitted settings breadcrumbs between ce and ee * renamed default import * minor style fix * added login form config. * updated login/signup pages to use form login disabled config * removed common functionality outside * implemented breadcrumb component from scratch without using blueprint * removed unwanted code * Small style update * updated breadcrumb categories file name and breadcrumb icon * added cypress tests for admin settings auth page * added comments * update locator for upgrade button * added link for intercom on upgrade button * removed unnecessary file * minor style fix * style fix for auth option cards * split messages constant * fixed imports for message constants splitting. * added message constants * updated unit test cases * fixed messages import in cypress index * fixed messages import again, cypress fails to read re-exported objs. * added OIDC auth method on authentication page * updated import statements from ee to @appsmith * removed dead code * updated read more link UI * PR comments fixes * some UI fixes * used color and fonts from theme * fixed some imports * fixed some imports * removed warning imports * updated OIDC logo and auth method desc copies * css changes * css changes * css changes * updated cypress test for breadcrumb * moved callout component to ads as calloutv2 * UI changes for form fields * updated css for spacing between form fields * added sub-text on auth pages * added active class for breadcrumb item * added config for disable signup toggle and fixed UI issues of restart banner * fixed admin settings page bugs * assigned true as default state for signup * fixed messages import statements * updated code for PR comments related suggestions * reverted file path change in cypress support * updated cypress test * updated cypress test Co-authored-by: Ankita Kinger <ankita@appsmith.com>
232 lines
7.3 KiB
TypeScript
232 lines
7.3 KiB
TypeScript
import React, { useEffect } from "react";
|
|
import { reduxForm, InjectedFormProps, formValueSelector } from "redux-form";
|
|
import { AUTH_LOGIN_URL } from "constants/routes";
|
|
import { SIGNUP_FORM_NAME } from "constants/forms";
|
|
import {
|
|
RouteComponentProps,
|
|
useHistory,
|
|
useLocation,
|
|
withRouter,
|
|
} from "react-router-dom";
|
|
import {
|
|
AuthCardHeader,
|
|
AuthCardNavLink,
|
|
SpacedSubmitForm,
|
|
FormActions,
|
|
SignUpLinkSection,
|
|
} from "pages/UserAuth/StyledComponents";
|
|
import {
|
|
SIGNUP_PAGE_TITLE,
|
|
SIGNUP_PAGE_EMAIL_INPUT_LABEL,
|
|
SIGNUP_PAGE_EMAIL_INPUT_PLACEHOLDER,
|
|
SIGNUP_PAGE_PASSWORD_INPUT_LABEL,
|
|
SIGNUP_PAGE_PASSWORD_INPUT_PLACEHOLDER,
|
|
SIGNUP_PAGE_LOGIN_LINK_TEXT,
|
|
FORM_VALIDATION_EMPTY_PASSWORD,
|
|
FORM_VALIDATION_INVALID_EMAIL,
|
|
FORM_VALIDATION_INVALID_PASSWORD,
|
|
SIGNUP_PAGE_SUBMIT_BUTTON_TEXT,
|
|
ALREADY_HAVE_AN_ACCOUNT,
|
|
createMessage,
|
|
} from "@appsmith/constants/messages";
|
|
import FormMessage from "components/ads/formFields/FormMessage";
|
|
import FormGroup from "components/ads/formFields/FormGroup";
|
|
import FormTextField from "components/ads/formFields/TextField";
|
|
import ThirdPartyAuth from "@appsmith/pages/UserAuth/ThirdPartyAuth";
|
|
import { ThirdPartyLoginRegistry } from "pages/UserAuth/ThirdPartyLoginRegistry";
|
|
import Button, { Size } from "components/ads/Button";
|
|
|
|
import { isEmail, isStrongPassword, isEmptyString } from "utils/formhelpers";
|
|
|
|
import { SignupFormValues } from "pages/UserAuth/helpers";
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
|
|
import { SIGNUP_SUBMIT_PATH } from "@appsmith/constants/ApiConstants";
|
|
import { connect } from "react-redux";
|
|
import { AppState } from "reducers";
|
|
import PerformanceTracker, {
|
|
PerformanceTransactionName,
|
|
} from "utils/PerformanceTracker";
|
|
|
|
import { SIGNUP_FORM_EMAIL_FIELD_NAME } from "constants/forms";
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
|
import { useScript, ScriptStatus, AddScriptTo } from "utils/hooks/useScript";
|
|
|
|
import { withTheme } from "styled-components";
|
|
import { Theme } from "constants/DefaultTheme";
|
|
import { getIsSafeRedirectURL } from "utils/helpers";
|
|
|
|
declare global {
|
|
interface Window {
|
|
grecaptcha: any;
|
|
}
|
|
}
|
|
const { disableSignup, googleRecaptchaSiteKey } = getAppsmithConfigs();
|
|
|
|
const validate = (values: SignupFormValues) => {
|
|
const errors: SignupFormValues = {};
|
|
if (!values.password || isEmptyString(values.password)) {
|
|
errors.password = createMessage(FORM_VALIDATION_EMPTY_PASSWORD);
|
|
} else if (!isStrongPassword(values.password)) {
|
|
errors.password = createMessage(FORM_VALIDATION_INVALID_PASSWORD);
|
|
}
|
|
|
|
const email = values.email || "";
|
|
if (!isEmptyString(email) && !isEmail(email)) {
|
|
errors.email = createMessage(FORM_VALIDATION_INVALID_EMAIL);
|
|
}
|
|
return errors;
|
|
};
|
|
|
|
type SignUpFormProps = InjectedFormProps<
|
|
SignupFormValues,
|
|
{ emailValue: string }
|
|
> &
|
|
RouteComponentProps<{ email: string }> & { theme: Theme; emailValue: string };
|
|
|
|
export function SignUp(props: SignUpFormProps) {
|
|
const history = useHistory();
|
|
useEffect(() => {
|
|
if (disableSignup) {
|
|
history.replace(AUTH_LOGIN_URL);
|
|
}
|
|
}, []);
|
|
const { emailValue: email, error, pristine, submitting, valid } = props;
|
|
const isFormValid = valid && email && !isEmptyString(email);
|
|
const socialLoginList = ThirdPartyLoginRegistry.get();
|
|
const location = useLocation();
|
|
|
|
const recaptchaStatus = useScript(
|
|
`https://www.google.com/recaptcha/api.js?render=${googleRecaptchaSiteKey.apiKey}`,
|
|
AddScriptTo.HEAD,
|
|
);
|
|
|
|
let showError = false;
|
|
let errorMessage = "";
|
|
const queryParams = new URLSearchParams(location.search);
|
|
if (queryParams.get("error")) {
|
|
errorMessage = queryParams.get("error") || "";
|
|
showError = true;
|
|
}
|
|
|
|
let signupURL = "/api/v1/" + SIGNUP_SUBMIT_PATH;
|
|
if (queryParams.has("appId")) {
|
|
signupURL += `?appId=${queryParams.get("appId")}`;
|
|
} else {
|
|
const redirectUrl = queryParams.get("redirectUrl");
|
|
if (redirectUrl != null && getIsSafeRedirectURL(redirectUrl)) {
|
|
signupURL += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{showError && <FormMessage intent="danger" message={errorMessage} />}
|
|
<AuthCardHeader>
|
|
<h1>{createMessage(SIGNUP_PAGE_TITLE)}</h1>
|
|
</AuthCardHeader>
|
|
<SignUpLinkSection>
|
|
{createMessage(ALREADY_HAVE_AN_ACCOUNT)}
|
|
<AuthCardNavLink
|
|
style={{ marginLeft: props.theme.spaces[3] }}
|
|
to={AUTH_LOGIN_URL}
|
|
>
|
|
{createMessage(SIGNUP_PAGE_LOGIN_LINK_TEXT)}
|
|
</AuthCardNavLink>
|
|
</SignUpLinkSection>
|
|
{socialLoginList.length > 0 && (
|
|
<ThirdPartyAuth logins={socialLoginList} type={"SIGNUP"} />
|
|
)}
|
|
<SpacedSubmitForm
|
|
action={signupURL}
|
|
id="signup-form"
|
|
method="POST"
|
|
onSubmit={(e) => {
|
|
e.preventDefault();
|
|
const formElement: HTMLFormElement = document.getElementById(
|
|
"signup-form",
|
|
) as HTMLFormElement;
|
|
if (
|
|
googleRecaptchaSiteKey.enabled &&
|
|
recaptchaStatus === ScriptStatus.READY
|
|
) {
|
|
window.grecaptcha
|
|
.execute(googleRecaptchaSiteKey.apiKey, {
|
|
action: "submit",
|
|
})
|
|
.then(function(token: any) {
|
|
formElement &&
|
|
formElement.setAttribute(
|
|
"action",
|
|
`${signupURL}?recaptchaToken=${token}`,
|
|
);
|
|
formElement && formElement.submit();
|
|
});
|
|
} else {
|
|
formElement && formElement.submit();
|
|
}
|
|
return false;
|
|
}}
|
|
>
|
|
<FormGroup
|
|
intent={error ? "danger" : "none"}
|
|
label={createMessage(SIGNUP_PAGE_EMAIL_INPUT_LABEL)}
|
|
>
|
|
<FormTextField
|
|
autoFocus
|
|
name="email"
|
|
placeholder={createMessage(SIGNUP_PAGE_EMAIL_INPUT_PLACEHOLDER)}
|
|
type="email"
|
|
/>
|
|
</FormGroup>
|
|
<FormGroup
|
|
intent={error ? "danger" : "none"}
|
|
label={createMessage(SIGNUP_PAGE_PASSWORD_INPUT_LABEL)}
|
|
>
|
|
<FormTextField
|
|
name="password"
|
|
placeholder={createMessage(SIGNUP_PAGE_PASSWORD_INPUT_PLACEHOLDER)}
|
|
type="password"
|
|
/>
|
|
</FormGroup>
|
|
<FormActions>
|
|
<Button
|
|
disabled={pristine || !isFormValid}
|
|
fill
|
|
isLoading={submitting}
|
|
onClick={() => {
|
|
AnalyticsUtil.logEvent("SIGNUP_CLICK", {
|
|
signupMethod: "EMAIL",
|
|
});
|
|
PerformanceTracker.startTracking(
|
|
PerformanceTransactionName.SIGN_UP,
|
|
);
|
|
}}
|
|
size={Size.large}
|
|
tag="button"
|
|
text={createMessage(SIGNUP_PAGE_SUBMIT_BUTTON_TEXT)}
|
|
type="submit"
|
|
/>
|
|
</FormActions>
|
|
</SpacedSubmitForm>
|
|
</>
|
|
);
|
|
}
|
|
|
|
const selector = formValueSelector(SIGNUP_FORM_NAME);
|
|
export default connect((state: AppState, props: SignUpFormProps) => {
|
|
const queryParams = new URLSearchParams(props.location.search);
|
|
return {
|
|
initialValues: {
|
|
email: queryParams.get("email"),
|
|
},
|
|
emailValue: selector(state, SIGNUP_FORM_EMAIL_FIELD_NAME),
|
|
};
|
|
}, null)(
|
|
reduxForm<SignupFormValues, { emailValue: string }>({
|
|
validate,
|
|
form: SIGNUP_FORM_NAME,
|
|
touchOnBlur: true,
|
|
})(withRouter(withTheme(SignUp))),
|
|
);
|