Files
twenty_crm/packages/twenty-front/src/modules/domain-manager/hooks/useBuildWorkspaceUrl.ts
P A C - 先生 4503ee3fbd bugfix: fix navigation between onboarding screens (#9637)
# This PR

- Fixes #9565

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
2025-01-16 11:24:03 +01:00

35 lines
910 B
TypeScript

import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
import { useRecoilValue } from 'recoil';
import { isDefined } from '~/utils/isDefined';
export const useBuildWorkspaceUrl = () => {
const domainConfiguration = useRecoilValue(domainConfigurationState);
const buildWorkspaceUrl = (
subdomain?: string,
pathname?: string,
searchParams?: Record<string, string>,
) => {
const url = new URL(window.location.href);
if (isDefined(subdomain) && subdomain.length !== 0) {
url.hostname = `${subdomain}.${domainConfiguration.frontDomain}`;
}
if (isDefined(pathname)) {
url.pathname = pathname;
}
if (isDefined(searchParams)) {
Object.entries(searchParams).forEach(([key, value]) =>
url.searchParams.set(key, value),
);
}
return url.toString();
};
return {
buildWorkspaceUrl,
};
};