ruvector/studio/data/projects/project-transfer-mutation.ts
rUv 814f595995 feat(studio): Add complete RuVector Studio application
Major additions:
- Complete Next.js studio application with 1600+ components
- Docker support (Dockerfile.combined, docker-compose.yml)
- GCP deployment documentation and benchmarks
- SQL benchmark scripts for performance testing
- Sentry integration for monitoring
- Comprehensive test suite and mocks

Studio features:
- Dashboard and admin interfaces
- Data visualization components
- Authentication and user management
- API integration with RuVector backend
- Static data and public assets

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-06 23:04:48 +00:00

68 lines
2.2 KiB
TypeScript

import { useMutation, useQueryClient } from '@tanstack/react-query'
import { toast } from 'sonner'
import { handleError, post } from 'data/fetchers'
import type { ResponseError, UseCustomMutationOptions } from 'types'
import { projectKeys } from './keys'
import { useInvalidateProjectsInfiniteQuery } from './org-projects-infinite-query'
export type ProjectTransferVariables = {
projectRef?: string
targetOrganizationSlug?: string
}
export async function transferProject({
projectRef,
targetOrganizationSlug,
}: ProjectTransferVariables) {
if (!projectRef) throw new Error('projectRef is required')
if (!targetOrganizationSlug) throw new Error('targetOrganizationSlug is required')
const payload: { target_organization_slug: string } = {
target_organization_slug: targetOrganizationSlug,
}
const { data, error } = await post('/platform/projects/{ref}/transfer', {
params: { path: { ref: projectRef } },
body: payload,
})
if (error) handleError(error)
return data
}
type ProjectTransferData = Awaited<ReturnType<typeof transferProject>>
export const useProjectTransferMutation = ({
onSuccess,
onError,
...options
}: Omit<
UseCustomMutationOptions<ProjectTransferData, ResponseError, ProjectTransferVariables>,
'mutationFn'
> = {}) => {
const queryClient = useQueryClient()
const { invalidateProjectsQuery } = useInvalidateProjectsInfiniteQuery()
return useMutation<ProjectTransferData, ResponseError, ProjectTransferVariables>({
mutationFn: (vars) => transferProject(vars),
async onSuccess(data, variables, context) {
const { projectRef, targetOrganizationSlug } = variables
await Promise.all([
queryClient.invalidateQueries({
queryKey: projectKeys.projectTransferPreview(projectRef, targetOrganizationSlug),
}),
queryClient.invalidateQueries({ queryKey: projectKeys.detail(projectRef) }),
invalidateProjectsQuery(),
])
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
if (onError === undefined) {
toast.error(`Failed to transfer project: ${data.message}`)
} else {
onError(data, variables, context)
}
},
...options,
})
}