mirror of
https://github.com/supabase/supabase.git
synced 2026-07-04 02:54:28 +08:00
* 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>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { useMutation, UseMutationOptions } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { get, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
|
|
export type GithubBranchVariables = {
|
|
repositoryId: number
|
|
branchName: string
|
|
}
|
|
|
|
export async function checkGithubBranchValidity(
|
|
{ repositoryId, branchName }: GithubBranchVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const { data, error } = await get(
|
|
'/platform/integrations/github/repositories/{repositoryId}/branches/{branchName}',
|
|
{
|
|
params: {
|
|
path: {
|
|
repositoryId,
|
|
branchName,
|
|
},
|
|
},
|
|
signal,
|
|
}
|
|
)
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type GitHubIntegrationCreateData = Awaited<ReturnType<typeof checkGithubBranchValidity>>
|
|
|
|
export const useCheckGithubBranchValidity = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<GitHubIntegrationCreateData, ResponseError, GithubBranchVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
return useMutation<GitHubIntegrationCreateData, ResponseError, GithubBranchVariables>(
|
|
(vars) => checkGithubBranchValidity(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to check Github branch: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|