@@ -32,23 +32,25 @@ const createProjectFormSchema = z.object({
32
32
33
33
type CreateProjectFormData = z . infer < typeof createProjectFormSchema > ;
34
34
35
- const repositories = [
36
- { id : 12 , name : 'Repository 1' } ,
37
- { id : 123 , name : 'Repository 2' } ,
38
- { id : 41 , name : 'Repository 3' } ,
39
- { id : 24 , name : 'Repository 4' } ,
40
- { id : 124 , name : 'Repository 5' } ,
41
- ] ;
35
+ type Repository = {
36
+ id : number ;
37
+ name : string ;
38
+ } ;
42
39
43
- export default function CreateProjectForm ( { organizationId } : { organizationId : string } ) {
44
- const [ selectedRepo , setSelectedRepo ] = useState ( repositories [ 0 ] . id ) ;
40
+ type CreateProjectFormProps = {
41
+ organizationId : string ;
42
+ repositories : Repository [ ] ;
43
+ } ;
44
+
45
+ export default function CreateProjectForm ( { organizationId, repositories } : CreateProjectFormProps ) {
46
+ const [ selectedRepo , setSelectedRepo ] = useState ( repositories [ 0 ] ?. id || null ) ;
45
47
const router = useRouter ( ) ;
46
48
47
49
const { control, handleSubmit, setValue, watch } = useForm < CreateProjectFormData > ( {
48
50
resolver : zodResolver ( createProjectFormSchema ) ,
49
51
defaultValues : {
50
52
name : "" ,
51
- repository : repositories [ 0 ] . id ,
53
+ repository : repositories [ 0 ] ? .id || 0 ,
52
54
terraformDir : "" ,
53
55
managedState : true ,
54
56
labels : [ ] ,
@@ -84,8 +86,6 @@ export default function CreateProjectForm({ organizationId }: { organizationId:
84
86
createProjectMutation . mutate ( data ) ;
85
87
} ;
86
88
87
-
88
-
89
89
return (
90
90
< div className = "p-6 max-w-4xl mx-auto" >
91
91
< form onSubmit = { ( e ) => {
@@ -159,31 +159,43 @@ export default function CreateProjectForm({ organizationId }: { organizationId:
159
159
</ Badge >
160
160
</ CardHeader >
161
161
< CardContent >
162
- < ScrollArea className = "w-full whitespace-nowrap rounded-md border" >
163
- < div className = "flex w-max space-x-4 p-4" >
164
- { repositories . map ( ( repo , index ) => (
165
- < MotionCard
166
- key = { repo . id }
167
- className = { `w-[200px] cursor-pointer ${ selectedRepo === repo . id ? 'ring-2 ring-primary' : '' } ` }
168
- whileHover = { { scale : 1.05 } }
169
- whileTap = { { scale : 0.95 } }
170
- onClick = { ( ) => {
171
- setSelectedRepo ( repo . id ) ;
172
- setValue ( "repository" , repo . id ) ;
173
- } }
174
- initial = { { opacity : 0 , y : 20 } }
175
- animate = { { opacity : 1 , y : 0 } }
176
- transition = { { delay : index * 0.1 } }
177
- >
178
- < CardContent className = "flex items-center justify-center p-6" >
179
- < Github className = "mr-2 h-6 w-6" />
180
- < span > { repo . name } </ span >
181
- </ CardContent >
182
- </ MotionCard >
183
- ) ) }
162
+ { repositories . length > 0 ? (
163
+ < ScrollArea className = "w-full whitespace-nowrap rounded-md border" >
164
+ < div className = "flex w-max space-x-4 p-4" >
165
+ { repositories . map ( ( repo , index ) => (
166
+ < MotionCard
167
+ key = { repo . id }
168
+ className = { `w-[200px] cursor-pointer ${ selectedRepo === repo . id ? 'ring-2 ring-primary' : '' } ` }
169
+ whileHover = { { scale : 1.05 } }
170
+ whileTap = { { scale : 0.95 } }
171
+ onClick = { ( ) => {
172
+ setSelectedRepo ( repo . id ) ;
173
+ setValue ( "repository" , repo . id ) ;
174
+ } }
175
+ initial = { { opacity : 0 , y : 20 } }
176
+ animate = { { opacity : 1 , y : 0 } }
177
+ transition = { { delay : index * 0.1 } }
178
+ >
179
+ < CardContent className = "flex items-center justify-center p-6" >
180
+ < Github className = "mr-2 h-6 w-6" />
181
+ < span > { repo . name } </ span >
182
+ </ CardContent >
183
+ </ MotionCard >
184
+ ) ) }
185
+ </ div >
186
+ < ScrollBar orientation = "horizontal" />
187
+ </ ScrollArea >
188
+ ) : (
189
+ < div className = "text-center py-8" >
190
+ < div className = "bg-muted/50 rounded-full p-4 inline-block" >
191
+ < Github className = "mx-auto size-8 text-muted-foreground" />
192
+ </ div >
193
+ < T . H4 className = "mb-1 mt-4" > No Repositories Found</ T . H4 >
194
+ < T . P className = "text-muted-foreground mb-4" >
195
+ It looks like there are no repositories.
196
+ </ T . P >
184
197
</ div >
185
- < ScrollBar orientation = "horizontal" />
186
- </ ScrollArea >
198
+ ) }
187
199
</ CardContent >
188
200
</ MotionCard >
189
201
0 commit comments