@@ -47,6 +47,7 @@ import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
4747
4848const GITHUB_ICON = (
4949 < svg xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 98 96" className = "w-6" >
50+ < title > GitHub icon</ title >
5051 < path
5152 fill = "#ffffff"
5253 fillRule = "evenodd"
@@ -70,7 +71,7 @@ const GitHubIntegrationConnectionForm = ({
7071 const [ isConfirmingBranchChange , setIsConfirmingBranchChange ] = useState ( false )
7172 const [ isConfirmingRepoChange , setIsConfirmingRepoChange ] = useState ( false )
7273 const [ repoComboBoxOpen , setRepoComboboxOpen ] = useState ( false )
73- const isParentProject = ! Boolean ( selectedProject ?. parent_project_ref )
74+ const isParentProject = ! selectedProject ?. parent_project_ref
7475
7576 const { can : canUpdateGitHubConnection } = useAsyncCheckPermissions (
7677 PermissionAction . UPDATE ,
@@ -81,14 +82,24 @@ const GitHubIntegrationConnectionForm = ({
8182 'integrations.github_connections'
8283 )
8384
84- const { data : gitHubAuthorization } = useGitHubAuthorizationQuery ( )
85+ const { data : gitHubAuthorization , refetch : refetchGitHubAuthorization } =
86+ useGitHubAuthorizationQuery ( )
8587
86- const { data : githubReposData , isLoading : isLoadingGitHubRepos } = useGitHubRepositoriesQuery <
87- any [ ]
88- > ( {
88+ const {
89+ data : githubReposData ,
90+ isLoading : isLoadingGitHubRepos ,
91+ refetch : refetchGitHubRepositories ,
92+ } = useGitHubRepositoriesQuery ( {
8993 enabled : Boolean ( gitHubAuthorization ) ,
9094 } )
9195
96+ const refetchGitHubAuthorizationAndRepositories = ( ) => {
97+ setTimeout ( ( ) => {
98+ refetchGitHubAuthorization ( )
99+ refetchGitHubRepositories ( )
100+ } , 2000 ) // 2 second to delay to let github authorization and repositories to be updated
101+ }
102+
92103 const { mutate : updateBranch } = useBranchUpdateMutation ( {
93104 onSuccess : ( ) => {
94105 toast . success ( 'Production branch settings successfully updated' )
@@ -130,7 +141,7 @@ const GitHubIntegrationConnectionForm = ({
130141
131142 const githubRepos = useMemo (
132143 ( ) =>
133- githubReposData ?. map ( ( repo : any ) => ( {
144+ githubReposData ?. map ( ( repo ) => ( {
134145 id : repo . id . toString ( ) ,
135146 name : repo . name ,
136147 installation_id : repo . installation_id ,
@@ -161,7 +172,7 @@ const GitHubIntegrationConnectionForm = ({
161172 repositoryId : Number ( repositoryId ) ,
162173 branchName : val . branchName ,
163174 } )
164- } catch ( error ) {
175+ } catch {
165176 const selectedRepo = githubRepos . find ( ( repo ) => repo . id === repositoryId )
166177 const repoName =
167178 selectedRepo ?. name || connection ?. repository . name || 'selected repository'
@@ -337,11 +348,11 @@ const GitHubIntegrationConnectionForm = ({
337348 const data = githubSettingsForm . getValues ( )
338349 const selectedRepo = githubRepos . find ( ( repo ) => repo . id === data . repositoryId )
339350
340- if ( ! selectedRepo || ! connection ) return
351+ if ( ! selectedRepo || ! connection || ! selectedOrganization ?. id ) return
341352
342353 try {
343354 await deleteConnection ( {
344- organizationId : selectedOrganization ! . id ,
355+ organizationId : selectedOrganization . id ,
345356 connectionId : connection . id ,
346357 } )
347358
@@ -390,7 +401,10 @@ const GitHubIntegrationConnectionForm = ({
390401 </ p >
391402 < Button
392403 onClick = { ( ) => {
393- openInstallGitHubIntegrationWindow ( 'authorize' )
404+ openInstallGitHubIntegrationWindow (
405+ 'authorize' ,
406+ refetchGitHubAuthorizationAndRepositories
407+ )
394408 } }
395409 >
396410 Authorize GitHub
@@ -482,7 +496,12 @@ const GitHubIntegrationConnectionForm = ({
482496 < CommandGroup_Shadcn_ >
483497 < CommandItem_Shadcn_
484498 className = "flex gap-2 items-center cursor-pointer"
485- onSelect = { ( ) => openInstallGitHubIntegrationWindow ( 'install' ) }
499+ onSelect = { ( ) =>
500+ openInstallGitHubIntegrationWindow (
501+ 'install' ,
502+ refetchGitHubAuthorizationAndRepositories
503+ )
504+ }
486505 >
487506 < PlusIcon size = { 16 } />
488507 Add GitHub Repositories
0 commit comments