import { Button } from "@/src/components/ui/button"; import { Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/src/components/ui/dialog"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/src/components/ui/form"; import { Input } from "@/src/components/ui/input"; import { api } from "@/src/utils/api"; import * as z from "zod/v4"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture"; import { hasOrganizationAccess, useHasOrganizationAccess, } from "@/src/features/rbac/utils/checkOrganizationAccess"; import { useQueryProject } from "@/src/features/projects/hooks"; import { useSession } from "next-auth/react"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/src/components/ui/select"; import { Alert, AlertDescription, AlertTitle } from "@/src/components/ui/alert"; import { TriangleAlert } from "lucide-react"; import { showSuccessToast } from "@/src/features/notifications/showSuccessToast"; export function TransferProjectButton() { const capture = usePostHogClientCapture(); const session = useSession(); const { project, organization } = useQueryProject(); const hasAccess = useHasOrganizationAccess({ organizationId: organization?.id, scope: "projects:transfer_org", }); const allOrgs = session.data?.user?.organizations ?? []; const organizationsToTransferTo = allOrgs.filter((org) => hasOrganizationAccess({ session: session.data, organizationId: org.id, scope: "projects:transfer_org", }), ) ?? []; const confirmMessage = (organization?.name + "/" + project?.name) .replaceAll(" ", "-") .toLowerCase(); const formSchema = z.object({ name: z.string().includes(confirmMessage, { message: `Please confirm with "${confirmMessage}"`, }), projectId: z.string(), }); const transferProject = api.projects.transfer.useMutation({ onSuccess: async () => { showSuccessToast({ title: "Project transferred", description: "The project is successfully transferred to the new organization. Redirecting...", }); await new Promise((resolve) => setTimeout(resolve, 5000)); void session.update(); window.location.href = "/"; }, }); const form = useForm({ resolver: zodResolver(formSchema), defaultValues: { name: "", projectId: "", }, }); const onSubmit = (values: z.infer) => { if (!project) return; capture("project_settings:project_delete"); transferProject.mutate({ projectId: project.id, targetOrgId: values.projectId, }); }; return ( Transfer Project Warning Transferring the project will move it to a different organization:
  • Members who are not part of the new organization will lose access.
  • The project remains fully operational as API keys, settings, and data will remain unchanged. All features (e.g. tracing, prompt management) will continue to work without interruption.
( Select New Organization Transfer this project to another organization where you have the ability to create projects. )} /> ( Confirm {`To confirm, type "${confirmMessage}" in the input box `} )} />
); }