@@ -3,6 +3,8 @@ import { useTeams } from "api/teams";
33import { useEffect } from "react" ;
44import { Loading } from "@ui/Loading" ;
55import { withAuthenticatedPage } from "lib/withAuthenticatedPage" ;
6+ import { useProjectById } from "api/projects" ;
7+ import { useSupportFormOpen } from "elements/SupportWidget" ;
68
79export { getServerSideProps } from "lib/ssr" ;
810
@@ -26,7 +28,57 @@ function RedirectToTeam() {
2628}
2729
2830function Main ( ) {
31+ const { query, push } = useRouter ( ) ;
32+ const { teams } = useTeams ( ) ;
33+ const [ , setOpenState ] = useSupportFormOpen ( ) ;
34+
35+ // If vercelPath is set, we need to redirect somewhere, but we don't know
36+ // which team to redirect to. We'll redirect to the first team that is managed
37+ // by Vercel. In most cases, this will be correct.
38+ const firstVercelTeam = teams ?. find ( ( t ) => t . managedBy === "vercel" ) ;
39+ if ( query . vercelPath === "support" ) {
40+ setOpenState ( true ) ;
41+ void push ( firstVercelTeam ? `/t/${ firstVercelTeam . slug } ` : "/" ) ;
42+ return < Loading /> ;
43+ }
44+
45+ if ( query . vercelPath === "billing" ) {
46+ void push (
47+ firstVercelTeam
48+ ? `/t/${ firstVercelTeam . slug } /settings/billing`
49+ : "/team/settings/billing" ,
50+ ) ;
51+ return < Loading /> ;
52+ }
53+ if ( query . vercelPath === "usage" ) {
54+ void push (
55+ firstVercelTeam
56+ ? `/t/${ firstVercelTeam . slug } /settings/usage`
57+ : "/team/settings/usage" ,
58+ ) ;
59+ return < Loading /> ;
60+ }
61+ if ( query . invoiceId ) {
62+ // TODO(ENG-9453): Support this.
63+ }
64+
65+ if ( query . projectId ) {
66+ return < RedirectToProjectById id = { query . vercel_resource_id as string } /> ;
67+ }
2968 return < RedirectToTeam /> ;
3069}
3170
71+ function RedirectToProjectById ( { id } : { id : string } ) {
72+ const project = useProjectById ( parseInt ( id ) ) ;
73+ const { teams } = useTeams ( ) ;
74+ const projectTeam = teams ?. find ( ( team ) => team . id === project ?. teamId ) ;
75+ const router = useRouter ( ) ;
76+ useEffect ( ( ) => {
77+ if ( project && projectTeam ) {
78+ void router . replace ( `/t/${ projectTeam . slug } /${ project . slug } ` ) ;
79+ }
80+ } , [ project , projectTeam , router ] ) ;
81+ return < Loading /> ;
82+ }
83+
3284export default withAuthenticatedPage ( Main ) ;
0 commit comments