2023-11-09 04:19:02 +00:00
|
|
|
import {
|
|
|
|
|
firstTimeUserOnboardingInit,
|
|
|
|
|
setCurrentApplicationIdForCreateNewApp,
|
|
|
|
|
} from "actions/onboardingActions";
|
2023-01-10 05:39:15 +00:00
|
|
|
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";
|
2024-05-06 12:06:12 +00:00
|
|
|
import type {
|
|
|
|
|
SocialLoginButtonProps,
|
|
|
|
|
SocialLoginType,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/SocialLogin";
|
|
|
|
|
import { SocialLoginButtonPropsList } from "ee/constants/SocialLogin";
|
2023-01-10 05:39:15 +00:00
|
|
|
|
|
|
|
|
export const redirectUserAfterSignup = (
|
|
|
|
|
redirectUrl: string,
|
|
|
|
|
shouldEnableFirstTimeUserOnboarding: string | null,
|
|
|
|
|
_validLicense?: boolean,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-01-10 05:39:15 +00:00
|
|
|
dispatch?: any,
|
2024-03-15 05:43:14 +00:00
|
|
|
isEnabledForCreateNew?: boolean, // is Enabled for only non-invited users
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-01-10 05:39:15 +00:00
|
|
|
): 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<{
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: string;
|
|
|
|
|
baseApplicationId: string;
|
2023-01-10 05:39:15 +00:00
|
|
|
}>(urlObject?.pathname ?? redirectUrl, {
|
|
|
|
|
path: [
|
|
|
|
|
BUILDER_PATH,
|
|
|
|
|
BUILDER_PATH_DEPRECATED,
|
|
|
|
|
VIEWER_PATH,
|
|
|
|
|
VIEWER_PATH_DEPRECATED,
|
|
|
|
|
],
|
|
|
|
|
strict: false,
|
|
|
|
|
exact: false,
|
|
|
|
|
});
|
2024-07-31 02:54:51 +00:00
|
|
|
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) {
|
2023-11-09 04:19:02 +00:00
|
|
|
if (isEnabledForCreateNew) {
|
|
|
|
|
dispatch(
|
2024-07-31 02:54:51 +00:00
|
|
|
setCurrentApplicationIdForCreateNewApp(
|
|
|
|
|
baseApplicationId as string,
|
|
|
|
|
),
|
2023-11-09 04:19:02 +00:00
|
|
|
);
|
|
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
} else {
|
|
|
|
|
dispatch(
|
2024-07-31 02:54:51 +00:00
|
|
|
firstTimeUserOnboardingInit(
|
|
|
|
|
baseApplicationId,
|
|
|
|
|
basePageId as string,
|
|
|
|
|
),
|
2023-11-09 04:19:02 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!urlObject) {
|
|
|
|
|
try {
|
|
|
|
|
urlObject = new URL(redirectUrl, window.location.origin);
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
}
|
|
|
|
|
const newRedirectUrl = urlObject?.toString() || "";
|
|
|
|
|
if (getIsSafeRedirectURL(newRedirectUrl)) {
|
|
|
|
|
window.location.replace(newRedirectUrl);
|
|
|
|
|
}
|
2023-01-10 05:39:15 +00:00
|
|
|
}
|
|
|
|
|
} else if (getIsSafeRedirectURL(redirectUrl)) {
|
|
|
|
|
window.location.replace(redirectUrl);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error("Error handling the redirect url");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-05-06 12:06:12 +00:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
});
|
|
|
|
|
};
|