@@ -27,7 +27,11 @@ import {
2727 FormItem ,
2828 FormMessage
2929} from '@/components/ui/form'
30- import { IconCheck , IconChevronUpDown } from '@/components/ui/icons'
30+ import {
31+ IconCheck ,
32+ IconChevronUpDown ,
33+ IconSpinner
34+ } from '@/components/ui/icons'
3135import {
3236 Popover ,
3337 PopoverContent ,
@@ -43,11 +47,11 @@ const formSchema = z.object({
4347 id : z . string ( )
4448} )
4549
46- type LinkRepositoryFormValues = z . infer < typeof formSchema >
50+ type ActivateRepositoryFormValues = z . infer < typeof formSchema >
4751
48- interface LinkRepositoryFormProps {
52+ interface ActivateRepositoryFormProps {
4953 kind : RepositoryKind
50- onCreated ?: ( ) => void
54+ onCreated ?: ( id : string ) => void
5155 onCancel : ( ) => void
5256 providerStatus : RepositoryProviderStatus | undefined
5357 repositories :
@@ -62,20 +66,21 @@ interface LinkRepositoryFormProps {
6266 }
6367 } >
6468 | undefined
69+ fetchingRepos : boolean
6570}
6671
67- export default function LinkRepositoryForm ( {
72+ export default function AddRepositoryForm ( {
6873 kind,
6974 onCreated,
7075 onCancel,
7176 repositories,
72- providerStatus
73- } : LinkRepositoryFormProps ) {
77+ providerStatus,
78+ fetchingRepos
79+ } : ActivateRepositoryFormProps ) {
7480 const [ open , setOpen ] = React . useState ( false )
75- const form = useForm < LinkRepositoryFormValues > ( {
81+ const form = useForm < ActivateRepositoryFormValues > ( {
7682 resolver : zodResolver ( formSchema )
7783 } )
78- const [ searchValue , setSearchValue ] = React . useState < string > ( )
7984 const commandListRef = React . useRef < HTMLDivElement > ( null )
8085
8186 const { isSubmitting } = form . formState
@@ -94,41 +99,41 @@ export default function LinkRepositoryForm({
9499 const updateGithubProvidedRepositoryActive = useMutation (
95100 updateGithubProvidedRepositoryActiveMutation ,
96101 {
97- onCompleted ( data ) {
98- if ( data ?. updateGithubProvidedRepositoryActive ) {
99- form . reset ( { id : undefined } )
100- onCreated ?.( )
101- }
102- } ,
103102 form
104103 }
105104 )
106105
107106 const updateGitlabProvidedRepositoryActive = useMutation (
108107 updateGitlabProvidedRepositoryActiveMutation ,
109108 {
110- onCompleted ( data ) {
111- if ( data ?. updateGitlabProvidedRepositoryActive ) {
112- form . reset ( { id : undefined } )
113- onCreated ?.( )
114- }
115- } ,
116109 form
117110 }
118111 )
119112
120- const onSubmit = ( values : LinkRepositoryFormValues ) => {
113+ const onSubmit = ( values : ActivateRepositoryFormValues ) => {
114+ const id = values . id
115+
121116 if ( kind === RepositoryKind . Github ) {
122117 return updateGithubProvidedRepositoryActive ( {
123118 id : values . id ,
124119 active : true
120+ } ) . then ( res => {
121+ if ( res ?. data ?. updateGithubProvidedRepositoryActive ) {
122+ form . reset ( { id : undefined } )
123+ onCreated ?.( id )
124+ }
125125 } )
126126 }
127127
128128 if ( kind === RepositoryKind . Gitlab ) {
129129 return updateGitlabProvidedRepositoryActive ( {
130130 id : values . id ,
131131 active : true
132+ } ) . then ( res => {
133+ if ( res ?. data ?. updateGitlabProvidedRepositoryActive ) {
134+ form . reset ( { id : undefined } )
135+ onCreated ?.( id )
136+ }
132137 } )
133138 }
134139 }
@@ -188,7 +193,15 @@ export default function LinkRepositoryForm({
188193 className = "max-h-[30vh]"
189194 ref = { commandListRef }
190195 >
191- < CommandEmpty > { emptyText } </ CommandEmpty >
196+ < CommandEmpty >
197+ { fetchingRepos ? (
198+ < div className = "flex justify-center" >
199+ < IconSpinner className = "h-6 w-6" />
200+ </ div >
201+ ) : (
202+ emptyText
203+ ) }
204+ </ CommandEmpty >
192205 < CommandGroup >
193206 { providerStatus !==
194207 RepositoryProviderStatus . Pending &&
0 commit comments