Files
supabase/apps/studio/data/integrations/github-connection-update-mutation.ts
Saxon Fletcher 3f3ed433fc Remove enable branching modal (#36458)
* remove enable branching modal

* re-add github linker

* abstract away enable and disable

* toggle fixes

* update logic to lean on connection status

* update form logic

* sheet layout

* gitless flag

* fix side panel size

* copy changes

* remove import

* add cost

* allow connection details on create

* Fix TS issues

* Fix TS issues

* Couple of clean ups

* Revert hardcode in useFlag

* Fix TS

* layout issues and github check

* refactor

* refactor to use new field

* cleanup

* style

* clarification with github integration

* replace branch dropdown button

* update repo picker

* remove modal

* change defaults

* disable if not gitless and no connection

* fixes

* prevent editing on child branch

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2025-07-02 21:58:45 +10:00

62 lines
1.8 KiB
TypeScript

import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { components } from 'api-types'
import { handleError, patch } from 'data/fetchers'
import type { ResponseError } from 'types'
import { integrationKeys } from './keys'
type GitHubConnectionUpdateVariables = {
connectionId: string | number
organizationId: number
connection: components['schemas']['UpdateGitHubConnectionBody']
}
export async function updateConnection(
{ connectionId, connection }: GitHubConnectionUpdateVariables,
signal?: AbortSignal
) {
const { data, error } = await patch('/platform/integrations/github/connections/{connection_id}', {
params: { path: { connection_id: String(connectionId) } },
signal,
body: connection,
})
if (error) handleError(error)
return data
}
type UpdateContentData = Awaited<ReturnType<typeof updateConnection>>
export const useGitHubConnectionUpdateMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseMutationOptions<UpdateContentData, ResponseError, GitHubConnectionUpdateVariables>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
return useMutation<UpdateContentData, ResponseError, GitHubConnectionUpdateVariables>(
(args) => updateConnection(args),
{
async onSuccess(data, variables, context) {
await Promise.all([
queryClient.invalidateQueries(
integrationKeys.githubConnectionsList(variables.organizationId)
),
])
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to update Github connection: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
}
)
}