PromucFlow_constructor/app/client/src/ce/utils/signupHelpers.ts
Valera Melnikov c42e0317de
fix: change appsmith alias (#35349)
In order to unify package names, we decided to use `@appsmith` prefix as
a marker to indicate that packages belong to our codebase and that these
packages are developed internally. So that we can use this prefix, we
need to rename the alias of the same name. But since `@appsmith` is
currently being used as an alias for `ee` folder, we have to rename the
alias as the first step.

Related discussion
https://theappsmith.slack.com/archives/CPG2ZTXEY/p1722516279126329

EE PR — https://github.com/appsmithorg/appsmith-ee/pull/4801

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10267368821>
> Commit: 2b00af2d257e4d4304db0a80072afef7513de6be
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10267368821&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Tue, 06 Aug 2024 14:24:22 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-08-06 17:52:22 +03:00

114 lines
3.6 KiB
TypeScript

import {
firstTimeUserOnboardingInit,
setCurrentApplicationIdForCreateNewApp,
} from "actions/onboardingActions";
import {
SIGNUP_SUCCESS_URL,
BUILDER_PATH,
BUILDER_PATH_DEPRECATED,
VIEWER_PATH,
VIEWER_PATH_DEPRECATED,
APPLICATIONS_URL,
} from "constants/routes";
import { error } from "loglevel";
import { matchPath } from "react-router";
import { getIsSafeRedirectURL } from "utils/helpers";
import history from "utils/history";
import type {
SocialLoginButtonProps,
SocialLoginType,
} from "ee/constants/SocialLogin";
import { SocialLoginButtonPropsList } from "ee/constants/SocialLogin";
export const redirectUserAfterSignup = (
redirectUrl: string,
shouldEnableFirstTimeUserOnboarding: string | null,
_validLicense?: boolean,
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
dispatch?: any,
isEnabledForCreateNew?: boolean, // is Enabled for only non-invited users
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): any => {
if (redirectUrl) {
try {
if (
window.location.pathname == SIGNUP_SUCCESS_URL &&
shouldEnableFirstTimeUserOnboarding === "true"
) {
let urlObject;
try {
urlObject = new URL(redirectUrl);
} catch (e) {}
const match = matchPath<{
basePageId: string;
baseApplicationId: string;
}>(urlObject?.pathname ?? redirectUrl, {
path: [
BUILDER_PATH,
BUILDER_PATH_DEPRECATED,
VIEWER_PATH,
VIEWER_PATH_DEPRECATED,
],
strict: false,
exact: false,
});
const { baseApplicationId, basePageId } = match?.params || {};
/** ! Dev Note:
* setCurrentApplicationIdForCreateNewApp & firstTimeUserOnboardingInit
* in the following block support only applicationId
* but since baseId and id are same for applications created outside git context
* and since these redux actions are only called during onboarding,
* passing baseApplicationId as applicationId should be fine
* **/
if (baseApplicationId || basePageId) {
if (isEnabledForCreateNew) {
dispatch(
setCurrentApplicationIdForCreateNewApp(
baseApplicationId as string,
),
);
history.replace(APPLICATIONS_URL);
} else {
dispatch(
firstTimeUserOnboardingInit(
baseApplicationId,
basePageId as string,
),
);
}
} else {
if (!urlObject) {
try {
urlObject = new URL(redirectUrl, window.location.origin);
} catch (e) {}
}
const newRedirectUrl = urlObject?.toString() || "";
if (getIsSafeRedirectURL(newRedirectUrl)) {
window.location.replace(newRedirectUrl);
}
}
} else if (getIsSafeRedirectURL(redirectUrl)) {
window.location.replace(redirectUrl);
}
} catch (e) {
error("Error handling the redirect url");
}
} else {
history.replace(APPLICATIONS_URL);
}
};
export const getSocialLoginButtonProps = (
logins: SocialLoginType[],
): SocialLoginButtonProps[] => {
return logins.map((login) => {
const socialLoginButtonProps = SocialLoginButtonPropsList[login];
if (!socialLoginButtonProps) {
throw Error("Social login not registered: " + login);
}
return socialLoginButtonProps;
});
};