Files
supabase/apps/studio/data/branches/branch-diff-query.ts
T
Raúl BarrosoandIvan Vasilov 86ef5e11cc feat(mgmt-api): adds partner confirmation page (#43237)
This adds some pages that will be needed soon.

Fixes
https://linear.app/supabase/issue/API-901/ship-studio-authentication-confirmation-page

Used by https://github.com/supabase/platform/pull/29718

Here are some screenshots of the 3 possible scenarios (initiated by the
Management API):

> [!NOTE]  
> As part of this flow, a new account + and a free organization will be
created.

### Initializing the confirmation flow

<img width="2708" height="1426" alt="CleanShot 2026-02-27 at 13 44
01@2x"
src="https://github.com/user-attachments/assets/e5a90886-43a9-4202-ad81-fb42c13da036"
/>

### Confirmation page

<img width="2610" height="1640" alt="CleanShot 2026-02-27 at 13 44
20@2x"
src="https://github.com/user-attachments/assets/8491fe24-c183-4987-a1c4-3d9b26dec9c3"
/>

### In the event of going through a flow with a different signed-in
account

<img width="1982" height="1564" alt="CleanShot 2026-02-27 at 13 47
44@2x"
src="https://github.com/user-attachments/assets/8a50b4c7-3fa4-4f6a-9d6f-b8776975b676"
/>

---------

Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-03-04 11:38:10 +00:00

65 lines
1.8 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
import type { ResponseError, UseCustomQueryOptions } from 'types'
import { branchKeys } from './keys'
export type BranchDiffVariables = {
branchRef: string
projectRef: string
includedSchemas?: string
pgdelta?: boolean
}
export async function getBranchDiff({
branchRef,
includedSchemas,
pgdelta,
}: Pick<BranchDiffVariables, 'branchRef' | 'includedSchemas' | 'pgdelta'>) {
const query: { included_schemas?: string; pgdelta?: string } = {}
if (includedSchemas) query.included_schemas = includedSchemas
if (pgdelta === true) query.pgdelta = 'true'
const { data: diffData, error } = await get('/v1/branches/{branch_id_or_ref}/diff', {
params: {
path: { branch_id_or_ref: branchRef },
query:
Object.keys(query).length > 0
? (query as { included_schemas?: string; pgdelta?: boolean })
: undefined,
},
headers: {
Accept: 'text/plain',
},
parseAs: 'text',
})
if (error) {
handleError(error)
}
// Handle empty object responses (when no diff exists)
if (typeof diffData === 'object' && Object.keys(diffData).length === 0) {
return ''
}
return diffData || ''
}
type BranchDiffData = Awaited<ReturnType<typeof getBranchDiff>>
export const useBranchDiffQuery = (
{ branchRef, projectRef, includedSchemas, pgdelta }: BranchDiffVariables,
{
enabled = true,
...options
}: Omit<UseCustomQueryOptions<BranchDiffData, ResponseError>, 'queryKey' | 'queryFn'> = {}
) =>
useQuery<BranchDiffData, ResponseError>({
queryKey: branchKeys.diff(projectRef, branchRef, pgdelta),
queryFn: () => getBranchDiff({ branchRef, includedSchemas, pgdelta }),
enabled: IS_PLATFORM && enabled && Boolean(branchRef),
...options,
})