@@ -3,6 +3,7 @@ import type {
33 LoaderFunctionArgs ,
44} from "@remix-run/node" ;
55import { json , redirect } from "@remix-run/node" ;
6+ import { fromPromise } from "neverthrow" ;
67import { Form , useActionData , useNavigation } from "@remix-run/react" ;
78import { typedjson , useTypedLoaderData } from "remix-typedjson" ;
89import { z } from "zod" ;
@@ -145,60 +146,67 @@ export const action = async ({ request, params }: ActionFunctionArgs) => {
145146 return json ( { error : "Vercel integration not found" } , { status : 404 } ) ;
146147 }
147148
148- try {
149- // First, attempt to uninstall the integration from Vercel side
150- const uninstallResult = await VercelIntegrationRepository . uninstallVercelIntegration ( vercelIntegration ) ;
149+ const uninstallActionResult = await fromPromise (
150+ ( async ( ) => {
151+ // First, attempt to uninstall the integration from Vercel side
152+ const uninstallResult = await VercelIntegrationRepository . uninstallVercelIntegration ( vercelIntegration ) ;
151153
152- // Then soft-delete the integration and all connected projects in a transaction
153- await $transaction ( prisma , async ( tx ) => {
154- // Soft-delete all connected projects
155- await tx . organizationProjectIntegration . updateMany ( {
156- where : {
157- organizationIntegrationId : vercelIntegration . id ,
158- deletedAt : null ,
159- } ,
160- data : { deletedAt : new Date ( ) } ,
161- } ) ;
154+ // Then soft-delete the integration and all connected projects in a transaction
155+ await $transaction ( prisma , async ( tx ) => {
156+ // Soft-delete all connected projects
157+ await tx . organizationProjectIntegration . updateMany ( {
158+ where : {
159+ organizationIntegrationId : vercelIntegration . id ,
160+ deletedAt : null ,
161+ } ,
162+ data : { deletedAt : new Date ( ) } ,
163+ } ) ;
162164
163- // Soft-delete the integration record
164- await tx . organizationIntegration . update ( {
165- where : { id : vercelIntegration . id } ,
166- data : { deletedAt : new Date ( ) } ,
165+ // Soft-delete the integration record
166+ await tx . organizationIntegration . update ( {
167+ where : { id : vercelIntegration . id } ,
168+ data : { deletedAt : new Date ( ) } ,
169+ } ) ;
167170 } ) ;
168- } ) ;
169171
170- if ( uninstallResult . authInvalid ) {
171- logger . warn ( "Vercel integration uninstalled with auth error - token invalid" , {
172- organizationId : organization . id ,
173- organizationSlug,
174- userId,
175- integrationId : vercelIntegration . id ,
176- } ) ;
177- } else {
178- logger . info ( "Vercel integration uninstalled successfully" , {
179- organizationId : organization . id ,
180- organizationSlug,
181- userId,
182- integrationId : vercelIntegration . id ,
183- } ) ;
184- }
172+ return uninstallResult ;
173+ } ) ( ) ,
174+ ( error ) => error
175+ ) ;
185176
186- // Redirect back to organization settings
187- return redirect ( `/orgs/${ organizationSlug } /settings` ) ;
188- } catch ( error ) {
177+ if ( uninstallActionResult . isErr ( ) ) {
189178 logger . error ( "Failed to uninstall Vercel integration" , {
190179 organizationId : organization . id ,
191180 organizationSlug,
192181 userId,
193182 integrationId : vercelIntegration . id ,
194- error : error instanceof Error ? error . message : String ( error ) ,
183+ error : uninstallActionResult . error instanceof Error ? uninstallActionResult . error . message : String ( uninstallActionResult . error ) ,
195184 } ) ;
196185
197186 return json (
198187 { error : "Failed to uninstall Vercel integration. Please try again." } ,
199188 { status : 500 }
200189 ) ;
201190 }
191+
192+ if ( uninstallActionResult . value . authInvalid ) {
193+ logger . warn ( "Vercel integration uninstalled with auth error - token invalid" , {
194+ organizationId : organization . id ,
195+ organizationSlug,
196+ userId,
197+ integrationId : vercelIntegration . id ,
198+ } ) ;
199+ } else {
200+ logger . info ( "Vercel integration uninstalled successfully" , {
201+ organizationId : organization . id ,
202+ organizationSlug,
203+ userId,
204+ integrationId : vercelIntegration . id ,
205+ } ) ;
206+ }
207+
208+ // Redirect back to organization settings
209+ return redirect ( `/orgs/${ organizationSlug } /settings` ) ;
202210} ;
203211
204212export default function VercelIntegrationPage ( ) {
0 commit comments