From a614e0030830a0b4ac69fa2727ced7d5322d3c91 Mon Sep 17 00:00:00 2001 From: Antoine Moreaux Date: Thu, 12 Jun 2025 13:51:05 +0200 Subject: [PATCH] =?UTF-8?q?fix(workspace):=20simplify=20hostname=20matchin?= =?UTF-8?q?g=20logic=20in=20WorkspaceProvider=E2=80=A6=20(#12365)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …Effect Replaced `getHostnamesFromWorkspaceUrls` with `isWorkspaceHostnameMatchCurrentLocationHostname` for streamlined hostname comparison, reducing redundancy and improving logic clarity. Fix #12295 --- .../components/WorkspaceProviderEffect.tsx | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx index 3896cbe5f..246f9b50d 100644 --- a/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx +++ b/packages/twenty-front/src/modules/workspace/components/WorkspaceProviderEffect.tsx @@ -4,7 +4,7 @@ import { isMultiWorkspaceEnabledState } from '@/client-config/states/isMultiWork import { useReadWorkspaceUrlFromCurrentLocation } from '@/domain-manager/hooks/useReadWorkspaceUrlFromCurrentLocation'; import { useRedirectToWorkspaceDomain } from '@/domain-manager/hooks/useRedirectToWorkspaceDomain'; import { lastAuthenticatedWorkspaceDomainState } from '@/domain-manager/states/lastAuthenticatedWorkspaceDomainState'; -import { useEffect } from 'react'; +import { useEffect, useCallback } from 'react'; import { useInitializeQueryParamState } from '@/app/hooks/useInitializeQueryParamState'; import { useGetPublicWorkspaceDataByDomain } from '@/domain-manager/hooks/useGetPublicWorkspaceDataByDomain'; @@ -27,26 +27,23 @@ export const WorkspaceProviderEffect = () => { const isMultiWorkspaceEnabled = useRecoilValue(isMultiWorkspaceEnabledState); - const getHostnamesFromWorkspaceUrls = (workspaceUrls: WorkspaceUrls) => { - return { - customUrlHostname: workspaceUrls.customUrl - ? new URL(workspaceUrls.customUrl).hostname - : undefined, - subdomainUrlHostname: new URL(workspaceUrls.subdomainUrl).hostname, - }; - }; - const { initializeQueryParamState } = useInitializeQueryParamState(); + const isWorkspaceHostnameMatchCurrentLocationHostname = useCallback( + (workspaceUrls: WorkspaceUrls) => { + const { hostname } = new URL(getWorkspaceUrl(workspaceUrls)); + return hostname === currentLocationHostname; + }, + [currentLocationHostname], + ); + useEffect(() => { - const hostnames = getPublicWorkspaceData - ? getHostnamesFromWorkspaceUrls(getPublicWorkspaceData?.workspaceUrls) - : null; if ( isMultiWorkspaceEnabled && isDefined(getPublicWorkspaceData) && - currentLocationHostname !== hostnames?.customUrlHostname && - currentLocationHostname !== hostnames?.subdomainUrlHostname + !isWorkspaceHostnameMatchCurrentLocationHostname( + getPublicWorkspaceData.workspaceUrls, + ) ) { redirectToWorkspaceDomain( getWorkspaceUrl(getPublicWorkspaceData.workspaceUrls), @@ -57,6 +54,7 @@ export const WorkspaceProviderEffect = () => { redirectToWorkspaceDomain, getPublicWorkspaceData, currentLocationHostname, + isWorkspaceHostnameMatchCurrentLocationHostname, ]); useEffect(() => {