2023-01-10 05:39:15 +00:00
|
|
|
import { firstTimeUserOnboardingInit } 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";
|
2023-10-30 05:45:05 +00:00
|
|
|
import { setUsersFirstApplicationId } from "utils/storage";
|
2023-01-10 05:39:15 +00:00
|
|
|
|
|
|
|
|
export const redirectUserAfterSignup = (
|
|
|
|
|
redirectUrl: string,
|
|
|
|
|
shouldEnableFirstTimeUserOnboarding: string | null,
|
|
|
|
|
_validLicense?: boolean,
|
|
|
|
|
dispatch?: any,
|
2023-10-30 05:45:05 +00:00
|
|
|
showStarterTemplatesInsteadofBlankCanvas: boolean = false,
|
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<{
|
|
|
|
|
pageId: string;
|
|
|
|
|
applicationId: string;
|
|
|
|
|
}>(urlObject?.pathname ?? redirectUrl, {
|
|
|
|
|
path: [
|
|
|
|
|
BUILDER_PATH,
|
|
|
|
|
BUILDER_PATH_DEPRECATED,
|
|
|
|
|
VIEWER_PATH,
|
|
|
|
|
VIEWER_PATH_DEPRECATED,
|
|
|
|
|
],
|
|
|
|
|
strict: false,
|
|
|
|
|
exact: false,
|
|
|
|
|
});
|
|
|
|
|
const { applicationId, pageId } = match?.params || {};
|
|
|
|
|
if (applicationId || pageId) {
|
2023-10-30 05:45:05 +00:00
|
|
|
showStarterTemplatesInsteadofBlankCanvas &&
|
|
|
|
|
applicationId &&
|
|
|
|
|
setUsersFirstApplicationId(applicationId);
|
2023-01-10 05:39:15 +00:00
|
|
|
dispatch(
|
|
|
|
|
firstTimeUserOnboardingInit(applicationId, pageId as string),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else if (getIsSafeRedirectURL(redirectUrl)) {
|
|
|
|
|
window.location.replace(redirectUrl);
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
error("Error handling the redirect url");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
history.replace(APPLICATIONS_URL);
|
|
|
|
|
}
|
|
|
|
|
};
|