19 lines
938 B
TypeScript
19 lines
938 B
TypeScript
import type { Params } from "react-router";
|
|
import { adminPath } from "~/utils/app/CanonicalUrlUtils";
|
|
import UrlUtils from "~/utils/app/UrlUtils";
|
|
|
|
const replaceTokens = (href: string, tokens: string[], value: string) => tokens.reduce((next, token) => next.split(token).join(value), href);
|
|
|
|
const getAppOrAdminBasePath = (params: Params) => {
|
|
const basePath = params.tenant ? UrlUtils.currentTenantUrl(params) : adminPath(undefined, { mode: "host-aware" });
|
|
return UrlUtils.stripTrailingSlash(basePath);
|
|
};
|
|
|
|
export function resolveOnboardingHref(href: string, params: Params, userId?: string) {
|
|
let resolved = href;
|
|
resolved = replaceTokens(resolved, [":tenant", "{tenant}", "$tenant"], params.tenant ?? "");
|
|
resolved = replaceTokens(resolved, [":user", "{user}", "$user"], userId ?? "");
|
|
resolved = replaceTokens(resolved, [":appOrAdmin", "{appOrAdmin}", "$appOrAdmin"], getAppOrAdminBasePath(params));
|
|
return resolved;
|
|
}
|