- Replace `window.location.replace` by `useRedirect` hook. - Remove unused code: `switchWorkspace, addUserByInviteHash...` - Refacto `Invite` component. - Fix signin on invite modal.
35 lines
885 B
TypeScript
35 lines
885 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 (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,
|
|
};
|
|
};
|