diff --git a/static/app/views/preprod/redirects/legacyUrlRedirect.tsx b/static/app/views/preprod/redirects/legacyUrlRedirect.tsx index a6dc3cfd291513..1a9811b75222ad 100644 --- a/static/app/views/preprod/redirects/legacyUrlRedirect.tsx +++ b/static/app/views/preprod/redirects/legacyUrlRedirect.tsx @@ -1,9 +1,11 @@ import {useEffect} from 'react'; +import ConfigStore from 'sentry/stores/configStore'; import {useLocation} from 'sentry/utils/useLocation'; import {useNavigate} from 'sentry/utils/useNavigate'; import useOrganization from 'sentry/utils/useOrganization'; import {useParams} from 'sentry/utils/useParams'; +import useProjectFromSlug from 'sentry/utils/useProjectFromSlug'; export default function LegacyPreprodRedirect() { const params = useParams<{ @@ -15,31 +17,40 @@ export default function LegacyPreprodRedirect() { const navigate = useNavigate(); const organization = useOrganization(); const location = useLocation(); + const project = useProjectFromSlug({organization, projectSlug: params.projectId}); useEffect(() => { - const {projectId, artifactId, headArtifactId, baseArtifactId} = params; + if (!project) { + return; + } + + const {artifactId, headArtifactId, baseArtifactId} = params; + const numericProjectId = project.id; const isInstall = location.pathname.includes('/install/'); const isCompare = location.pathname.includes('/compare/'); + const {customerDomain} = ConfigStore.getState(); + const orgPrefix = customerDomain ? '' : `/organizations/${organization.slug}`; + let newPath = ''; if (isCompare && headArtifactId) { const compareType = 'size'; if (baseArtifactId) { - newPath = `/organizations/${organization.slug}/preprod/${compareType}/compare/${headArtifactId}/${baseArtifactId}/?project=${projectId}`; + newPath = `${orgPrefix}/preprod/${compareType}/compare/${headArtifactId}/${baseArtifactId}/?project=${numericProjectId}`; } else { - newPath = `/organizations/${organization.slug}/preprod/${compareType}/compare/${headArtifactId}/?project=${projectId}`; + newPath = `${orgPrefix}/preprod/${compareType}/compare/${headArtifactId}/?project=${numericProjectId}`; } } else if (isInstall && artifactId) { - newPath = `/organizations/${organization.slug}/preprod/install/${artifactId}/?project=${projectId}`; + newPath = `${orgPrefix}/preprod/install/${artifactId}/?project=${numericProjectId}`; } else if (artifactId) { - newPath = `/organizations/${organization.slug}/preprod/size/${artifactId}/?project=${projectId}`; + newPath = `${orgPrefix}/preprod/size/${artifactId}/?project=${numericProjectId}`; } if (newPath) { navigate(newPath, {replace: true}); } - }, [params, navigate, organization, location]); + }, [params, navigate, organization, location, project]); return null; }