@@ -7,94 +7,30 @@ import {
7
7
DropdownMenuRoot ,
8
8
DropdownMenuTrigger ,
9
9
} from '@/components'
10
- import { addProject } from '@/features/projects/actions'
11
- import { createClient } from '@/libs/db/client'
12
- import { getRepositoriesByInstallationId } from '@liam-hq/github'
13
- import type { Installation , Repository } from '@liam-hq/github'
14
- import { type FC , useCallback , useEffect , useState } from 'react'
10
+ import type { Installation } from '@liam-hq/github'
11
+ import { type FC , useState } from 'react'
15
12
import { P , match } from 'ts-pattern'
16
- import { RepositoryItem } from '../RepositoryItem'
17
13
import styles from './InstallationSelector.module.css'
14
+ import { RepositoriesPanel } from './RepositoriesPanel'
18
15
19
16
type Props = {
20
17
installations : Installation [ ]
21
- organizationId ? : string
18
+ organizationId : string
22
19
}
23
20
21
+ const githubAppUrl = process . env . NEXT_PUBLIC_GITHUB_APP_URL
22
+
24
23
export const InstallationSelector : FC < Props > = ( {
25
24
installations,
26
25
organizationId,
27
26
} ) => {
28
27
const [ selectedInstallation , setSelectedInstallation ] =
29
28
useState < Installation | null > ( null )
30
- const [ repositories , setRepositories ] = useState < Repository [ ] > ( [ ] )
31
- const [ loading , setLoading ] = useState ( false )
32
- const [ isAddingProject , setIsAddingProject ] = useState ( false )
33
-
34
- const githubAppUrl = process . env . NEXT_PUBLIC_GITHUB_APP_URL
35
-
36
- useEffect ( ( ) => {
37
- if ( selectedInstallation ) {
38
- fetchRepositories ( selectedInstallation . id )
39
- }
40
- } , [ selectedInstallation ] )
41
-
42
- const fetchRepositories = async ( installationId : number ) => {
43
- setLoading ( true )
44
- try {
45
- const supabase = await createClient ( )
46
- const { data } = await supabase . auth . getSession ( )
47
- const session = data . session
48
-
49
- if ( session === null ) {
50
- throw new Error ( '' )
51
- }
52
-
53
- const res = await getRepositoriesByInstallationId (
54
- data . session ,
55
- installationId ,
56
- )
57
- setRepositories ( res . repositories )
58
- } catch ( error ) {
59
- console . error ( 'Error fetching repositories:' , error )
60
- } finally {
61
- setLoading ( false )
62
- }
63
- }
64
29
65
30
const handleSelectInstallation = ( installation : Installation ) => {
66
31
setSelectedInstallation ( installation )
67
32
}
68
33
69
- const handleClick = useCallback (
70
- async ( repository : Repository ) => {
71
- try {
72
- setIsAddingProject ( true )
73
-
74
- const formData = new FormData ( )
75
- formData . set ( 'projectName' , repository . name )
76
- formData . set ( 'repositoryName' , repository . name )
77
- formData . set ( 'repositoryOwner' , repository . owner . login )
78
- formData . set ( 'repositoryId' , repository . id . toString ( ) )
79
- formData . set (
80
- 'installationId' ,
81
- selectedInstallation ?. id . toString ( ) || '' ,
82
- )
83
-
84
- if ( organizationId ) {
85
- formData . set ( 'organizationId' , organizationId . toString ( ) )
86
- }
87
-
88
- await addProject ( formData )
89
- // This point is not reached because a redirect occurs on success
90
- } catch ( error ) {
91
- console . error ( 'Error adding project:' , error )
92
- setIsAddingProject ( false )
93
- }
94
- } ,
95
- [ selectedInstallation , organizationId ] ,
96
- )
97
-
98
34
return (
99
35
< >
100
36
< div className = { styles . installationSelector } >
@@ -136,24 +72,11 @@ export const InstallationSelector: FC<Props> = ({
136
72
</ DropdownMenuRoot >
137
73
</ div >
138
74
139
- { loading && < div > Loading repositories...</ div > }
140
-
141
- { ! loading && repositories . length > 0 && (
142
- < div className = { styles . repositoriesList } >
143
- < h3 > Repositories</ h3 >
144
- { repositories . map ( ( repo ) => (
145
- < RepositoryItem
146
- key = { repo . id }
147
- name = { repo . name }
148
- onClick = { ( ) => handleClick ( repo ) }
149
- isLoading = { isAddingProject }
150
- />
151
- ) ) }
152
- </ div >
153
- ) }
154
-
155
- { ! loading && selectedInstallation && repositories . length === 0 && (
156
- < div > No repositories found</ div >
75
+ { selectedInstallation && (
76
+ < RepositoriesPanel
77
+ installationId = { selectedInstallation . id }
78
+ organizationId = { organizationId }
79
+ />
157
80
) }
158
81
</ >
159
82
)
0 commit comments