2022-01-05 04:56:42 +00:00
|
|
|
import React, { useEffect } from "react";
|
2021-01-28 07:20:09 +00:00
|
|
|
import { reduxForm, InjectedFormProps, formValueSelector } from "redux-form";
|
2019-12-16 08:49:10 +00:00
|
|
|
import { AUTH_LOGIN_URL } from "constants/routes";
|
|
|
|
|
import { SIGNUP_FORM_NAME } from "constants/forms";
|
2022-01-05 04:56:42 +00:00
|
|
|
import {
|
|
|
|
|
RouteComponentProps,
|
|
|
|
|
useHistory,
|
|
|
|
|
useLocation,
|
|
|
|
|
withRouter,
|
|
|
|
|
} from "react-router-dom";
|
2019-12-16 08:49:10 +00:00
|
|
|
import {
|
|
|
|
|
AuthCardHeader,
|
|
|
|
|
AuthCardNavLink,
|
2020-08-10 12:19:46 +00:00
|
|
|
SpacedSubmitForm,
|
2019-12-16 08:49:10 +00:00
|
|
|
FormActions,
|
2021-01-27 06:12:32 +00:00
|
|
|
SignUpLinkSection,
|
2022-01-07 06:08:17 +00:00
|
|
|
} from "pages/UserAuth/StyledComponents";
|
2019-12-16 08:49:10 +00:00
|
|
|
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,
|
2021-01-27 06:12:32 +00:00
|
|
|
ALREADY_HAVE_AN_ACCOUNT,
|
2021-03-13 14:24:45 +00:00
|
|
|
createMessage,
|
2022-02-11 18:08:46 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2021-01-27 06:12:32 +00:00
|
|
|
import FormMessage from "components/ads/formFields/FormMessage";
|
|
|
|
|
import FormGroup from "components/ads/formFields/FormGroup";
|
|
|
|
|
import FormTextField from "components/ads/formFields/TextField";
|
2022-01-07 06:08:17 +00:00
|
|
|
import ThirdPartyAuth from "@appsmith/pages/UserAuth/ThirdPartyAuth";
|
|
|
|
|
import { ThirdPartyLoginRegistry } from "pages/UserAuth/ThirdPartyLoginRegistry";
|
2021-01-27 06:12:32 +00:00
|
|
|
import Button, { Size } from "components/ads/Button";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
import { isEmail, isStrongPassword, isEmptyString } from "utils/formhelpers";
|
|
|
|
|
|
2022-01-07 06:08:17 +00:00
|
|
|
import { SignupFormValues } from "pages/UserAuth/helpers";
|
2020-03-11 13:59:46 +00:00
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
2022-01-07 06:08:17 +00:00
|
|
|
import { SIGNUP_SUBMIT_PATH } from "@appsmith/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";
|
2021-01-28 07:20:09 +00:00
|
|
|
|
|
|
|
|
import { SIGNUP_FORM_EMAIL_FIELD_NAME } from "constants/forms";
|
2022-01-07 06:08:17 +00:00
|
|
|
import { getAppsmithConfigs } from "@appsmith/configs";
|
2021-06-08 05:40:11 +00:00
|
|
|
import { useScript, ScriptStatus, AddScriptTo } from "utils/hooks/useScript";
|
2021-01-28 07:20:09 +00:00
|
|
|
|
2021-01-27 06:12:32 +00:00
|
|
|
import { withTheme } from "styled-components";
|
|
|
|
|
import { Theme } from "constants/DefaultTheme";
|
2021-07-29 08:49:46 +00:00
|
|
|
import { getIsSafeRedirectURL } from "utils/helpers";
|
2020-07-07 10:22:17 +00:00
|
|
|
|
2021-06-08 05:40:11 +00:00
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
|
|
|
|
grecaptcha: any;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-07 15:18:44 +00:00
|
|
|
const { disableSignup, googleRecaptchaSiteKey } = getAppsmithConfigs();
|
2021-06-08 05:40:11 +00:00
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
const validate = (values: SignupFormValues) => {
|
|
|
|
|
const errors: SignupFormValues = {};
|
|
|
|
|
if (!values.password || isEmptyString(values.password)) {
|
2021-03-13 14:24:45 +00:00
|
|
|
errors.password = createMessage(FORM_VALIDATION_EMPTY_PASSWORD);
|
2019-12-16 08:49:10 +00:00
|
|
|
} else if (!isStrongPassword(values.password)) {
|
2021-03-13 14:24:45 +00:00
|
|
|
errors.password = createMessage(FORM_VALIDATION_INVALID_PASSWORD);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
2021-01-28 07:20:09 +00:00
|
|
|
|
|
|
|
|
const email = values.email || "";
|
|
|
|
|
if (!isEmptyString(email) && !isEmail(email)) {
|
2021-03-13 14:24:45 +00:00
|
|
|
errors.email = createMessage(FORM_VALIDATION_INVALID_EMAIL);
|
2019-12-16 08:49:10 +00:00
|
|
|
}
|
|
|
|
|
return errors;
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-28 07:20:09 +00:00
|
|
|
type SignUpFormProps = InjectedFormProps<
|
|
|
|
|
SignupFormValues,
|
|
|
|
|
{ emailValue: string }
|
|
|
|
|
> &
|
|
|
|
|
RouteComponentProps<{ email: string }> & { theme: Theme; emailValue: string };
|
2020-08-14 06:01:50 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function SignUp(props: SignUpFormProps) {
|
2022-01-05 04:56:42 +00:00
|
|
|
const history = useHistory();
|
|
|
|
|
useEffect(() => {
|
2022-02-07 15:18:44 +00:00
|
|
|
if (disableSignup) {
|
2022-01-05 04:56:42 +00:00
|
|
|
history.replace(AUTH_LOGIN_URL);
|
|
|
|
|
}
|
|
|
|
|
}, []);
|
2021-05-13 08:35:39 +00:00
|
|
|
const { emailValue: email, error, pristine, submitting, valid } = props;
|
2021-01-28 07:20:09 +00:00
|
|
|
const isFormValid = valid && email && !isEmptyString(email);
|
2022-01-07 06:08:17 +00:00
|
|
|
const socialLoginList = ThirdPartyLoginRegistry.get();
|
2020-08-10 12:19:46 +00:00
|
|
|
const location = useLocation();
|
|
|
|
|
|
2021-06-08 05:40:11 +00:00
|
|
|
const recaptchaStatus = useScript(
|
|
|
|
|
`https://www.google.com/recaptcha/api.js?render=${googleRecaptchaSiteKey.apiKey}`,
|
|
|
|
|
AddScriptTo.HEAD,
|
|
|
|
|
);
|
|
|
|
|
|
2020-08-10 12:19:46 +00:00
|
|
|
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-05-18 05:52:54 +00:00
|
|
|
} else {
|
|
|
|
|
const redirectUrl = queryParams.get("redirectUrl");
|
2021-07-29 08:49:46 +00:00
|
|
|
if (redirectUrl != null && getIsSafeRedirectURL(redirectUrl)) {
|
2021-05-18 05:52:54 +00:00
|
|
|
signupURL += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
|
|
|
|
|
}
|
2020-08-10 12:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
return (
|
2021-01-27 06:12:32 +00:00
|
|
|
<>
|
2020-08-10 12:19:46 +00:00
|
|
|
{showError && <FormMessage intent="danger" message={errorMessage} />}
|
2019-12-16 08:49:10 +00:00
|
|
|
<AuthCardHeader>
|
2021-03-13 14:24:45 +00:00
|
|
|
<h1>{createMessage(SIGNUP_PAGE_TITLE)}</h1>
|
2019-12-16 08:49:10 +00:00
|
|
|
</AuthCardHeader>
|
2021-01-27 06:12:32 +00:00
|
|
|
<SignUpLinkSection>
|
2021-03-13 14:24:45 +00:00
|
|
|
{createMessage(ALREADY_HAVE_AN_ACCOUNT)}
|
2021-01-27 06:12:32 +00:00
|
|
|
<AuthCardNavLink
|
|
|
|
|
style={{ marginLeft: props.theme.spaces[3] }}
|
2021-04-28 10:28:39 +00:00
|
|
|
to={AUTH_LOGIN_URL}
|
2021-01-27 06:12:32 +00:00
|
|
|
>
|
2021-03-13 14:24:45 +00:00
|
|
|
{createMessage(SIGNUP_PAGE_LOGIN_LINK_TEXT)}
|
2021-01-27 06:12:32 +00:00
|
|
|
</AuthCardNavLink>
|
|
|
|
|
</SignUpLinkSection>
|
2022-01-07 06:08:17 +00:00
|
|
|
{socialLoginList.length > 0 && (
|
|
|
|
|
<ThirdPartyAuth logins={socialLoginList} type={"SIGNUP"} />
|
2021-01-27 06:12:32 +00:00
|
|
|
)}
|
2021-06-08 05:40:11 +00:00
|
|
|
<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;
|
|
|
|
|
}}
|
|
|
|
|
>
|
2021-01-27 06:12:32 +00:00
|
|
|
<FormGroup
|
|
|
|
|
intent={error ? "danger" : "none"}
|
2021-03-13 14:24:45 +00:00
|
|
|
label={createMessage(SIGNUP_PAGE_EMAIL_INPUT_LABEL)}
|
2021-01-27 06:12:32 +00:00
|
|
|
>
|
|
|
|
|
<FormTextField
|
2021-04-28 10:28:39 +00:00
|
|
|
autoFocus
|
2021-01-27 06:12:32 +00:00
|
|
|
name="email"
|
2021-03-13 14:24:45 +00:00
|
|
|
placeholder={createMessage(SIGNUP_PAGE_EMAIL_INPUT_PLACEHOLDER)}
|
2021-04-28 10:28:39 +00:00
|
|
|
type="email"
|
2021-01-27 06:12:32 +00:00
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormGroup
|
|
|
|
|
intent={error ? "danger" : "none"}
|
2021-03-13 14:24:45 +00:00
|
|
|
label={createMessage(SIGNUP_PAGE_PASSWORD_INPUT_LABEL)}
|
2021-01-27 06:12:32 +00:00
|
|
|
>
|
|
|
|
|
<FormTextField
|
|
|
|
|
name="password"
|
2021-03-13 14:24:45 +00:00
|
|
|
placeholder={createMessage(SIGNUP_PAGE_PASSWORD_INPUT_PLACEHOLDER)}
|
2021-04-28 10:28:39 +00:00
|
|
|
type="password"
|
2021-01-27 06:12:32 +00:00
|
|
|
/>
|
|
|
|
|
</FormGroup>
|
|
|
|
|
<FormActions>
|
|
|
|
|
<Button
|
2021-01-28 07:20:09 +00:00
|
|
|
disabled={pristine || !isFormValid}
|
2021-01-27 06:12:32 +00:00
|
|
|
fill
|
2021-04-28 10:28:39 +00:00
|
|
|
isLoading={submitting}
|
2021-01-27 06:12:32 +00:00
|
|
|
onClick={() => {
|
|
|
|
|
AnalyticsUtil.logEvent("SIGNUP_CLICK", {
|
|
|
|
|
signupMethod: "EMAIL",
|
|
|
|
|
});
|
|
|
|
|
PerformanceTracker.startTracking(
|
|
|
|
|
PerformanceTransactionName.SIGN_UP,
|
|
|
|
|
);
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
size={Size.large}
|
|
|
|
|
tag="button"
|
|
|
|
|
text={createMessage(SIGNUP_PAGE_SUBMIT_BUTTON_TEXT)}
|
|
|
|
|
type="submit"
|
2021-01-27 06:12:32 +00:00
|
|
|
/>
|
|
|
|
|
</FormActions>
|
|
|
|
|
</SpacedSubmitForm>
|
|
|
|
|
</>
|
2019-12-16 08:49:10 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-12-16 08:49:10 +00:00
|
|
|
|
2021-01-28 07:20:09 +00:00
|
|
|
const selector = formValueSelector(SIGNUP_FORM_NAME);
|
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"),
|
|
|
|
|
},
|
2021-01-28 07:20:09 +00:00
|
|
|
emailValue: selector(state, SIGNUP_FORM_EMAIL_FIELD_NAME),
|
2020-08-28 10:51:41 +00:00
|
|
|
};
|
|
|
|
|
}, null)(
|
2021-01-28 07:20:09 +00:00
|
|
|
reduxForm<SignupFormValues, { emailValue: string }>({
|
2020-08-14 06:01:50 +00:00
|
|
|
validate,
|
|
|
|
|
form: SIGNUP_FORM_NAME,
|
|
|
|
|
touchOnBlur: true,
|
2021-01-27 06:12:32 +00:00
|
|
|
})(withRouter(withTheme(SignUp))),
|
2020-08-14 06:01:50 +00:00
|
|
|
);
|