@@ -161,9 +161,14 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
161161 return typedjson ( { githubAppInstallations, connectedGithubRepository : undefined } ) ;
162162} ;
163163
164+ const ConnectGitHubRepoFormSchema = z . object ( {
165+ action : z . literal ( "connect-repo" ) ,
166+ installationId : z . string ( ) ,
167+ repositoryId : z . string ( ) ,
168+ } ) ;
169+
164170const UpdateGitSettingsFormSchema = z . object ( {
165171 action : z . literal ( "update-git-settings" ) ,
166- projectId : z . string ( ) ,
167172 productionBranch : z . string ( ) . min ( 1 , "Production branch is required" ) ,
168173 stagingBranch : z . string ( ) . min ( 1 , "Staging branch is required" ) ,
169174 previewDeploymentsEnabled : z
@@ -203,13 +208,11 @@ export function createSchema(
203208 }
204209 } ) ,
205210 } ) ,
211+ ConnectGitHubRepoFormSchema ,
212+ UpdateGitSettingsFormSchema ,
206213 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" ) ,
211215 } ) ,
212- UpdateGitSettingsFormSchema ,
213216 ] ) ;
214217}
215218
@@ -254,6 +257,8 @@ export const action: ActionFunction = async ({ request, params }) => {
254257 return json ( { errors : { body : "project not found" } } , { status : 404 } ) ;
255258 }
256259
260+ console . log ( submission . value ) ;
261+
257262 try {
258263 switch ( submission . value . action ) {
259264 case "rename" : {
@@ -293,13 +298,24 @@ export const action: ActionFunction = async ({ request, params }) => {
293298 ) ;
294299 }
295300 }
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+ }
296313 case "update-git-settings" : {
297- const { projectId, productionBranch, stagingBranch, previewDeploymentsEnabled } =
298- submission . value ;
314+ const { productionBranch, stagingBranch, previewDeploymentsEnabled } = submission . value ;
299315
300316 const existingConnection = await prisma . connectedGithubRepository . findFirst ( {
301317 where : {
302- projectId : projectId ,
318+ projectId : project . id ,
303319 } ,
304320 } ) ;
305321
@@ -309,7 +325,7 @@ export const action: ActionFunction = async ({ request, params }) => {
309325
310326 await prisma . connectedGithubRepository . update ( {
311327 where : {
312- projectId : projectId ,
328+ projectId : project . id ,
313329 } ,
314330 data : {
315331 branchTracking : {
@@ -323,7 +339,7 @@ export const action: ActionFunction = async ({ request, params }) => {
323339 return redirectBackWithSuccessMessage ( request , "Git settings updated successfully" ) ;
324340 }
325341 case "connect-repo" : {
326- const { repositoryId, projectId } = submission . value ;
342+ const { repositoryId } = submission . value ;
327343
328344 const [ repository , existingConnection ] = await Promise . all ( [
329345 prisma . githubRepository . findFirst ( {
@@ -341,7 +357,7 @@ export const action: ActionFunction = async ({ request, params }) => {
341357 } ) ,
342358 prisma . connectedGithubRepository . findFirst ( {
343359 where : {
344- projectId : projectId ,
360+ projectId : project . id ,
345361 } ,
346362 } ) ,
347363 ] ) ;
@@ -359,7 +375,7 @@ export const action: ActionFunction = async ({ request, params }) => {
359375
360376 await prisma . connectedGithubRepository . create ( {
361377 data : {
362- projectId : projectId ,
378+ projectId : project . id ,
363379 repositoryId : repositoryId ,
364380 branchTracking : {
365381 production : { branch : repository . defaultBranch } ,
@@ -501,15 +517,11 @@ export default function Page() {
501517 < Header2 spacing > Git settings</ Header2 >
502518 < div className = "w-full rounded-sm border border-grid-dimmed p-4" >
503519 { connectedGithubRepository ? (
504- < ConnectedGitHubRepoForm
505- connectedGitHubRepo = { connectedGithubRepository }
506- projectId = { project . id }
507- />
520+ < ConnectedGitHubRepoForm connectedGitHubRepo = { connectedGithubRepository } />
508521 ) : (
509522 < GitHubConnectionPrompt
510523 gitHubAppInstallations = { githubAppInstallations }
511524 organizationSlug = { organization . slug }
512- projectId = { project . id }
513525 />
514526 ) }
515527 </ div >
@@ -561,12 +573,6 @@ export default function Page() {
561573 ) ;
562574}
563575
564- const ConnectGitHubRepoFormSchema = z . object ( {
565- installationId : z . string ( ) ,
566- repositoryId : z . string ( ) ,
567- projectId : z . string ( ) ,
568- } ) ;
569-
570576type GitHubRepository = {
571577 id : string ;
572578 name : string ;
@@ -584,10 +590,8 @@ type GitHubAppInstallation = {
584590
585591function ConnectGitHubRepoModal ( {
586592 gitHubAppInstallations,
587- projectId : triggerProjectId ,
588593} : {
589594 gitHubAppInstallations : GitHubAppInstallation [ ] ;
590- projectId : string ;
591595} ) {
592596 const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
593597 const lastSubmission = useActionData ( ) as any ;
@@ -608,7 +612,7 @@ function ConnectGitHubRepoModal({
608612 navigation . formData ?. get ( "action" ) === "connect-repo" &&
609613 ( navigation . state === "submitting" || navigation . state === "loading" ) ;
610614
611- const [ form , { installationId, repositoryId, projectId } ] = useForm ( {
615+ const [ form , { installationId, repositoryId } ] = useForm ( {
612616 id : "connect-repo" ,
613617 lastSubmission : lastSubmission ,
614618 shouldRevalidate : "onSubmit" ,
@@ -636,7 +640,6 @@ function ConnectGitHubRepoModal({
636640 < DialogHeader > Connect GitHub repository</ DialogHeader >
637641 < div className = "mt-2 flex flex-col gap-4" >
638642 < Form method = "post" { ...form . props } className = "w-full" >
639- < input { ...conform . input ( projectId , { type : "hidden" } ) } value = { triggerProjectId } />
640643 < Paragraph className = "mb-3" >
641644 Choose a GitHub repository to connect to your project.
642645 </ Paragraph >
@@ -751,11 +754,9 @@ function ConnectGitHubRepoModal({
751754function GitHubConnectionPrompt ( {
752755 gitHubAppInstallations,
753756 organizationSlug,
754- projectId,
755757} : {
756758 gitHubAppInstallations : GitHubAppInstallation [ ] ;
757759 organizationSlug : string ;
758- projectId : string ;
759760} ) {
760761 return (
761762 < Fieldset >
@@ -771,10 +772,7 @@ function GitHubConnectionPrompt({
771772 ) }
772773 { gitHubAppInstallations . length !== 0 && (
773774 < div className = "flex items-center gap-3" >
774- < ConnectGitHubRepoModal
775- gitHubAppInstallations = { gitHubAppInstallations }
776- projectId = { projectId }
777- />
775+ < ConnectGitHubRepoModal gitHubAppInstallations = { gitHubAppInstallations } />
778776 < span className = "flex items-center gap-1 text-xs text-text-dimmed" >
779777 < CheckCircleIcon className = "size-4 text-success" /> GitHub app is installed
780778 </ span >
@@ -796,10 +794,8 @@ type ConnectedGitHubRepo = {
796794
797795function ConnectedGitHubRepoForm ( {
798796 connectedGitHubRepo,
799- projectId,
800797} : {
801798 connectedGitHubRepo : ConnectedGitHubRepo ;
802- projectId : string ;
803799} ) {
804800 const lastSubmission = useActionData ( ) as any ;
805801 const navigation = useNavigation ( ) ;
@@ -835,11 +831,14 @@ function ConnectedGitHubRepoForm({
835831 < LockClosedIcon className = "size-3 text-text-dimmed" />
836832 ) }
837833 </ 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 >
839839 </ div >
840840
841841 < Form method = "post" { ...gitSettingsForm . props } >
842- < input type = "hidden" name = "projectId" value = { projectId } />
843842 < Fieldset >
844843 < InputGroup fullWidth >
845844 < Hint >
0 commit comments