@@ -16,8 +16,9 @@ import {
1616 CardTitle ,
1717 Skeleton ,
1818} from "@rivet-gg/components" ;
19+ import * as Sentry from "@sentry/react" ;
1920import { useSuspenseQuery } from "@tanstack/react-query" ;
20- import { useNavigate } from "@tanstack/react-router" ;
21+ import { Navigate , useNavigate } from "@tanstack/react-router" ;
2122import { motion } from "framer-motion" ;
2223import { Suspense , useState } from "react" ;
2324
@@ -27,7 +28,12 @@ enum Step {
2728 ChoosePlan = 2 ,
2829}
2930
30- export function Intro ( { initialStep } : { initialStep ?: Step } ) {
31+ interface IntroProps {
32+ initialStep ?: Step ;
33+ initialProjectName ?: string ;
34+ }
35+
36+ export function Intro ( { initialStep, initialProjectName } : IntroProps ) {
3137 const { mutateAsync, data : createdGroupResponse } = useGroupCreateMutation ( ) ;
3238 const { mutateAsync : createProject , data : projectCreationData } =
3339 useProjectCreateMutation ( ) ;
@@ -38,14 +44,13 @@ export function Intro({ initialStep }: { initialStep?: Step }) {
3844 data
3945 . flatMap ( ( team ) => team . projects )
4046 . find ( ( project ) => project . gameId === projectCreationData ?. gameId ) ||
41- // biome-ignore lint/style/noNonNullAssertion: at this point user should have at least one project
42- data . find ( ( team ) => team . projects . length > 0 ) ! . projects [ 0 ] ! ;
47+ data . find ( ( team ) => team . projects . length > 0 ) ?. projects [ 0 ] ;
4348
4449 const [ step , setStep ] = useState < Step > (
4550 ( ) => initialStep ?? ( ! project ? Step . CreateGroup : Step . CreateProject ) ,
4651 ) ;
4752
48- const groupId = createdGroupResponse ?. groupId || project . developer . groupId ;
53+ const groupId = createdGroupResponse ?. groupId || project ? .developer . groupId ;
4954
5055 const navigate = useNavigate ( ) ;
5156
@@ -60,7 +65,10 @@ export function Intro({ initialStep }: { initialStep?: Step }) {
6065 exit = { { opacity : 0 } }
6166 >
6267 < GroupCreateProjectForm . Form
63- defaultValues = { { slug : "" , name : "" } }
68+ defaultValues = { {
69+ slug : "" ,
70+ name : initialProjectName ?? "" ,
71+ } }
6472 onSubmit = { async ( values ) => {
6573 await createProject ( {
6674 displayName : values . name ,
@@ -80,6 +88,12 @@ export function Intro({ initialStep }: { initialStep?: Step }) {
8088 </ CardHeader >
8189 < CardContent >
8290 < div className = "grid grid-cols-[auto_auto_min-content] items-center gap-4 " >
91+ { initialProjectName ? (
92+ < GroupCreateProjectForm . SetValue
93+ name = "name"
94+ value = { initialProjectName }
95+ />
96+ ) : null }
8397 < GroupCreateProjectForm . Name className = "contents space-y-0" />
8498 < GroupCreateProjectForm . Slug className = "contents space-y-0" />
8599 < GroupCreateProjectForm . Submit
@@ -98,6 +112,15 @@ export function Intro({ initialStep }: { initialStep?: Step }) {
98112 }
99113
100114 if ( step === Step . ChoosePlan ) {
115+ if ( ! groupId || ! project ) {
116+ // At this point those values should be defined, if not, we should redirect to the home page
117+ // It's unlikely that this will happen, but it's better to be safe than sorry
118+ Sentry . captureMessage (
119+ "Group or project not defined in Intro component" ,
120+ "fatal" ,
121+ ) ;
122+ return < Navigate to = "/" replace /> ;
123+ }
101124 return (
102125 < Suspense
103126 fallback = {
0 commit comments