2022-01-05 04:56:42 +00:00
|
|
|
import React, { useEffect } from "react";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { InjectedFormProps } from "redux-form";
|
|
|
|
|
import { reduxForm, formValueSelector } from "redux-form";
|
2019-12-16 08:49:10 +00:00
|
|
|
import { AUTH_LOGIN_URL } from "constants/routes";
|
2022-09-02 17:15:08 +00:00
|
|
|
import { SIGNUP_FORM_NAME } from "@appsmith/constants/forms";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { RouteComponentProps } from "react-router-dom";
|
|
|
|
|
import { useHistory, useLocation, withRouter, Link } from "react-router-dom";
|
2022-12-09 14:43:47 +00:00
|
|
|
import { SpacedSubmitForm, FormActions } 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-12-09 14:43:47 +00:00
|
|
|
SIGNUP_PAGE_SUBTITLE,
|
2022-02-11 18:08:46 +00:00
|
|
|
} from "@appsmith/constants/messages";
|
2022-10-05 11:06:49 +00:00
|
|
|
import FormTextField from "components/utils/ReduxFormTextField";
|
2022-01-07 06:08:17 +00:00
|
|
|
import ThirdPartyAuth from "@appsmith/pages/UserAuth/ThirdPartyAuth";
|
|
|
|
|
import { ThirdPartyLoginRegistry } from "pages/UserAuth/ThirdPartyLoginRegistry";
|
2023-01-23 03:50:47 +00:00
|
|
|
import { Button, FormGroup, FormMessage, Size } from "design-system-old";
|
2019-12-16 08:49:10 +00:00
|
|
|
|
|
|
|
|
import { isEmail, isStrongPassword, isEmptyString } from "utils/formhelpers";
|
|
|
|
|
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { 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";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { AppState } from "@appsmith/reducers";
|
2020-09-28 06:29:41 +00:00
|
|
|
import PerformanceTracker, {
|
|
|
|
|
PerformanceTransactionName,
|
|
|
|
|
} from "utils/PerformanceTracker";
|
2021-01-28 07:20:09 +00:00
|
|
|
|
2022-09-02 17:15:08 +00:00
|
|
|
import { SIGNUP_FORM_EMAIL_FIELD_NAME } from "@appsmith/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-07-29 08:49:46 +00:00
|
|
|
import { getIsSafeRedirectURL } from "utils/helpers";
|
2022-12-09 14:43:47 +00:00
|
|
|
import Container from "pages/UserAuth/Container";
|
2020-07-07 10:22:17 +00:00
|
|
|
|
2021-06-08 05:40:11 +00:00
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
|
|
|
|
grecaptcha: any;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-16 16:26:37 +00:00
|
|
|
const { disableLoginForm, 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 }
|
|
|
|
|
> &
|
2023-01-13 11:05:59 +00:00
|
|
|
RouteComponentProps<{ email: string }> & { 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-03-16 16:26:37 +00:00
|
|
|
if (disableLoginForm) {
|
2022-04-01 11:27:49 +00:00
|
|
|
const search = new URL(window.location.href)?.searchParams?.toString();
|
|
|
|
|
history.replace({
|
|
|
|
|
pathname: AUTH_LOGIN_URL,
|
|
|
|
|
search,
|
|
|
|
|
});
|
2022-01-05 04:56:42 +00:00
|
|
|
}
|
|
|
|
|
}, []);
|
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();
|
2022-03-24 07:05:00 +00:00
|
|
|
const shouldDisableSignupButton = pristine || !isFormValid;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-11 09:03:37 +00:00
|
|
|
const signupURL = new URL(
|
|
|
|
|
`/api/v1/` + SIGNUP_SUBMIT_PATH,
|
|
|
|
|
window.location.origin,
|
|
|
|
|
);
|
|
|
|
|
const appId = queryParams.get("appId");
|
|
|
|
|
if (appId) {
|
|
|
|
|
signupURL.searchParams.append("appId", 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)) {
|
2022-07-11 09:03:37 +00:00
|
|
|
signupURL.searchParams.append("redirectUrl", redirectUrl);
|
2021-05-18 05:52:54 +00:00
|
|
|
}
|
2020-08-10 12:19:46 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-24 07:05:00 +00:00
|
|
|
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const formElement: HTMLFormElement = document.getElementById(
|
|
|
|
|
"signup-form",
|
|
|
|
|
) as HTMLFormElement;
|
|
|
|
|
if (
|
|
|
|
|
googleRecaptchaSiteKey.enabled &&
|
|
|
|
|
recaptchaStatus === ScriptStatus.READY
|
|
|
|
|
) {
|
|
|
|
|
window.grecaptcha
|
|
|
|
|
.execute(googleRecaptchaSiteKey.apiKey, {
|
|
|
|
|
action: "submit",
|
|
|
|
|
})
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### Test Plan
> Add Testsmith test cases links that relate to this PR
### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
## Checklist:
### Dev activity
- [x] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag
### QA activity:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
.then(function (token: any) {
|
2022-07-11 09:03:37 +00:00
|
|
|
if (formElement) {
|
|
|
|
|
signupURL.searchParams.append("recaptchaToken", token);
|
|
|
|
|
formElement.setAttribute("action", signupURL.toString());
|
|
|
|
|
formElement.submit();
|
|
|
|
|
}
|
2022-03-24 07:05:00 +00:00
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
formElement && formElement.submit();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-12-09 14:43:47 +00:00
|
|
|
const footerSection = (
|
|
|
|
|
<div className="px-2 py-4 text-base text-center border-b">
|
|
|
|
|
{createMessage(ALREADY_HAVE_AN_ACCOUNT)}
|
|
|
|
|
<Link
|
|
|
|
|
className="t--sign-up ml-2 text-[color:var(--ads-color-brand)] hover:text-[color:var(--ads-color-brand)]"
|
|
|
|
|
to={AUTH_LOGIN_URL}
|
|
|
|
|
>
|
|
|
|
|
{createMessage(SIGNUP_PAGE_LOGIN_LINK_TEXT)}
|
|
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2019-12-16 08:49:10 +00:00
|
|
|
return (
|
2022-12-09 14:43:47 +00:00
|
|
|
<Container
|
|
|
|
|
footer={footerSection}
|
|
|
|
|
subtitle={createMessage(SIGNUP_PAGE_SUBTITLE)}
|
|
|
|
|
title={createMessage(SIGNUP_PAGE_TITLE)}
|
|
|
|
|
>
|
2020-08-10 12:19:46 +00:00
|
|
|
{showError && <FormMessage intent="danger" message={errorMessage} />}
|
2022-01-07 06:08:17 +00:00
|
|
|
{socialLoginList.length > 0 && (
|
|
|
|
|
<ThirdPartyAuth logins={socialLoginList} type={"SIGNUP"} />
|
2021-01-27 06:12:32 +00:00
|
|
|
)}
|
2022-03-24 07:05:00 +00:00
|
|
|
{!disableLoginForm && (
|
|
|
|
|
<SpacedSubmitForm
|
2022-07-11 09:03:37 +00:00
|
|
|
action={signupURL.toString()}
|
2022-03-24 07:05:00 +00:00
|
|
|
id="signup-form"
|
|
|
|
|
method="POST"
|
|
|
|
|
onSubmit={(e) => handleSubmit(e)}
|
2021-01-27 06:12:32 +00:00
|
|
|
>
|
2022-03-24 07:05:00 +00:00
|
|
|
<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={shouldDisableSignupButton}
|
|
|
|
|
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>
|
|
|
|
|
)}
|
2022-12-09 14:43:47 +00:00
|
|
|
</Container>
|
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,
|
2023-01-13 11:05:59 +00:00
|
|
|
})(withRouter(SignUp)),
|
2020-08-14 06:01:50 +00:00
|
|
|
);
|