2019-12-16 08:49:10 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { reduxForm, InjectedFormProps } from "redux-form";
|
|
|
|
|
import { AUTH_LOGIN_URL } from "constants/routes";
|
|
|
|
|
import { SIGNUP_FORM_NAME } from "constants/forms";
|
2020-08-28 10:51:41 +00:00
|
|
|
import {
|
|
|
|
|
Link,
|
|
|
|
|
RouteComponentProps,
|
|
|
|
|
useLocation,
|
|
|
|
|
withRouter,
|
|
|
|
|
} from "react-router-dom";
|
2019-12-16 08:49:10 +00:00
|
|
|
import Divider from "components/editorComponents/Divider";
|
|
|
|
|
import {
|
|
|
|
|
AuthCardHeader,
|
|
|
|
|
AuthCardBody,
|
|
|
|
|
AuthCardFooter,
|
|
|
|
|
AuthCardNavLink,
|
2020-08-10 12:19:46 +00:00
|
|
|
SpacedSubmitForm,
|
2019-12-16 08:49:10 +00:00
|
|
|
FormActions,
|
|
|
|
|
AuthCardContainer,
|
|
|
|
|
} from "./StyledComponents";
|
|
|
|
|
import {
|
|
|
|
|
SIGNUP_PAGE_TITLE,
|
|
|
|
|
SIGNUP_PAGE_SUBTITLE,
|
|
|
|
|
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_EMAIL,
|
|
|
|
|
FORM_VALIDATION_EMPTY_PASSWORD,
|
|
|
|
|
FORM_VALIDATION_INVALID_EMAIL,
|
|
|
|
|
FORM_VALIDATION_INVALID_PASSWORD,
|
|
|
|
|
SIGNUP_PAGE_SUBMIT_BUTTON_TEXT,
|
|
|
|
|
PRIVACY_POLICY_LINK,
|
|
|
|
|
TERMS_AND_CONDITIONS_LINK,
|
2020-02-25 11:38:53 +00:00
|
|
|
FORM_VALIDATION_PASSWORD_RULE,
|
2019-12-16 08:49:10 +00:00
|
|
|
} from "constants/messages";
|
2019-12-23 12:16:33 +00:00
|
|
|
import FormMessage from "components/editorComponents/form/FormMessage";
|
|
|
|
|
import FormGroup from "components/editorComponents/form/FormGroup";
|
2020-02-25 11:38:53 +00:00
|
|
|
import FormTextField from "components/editorComponents/form/FormTextField";
|
2019-12-16 08:49:10 +00:00
|
|
|
import ThirdPartyAuth, { SocialLoginTypes } from "./ThirdPartyAuth";
|
2020-02-24 09:35:11 +00:00
|
|
|
import Button from "components/editorComponents/Button";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
import { isEmail, isStrongPassword, isEmptyString } from "utils/formhelpers";
|
|
|
|
|
|
2020-08-10 12:19:46 +00:00
|
|
|
import { SignupFormValues } from "./helpers";
|
2020-03-11 13:59:46 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
2020-07-07 10:22:17 +00:00
|
|
|
import { getAppsmithConfigs } from "configs";
|
2020-08-10 12:19:46 +00:00
|
|
|
import { SIGNUP_SUBMIT_PATH } from "constants/ApiConstants";
|
2020-08-14 06:01:50 +00:00
|
|
|
import { connect } from "react-redux";
|
2020-09-01 10:31:39 +00:00
|
|
|
import { AppState } from "reducers";
|
2020-09-28 06:29:41 +00:00
|
|
|
import PerformanceTracker, {
|
|
|
|
|
PerformanceTransactionName,
|
|
|
|
|
} from "utils/PerformanceTracker";
|
2020-12-30 07:31:20 +00:00
|
|
|
import { setOnboardingState } from "utils/storage";
|
2020-07-07 10:22:17 +00:00
|
|
|
const {
|
|
|
|
|
enableGithubOAuth,
|
|
|
|
|
enableGoogleOAuth,
|
|
|
|
|
enableTNCPP,
|
|
|
|
|
} = getAppsmithConfigs();
|
|
|
|
|
const SocialLoginList: string[] = [];
|
|
|
|
|
if (enableGithubOAuth) SocialLoginList.push(SocialLoginTypes.GITHUB);
|
|
|
|
|
if (enableGoogleOAuth) SocialLoginList.push(SocialLoginTypes.GOOGLE);
|
|
|
|
|
|
|
|
|
|
export const TncPPLinks = () => {
|
|
|
|
|
if (!enableTNCPP) return null;
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Link target="_blank" to="/privacy-policy.html">
|
|
|
|
|
{PRIVACY_POLICY_LINK}
|
|
|
|
|
</Link>
|
|
|
|
|
<Link target="_blank" to="/terms-and-conditions.html">
|
|
|
|
|
{TERMS_AND_CONDITIONS_LINK}
|
|
|
|
|
</Link>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
const validate = (values: SignupFormValues) => {
|
|
|
|
|
const errors: SignupFormValues = {};
|
|
|
|
|
if (!values.password || isEmptyString(values.password)) {
|
|
|
|
|
errors.password = FORM_VALIDATION_EMPTY_PASSWORD;
|
|
|
|
|
} else if (!isStrongPassword(values.password)) {
|
|
|
|
|
errors.password = FORM_VALIDATION_INVALID_PASSWORD;
|
|
|
|
|
}
|
|
|
|
|
if (!values.email || isEmptyString(values.email)) {
|
|
|
|
|
errors.email = FORM_VALIDATION_EMPTY_EMAIL;
|
|
|
|
|
} else if (!isEmail(values.email)) {
|
|
|
|
|
errors.email = FORM_VALIDATION_INVALID_EMAIL;
|
|
|
|
|
}
|
|
|
|
|
return errors;
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-28 10:51:41 +00:00
|
|
|
type SignUpFormProps = InjectedFormProps<SignupFormValues> &
|
|
|
|
|
RouteComponentProps<{ email: string }>;
|
2020-08-14 06:01:50 +00:00
|
|
|
|
|
|
|
|
export const SignUp = (props: SignUpFormProps) => {
|
2020-08-10 12:19:46 +00:00
|
|
|
const { error, submitting, pristine, valid } = props;
|
|
|
|
|
const location = useLocation();
|
|
|
|
|
|
|
|
|
|
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;
|
2020-08-13 09:33:44 +00:00
|
|
|
if (queryParams.has("appId")) {
|
|
|
|
|
signupURL += `?appId=${queryParams.get("appId")}`;
|
2021-01-06 11:24:16 +00:00
|
|
|
} else if (queryParams.has("redirectUrl")) {
|
|
|
|
|
signupURL += `?redirectUrl=${queryParams.get("redirectUrl")}`;
|
2020-08-10 12:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
return (
|
|
|
|
|
<AuthCardContainer>
|
2020-08-10 12:19:46 +00:00
|
|
|
{showError && <FormMessage intent="danger" message={errorMessage} />}
|
2019-12-16 08:49:10 +00:00
|
|
|
<AuthCardHeader>
|
|
|
|
|
<h1>{SIGNUP_PAGE_TITLE}</h1>
|
|
|
|
|
<h5>{SIGNUP_PAGE_SUBTITLE}</h5>
|
|
|
|
|
</AuthCardHeader>
|
|
|
|
|
<AuthCardBody>
|
2020-08-10 12:19:46 +00:00
|
|
|
<SpacedSubmitForm method="POST" action={signupURL}>
|
2019-12-16 08:49:10 +00:00
|
|
|
<FormGroup
|
|
|
|
|
intent={error ? "danger" : "none"}
|
|
|
|
|
label={SIGNUP_PAGE_EMAIL_INPUT_LABEL}
|
|
|
|
|
>
|
2020-02-25 11:38:53 +00:00
|
|
|
<FormTextField
|
2019-12-16 08:49:10 +00:00
|
|
|
name="email"
|
|
|
|
|
type="email"
|
|
|
|
|
placeholder={SIGNUP_PAGE_EMAIL_INPUT_PLACEHOLDER}
|
2020-10-07 07:07:16 +00:00
|
|
|
autoFocus
|
2019-12-16 08:49:10 +00:00
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup
|
|
|
|
|
intent={error ? "danger" : "none"}
|
|
|
|
|
label={SIGNUP_PAGE_PASSWORD_INPUT_LABEL}
|
2020-02-25 11:38:53 +00:00
|
|
|
helperText={FORM_VALIDATION_PASSWORD_RULE}
|
2019-12-16 08:49:10 +00:00
|
|
|
>
|
2020-02-25 11:38:53 +00:00
|
|
|
<FormTextField
|
2019-12-16 08:49:10 +00:00
|
|
|
type="password"
|
|
|
|
|
name="password"
|
|
|
|
|
placeholder={SIGNUP_PAGE_PASSWORD_INPUT_PLACEHOLDER}
|
|
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormActions>
|
2020-02-24 09:35:11 +00:00
|
|
|
<Button
|
2019-12-16 08:49:10 +00:00
|
|
|
type="submit"
|
2020-01-06 09:07:30 +00:00
|
|
|
disabled={pristine || !valid}
|
2019-12-16 08:49:10 +00:00
|
|
|
loading={submitting}
|
|
|
|
|
text={SIGNUP_PAGE_SUBMIT_BUTTON_TEXT}
|
|
|
|
|
intent="primary"
|
2020-02-24 09:35:11 +00:00
|
|
|
filled
|
|
|
|
|
size="large"
|
2020-03-11 13:59:46 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
AnalyticsUtil.logEvent("SIGNUP_CLICK", {
|
|
|
|
|
signupMethod: "EMAIL",
|
|
|
|
|
});
|
2020-09-28 06:29:41 +00:00
|
|
|
PerformanceTracker.startTracking(
|
|
|
|
|
PerformanceTransactionName.SIGN_UP,
|
|
|
|
|
);
|
2020-12-30 07:31:20 +00:00
|
|
|
setOnboardingState(true);
|
2020-03-11 13:59:46 +00:00
|
|
|
}}
|
2019-12-16 08:49:10 +00:00
|
|
|
/>
|
|
|
|
|
</FormActions>
|
2020-08-10 12:19:46 +00:00
|
|
|
</SpacedSubmitForm>
|
2020-10-05 07:05:20 +00:00
|
|
|
{SocialLoginList.length > 0 && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<ThirdPartyAuth type={"SIGNUP"} logins={SocialLoginList} />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2019-12-16 08:49:10 +00:00
|
|
|
</AuthCardBody>
|
2020-07-07 10:22:17 +00:00
|
|
|
<AuthCardFooter>
|
2020-08-10 12:19:46 +00:00
|
|
|
<TncPPLinks />
|
2020-07-07 10:22:17 +00:00
|
|
|
</AuthCardFooter>
|
2019-12-16 08:49:10 +00:00
|
|
|
<AuthCardNavLink to={AUTH_LOGIN_URL}>
|
|
|
|
|
{SIGNUP_PAGE_LOGIN_LINK_TEXT}
|
|
|
|
|
</AuthCardNavLink>
|
|
|
|
|
</AuthCardContainer>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-28 10:51:41 +00:00
|
|
|
export default connect((state: AppState, props: SignUpFormProps) => {
|
|
|
|
|
const queryParams = new URLSearchParams(props.location.search);
|
|
|
|
|
return {
|
|
|
|
|
initialValues: {
|
|
|
|
|
email: queryParams.get("email"),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}, null)(
|
2020-08-14 06:01:50 +00:00
|
|
|
reduxForm<SignupFormValues>({
|
|
|
|
|
validate,
|
|
|
|
|
form: SIGNUP_FORM_NAME,
|
|
|
|
|
touchOnBlur: true,
|
|
|
|
|
})(withRouter(SignUp)),
|
|
|
|
|
);
|