PromucFlow_constructor/app/client/src/pages/UserAuth/SignUp.tsx

228 lines
7.3 KiB
TypeScript
Raw Normal View History

2019-12-16 08:49:10 +00:00
import React from "react";
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";
import { RouteComponentProps, useLocation, withRouter } from "react-router-dom";
2019-12-16 08:49:10 +00:00
import {
AuthCardHeader,
AuthCardNavLink,
SpacedSubmitForm,
2019-12-16 08:49:10 +00:00
FormActions,
SignUpLinkSection,
2019-12-16 08:49:10 +00:00
} from "./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,
2019-12-16 08:49:10 +00:00
} from "constants/messages";
import FormMessage from "components/ads/formFields/FormMessage";
import FormGroup from "components/ads/formFields/FormGroup";
import FormTextField from "components/ads/formFields/TextField";
2019-12-16 08:49:10 +00:00
import ThirdPartyAuth, { SocialLoginTypes } from "./ThirdPartyAuth";
import Button, { Size } from "components/ads/Button";
2019-12-16 08:49:10 +00:00
import { isEmail, isStrongPassword, isEmptyString } from "utils/formhelpers";
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
import { SIGNUP_SUBMIT_PATH } from "constants/ApiConstants";
import { connect } from "react-redux";
import { AppState } from "reducers";
import PerformanceTracker, {
PerformanceTransactionName,
} from "utils/PerformanceTracker";
import { useIntiateOnboarding } from "components/editorComponents/Onboarding/utils";
import { SIGNUP_FORM_EMAIL_FIELD_NAME } from "constants/forms";
import { getAppsmithConfigs } from "configs";
import { useScript, ScriptStatus, AddScriptTo } from "utils/hooks/useScript";
const { enableGithubOAuth, enableGoogleOAuth } = getAppsmithConfigs();
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +00:00
const SocialLoginList: string[] = [];
if (enableGoogleOAuth) SocialLoginList.push(SocialLoginTypes.GOOGLE);
if (enableGithubOAuth) SocialLoginList.push(SocialLoginTypes.GITHUB);
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +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";
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +00:00
declare global {
interface Window {
grecaptcha: any;
}
}
const { googleRecaptchaSiteKey } = getAppsmithConfigs();
2019-12-16 08:49:10 +00:00
const validate = (values: SignupFormValues) => {
const errors: SignupFormValues = {};
if (!values.password || isEmptyString(values.password)) {
errors.password = createMessage(FORM_VALIDATION_EMPTY_PASSWORD);
2019-12-16 08:49:10 +00:00
} else if (!isStrongPassword(values.password)) {
errors.password = createMessage(FORM_VALIDATION_INVALID_PASSWORD);
2019-12-16 08:49:10 +00:00
}
const email = values.email || "";
if (!isEmptyString(email) && !isEmail(email)) {
errors.email = createMessage(FORM_VALIDATION_INVALID_EMAIL);
2019-12-16 08:49:10 +00:00
}
return errors;
};
type SignUpFormProps = InjectedFormProps<
SignupFormValues,
{ emailValue: string }
> &
RouteComponentProps<{ email: string }> & { theme: Theme; emailValue: string };
export function SignUp(props: SignUpFormProps) {
const { emailValue: email, error, pristine, submitting, valid } = props;
const isFormValid = valid && email && !isEmptyString(email);
const location = useLocation();
const initiateOnboarding = useIntiateOnboarding();
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;
2020-08-13 09:33:44 +00:00
if (queryParams.has("appId")) {
signupURL += `?appId=${queryParams.get("appId")}`;
} else {
const redirectUrl = queryParams.get("redirectUrl");
2021-07-29 08:49:46 +00:00
if (redirectUrl != null && getIsSafeRedirectURL(redirectUrl)) {
signupURL += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
}
}
2019-12-16 08:49:10 +00:00
return (
<>
{showError && <FormMessage intent="danger" message={errorMessage} />}
2019-12-16 08:49:10 +00:00
<AuthCardHeader>
<h1>{createMessage(SIGNUP_PAGE_TITLE)}</h1>
2019-12-16 08:49:10 +00:00
</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,
);
initiateOnboarding();
}}
size={Size.large}
tag="button"
text={createMessage(SIGNUP_PAGE_SUBMIT_BUTTON_TEXT)}
type="submit"
/>
</FormActions>
</SpacedSubmitForm>
</>
2019-12-16 08:49:10 +00:00
);
}
2019-12-16 08:49:10 +00:00
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))),
);