@@ -161,9 +161,14 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
161
161
return typedjson ( { githubAppInstallations, connectedGithubRepository : undefined } ) ;
162
162
} ;
163
163
164
+ const ConnectGitHubRepoFormSchema = z . object ( {
165
+ action : z . literal ( "connect-repo" ) ,
166
+ installationId : z . string ( ) ,
167
+ repositoryId : z . string ( ) ,
168
+ } ) ;
169
+
164
170
const UpdateGitSettingsFormSchema = z . object ( {
165
171
action : z . literal ( "update-git-settings" ) ,
166
- projectId : z . string ( ) ,
167
172
productionBranch : z . string ( ) . min ( 1 , "Production branch is required" ) ,
168
173
stagingBranch : z . string ( ) . min ( 1 , "Staging branch is required" ) ,
169
174
previewDeploymentsEnabled : z
@@ -203,13 +208,11 @@ export function createSchema(
203
208
}
204
209
} ) ,
205
210
} ) ,
211
+ ConnectGitHubRepoFormSchema ,
212
+ UpdateGitSettingsFormSchema ,
206
213
z . object ( {
207
- action : z . literal ( "connect-repo" ) ,
208
- installationId : z . string ( ) . min ( 1 , "Installation is required" ) ,
209
- repositoryId : z . string ( ) . min ( 1 , "Repository is required" ) ,
210
- projectId : z . string ( ) . min ( 1 , "Project ID is required" ) ,
214
+ action : z . literal ( "disconnect-repo" ) ,
211
215
} ) ,
212
- UpdateGitSettingsFormSchema ,
213
216
] ) ;
214
217
}
215
218
@@ -254,6 +257,8 @@ export const action: ActionFunction = async ({ request, params }) => {
254
257
return json ( { errors : { body : "project not found" } } , { status : 404 } ) ;
255
258
}
256
259
260
+ console . log ( submission . value ) ;
261
+
257
262
try {
258
263
switch ( submission . value . action ) {
259
264
case "rename" : {
@@ -293,13 +298,24 @@ export const action: ActionFunction = async ({ request, params }) => {
293
298
) ;
294
299
}
295
300
}
301
+ case "disconnect-repo" : {
302
+ await prisma . connectedGithubRepository . delete ( {
303
+ where : {
304
+ projectId : project . id ,
305
+ } ,
306
+ } ) ;
307
+
308
+ return redirectBackWithSuccessMessage (
309
+ request ,
310
+ "GitHub repository disconnected successfully"
311
+ ) ;
312
+ }
296
313
case "update-git-settings" : {
297
- const { projectId, productionBranch, stagingBranch, previewDeploymentsEnabled } =
298
- submission . value ;
314
+ const { productionBranch, stagingBranch, previewDeploymentsEnabled } = submission . value ;
299
315
300
316
const existingConnection = await prisma . connectedGithubRepository . findFirst ( {
301
317
where : {
302
- projectId : projectId ,
318
+ projectId : project . id ,
303
319
} ,
304
320
} ) ;
305
321
@@ -309,7 +325,7 @@ export const action: ActionFunction = async ({ request, params }) => {
309
325
310
326
await prisma . connectedGithubRepository . update ( {
311
327
where : {
312
- projectId : projectId ,
328
+ projectId : project . id ,
313
329
} ,
314
330
data : {
315
331
branchTracking : {
@@ -323,7 +339,7 @@ export const action: ActionFunction = async ({ request, params }) => {
323
339
return redirectBackWithSuccessMessage ( request , "Git settings updated successfully" ) ;
324
340
}
325
341
case "connect-repo" : {
326
- const { repositoryId, projectId } = submission . value ;
342
+ const { repositoryId } = submission . value ;
327
343
328
344
const [ repository , existingConnection ] = await Promise . all ( [
329
345
prisma . githubRepository . findFirst ( {
@@ -341,7 +357,7 @@ export const action: ActionFunction = async ({ request, params }) => {
341
357
} ) ,
342
358
prisma . connectedGithubRepository . findFirst ( {
343
359
where : {
344
- projectId : projectId ,
360
+ projectId : project . id ,
345
361
} ,
346
362
} ) ,
347
363
] ) ;
@@ -359,7 +375,7 @@ export const action: ActionFunction = async ({ request, params }) => {
359
375
360
376
await prisma . connectedGithubRepository . create ( {
361
377
data : {
362
- projectId : projectId ,
378
+ projectId : project . id ,
363
379
repositoryId : repositoryId ,
364
380
branchTracking : {
365
381
production : { branch : repository . defaultBranch } ,
@@ -501,15 +517,11 @@ export default function Page() {
501
517
< Header2 spacing > Git settings</ Header2 >
502
518
< div className = "w-full rounded-sm border border-grid-dimmed p-4" >
503
519
{ connectedGithubRepository ? (
504
- < ConnectedGitHubRepoForm
505
- connectedGitHubRepo = { connectedGithubRepository }
506
- projectId = { project . id }
507
- />
520
+ < ConnectedGitHubRepoForm connectedGitHubRepo = { connectedGithubRepository } />
508
521
) : (
509
522
< GitHubConnectionPrompt
510
523
gitHubAppInstallations = { githubAppInstallations }
511
524
organizationSlug = { organization . slug }
512
- projectId = { project . id }
513
525
/>
514
526
) }
515
527
</ div >
@@ -561,12 +573,6 @@ export default function Page() {
561
573
) ;
562
574
}
563
575
564
- const ConnectGitHubRepoFormSchema = z . object ( {
565
- installationId : z . string ( ) ,
566
- repositoryId : z . string ( ) ,
567
- projectId : z . string ( ) ,
568
- } ) ;
569
-
570
576
type GitHubRepository = {
571
577
id : string ;
572
578
name : string ;
@@ -584,10 +590,8 @@ type GitHubAppInstallation = {
584
590
585
591
function ConnectGitHubRepoModal ( {
586
592
gitHubAppInstallations,
587
- projectId : triggerProjectId ,
588
593
} : {
589
594
gitHubAppInstallations : GitHubAppInstallation [ ] ;
590
- projectId : string ;
591
595
} ) {
592
596
const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
593
597
const lastSubmission = useActionData ( ) as any ;
@@ -608,7 +612,7 @@ function ConnectGitHubRepoModal({
608
612
navigation . formData ?. get ( "action" ) === "connect-repo" &&
609
613
( navigation . state === "submitting" || navigation . state === "loading" ) ;
610
614
611
- const [ form , { installationId, repositoryId, projectId } ] = useForm ( {
615
+ const [ form , { installationId, repositoryId } ] = useForm ( {
612
616
id : "connect-repo" ,
613
617
lastSubmission : lastSubmission ,
614
618
shouldRevalidate : "onSubmit" ,
@@ -636,7 +640,6 @@ function ConnectGitHubRepoModal({
636
640
< DialogHeader > Connect GitHub repository</ DialogHeader >
637
641
< div className = "mt-2 flex flex-col gap-4" >
638
642
< Form method = "post" { ...form . props } className = "w-full" >
639
- < input { ...conform . input ( projectId , { type : "hidden" } ) } value = { triggerProjectId } />
640
643
< Paragraph className = "mb-3" >
641
644
Choose a GitHub repository to connect to your project.
642
645
</ Paragraph >
@@ -751,11 +754,9 @@ function ConnectGitHubRepoModal({
751
754
function GitHubConnectionPrompt ( {
752
755
gitHubAppInstallations,
753
756
organizationSlug,
754
- projectId,
755
757
} : {
756
758
gitHubAppInstallations : GitHubAppInstallation [ ] ;
757
759
organizationSlug : string ;
758
- projectId : string ;
759
760
} ) {
760
761
return (
761
762
< Fieldset >
@@ -771,10 +772,7 @@ function GitHubConnectionPrompt({
771
772
) }
772
773
{ gitHubAppInstallations . length !== 0 && (
773
774
< div className = "flex items-center gap-3" >
774
- < ConnectGitHubRepoModal
775
- gitHubAppInstallations = { gitHubAppInstallations }
776
- projectId = { projectId }
777
- />
775
+ < ConnectGitHubRepoModal gitHubAppInstallations = { gitHubAppInstallations } />
778
776
< span className = "flex items-center gap-1 text-xs text-text-dimmed" >
779
777
< CheckCircleIcon className = "size-4 text-success" /> GitHub app is installed
780
778
</ span >
@@ -796,10 +794,8 @@ type ConnectedGitHubRepo = {
796
794
797
795
function ConnectedGitHubRepoForm ( {
798
796
connectedGitHubRepo,
799
- projectId,
800
797
} : {
801
798
connectedGitHubRepo : ConnectedGitHubRepo ;
802
- projectId : string ;
803
799
} ) {
804
800
const lastSubmission = useActionData ( ) as any ;
805
801
const navigation = useNavigation ( ) ;
@@ -835,11 +831,14 @@ function ConnectedGitHubRepoForm({
835
831
< LockClosedIcon className = "size-3 text-text-dimmed" />
836
832
) }
837
833
</ div >
838
- < Button variant = "minimal/small" > Disconnect</ Button >
834
+ < Form method = "post" >
835
+ < Button type = "submit" name = "action" value = "disconnect-repo" variant = "minimal/small" >
836
+ Disconnect
837
+ </ Button >
838
+ </ Form >
839
839
</ div >
840
840
841
841
< Form method = "post" { ...gitSettingsForm . props } >
842
- < input type = "hidden" name = "projectId" value = { projectId } />
843
842
< Fieldset >
844
843
< InputGroup fullWidth >
845
844
< Hint >
0 commit comments