review(front): refacto url-manager (#8861)
Replace https://github.com/twentyhq/twenty/pull/8855
This commit is contained in:
@ -0,0 +1,34 @@
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
import { domainConfigurationState } from '@/domain-manager/states/domainConfigurationState';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
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,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user