import { OAuthScope } from '@supabase/shared-types/out/constants' import { useParams } from 'common' import { CheckCircle2, ChevronRight, ChevronsLeftRight } from 'lucide-react' import Image from 'next/image' import { useRouter } from 'next/router' import { toast } from 'sonner' import { Button, cn, Collapsible, CollapsibleContent, CollapsibleTrigger } from 'ui' import { Admonition } from 'ui-patterns/admonition' import { ScopeSection } from '../OAuthApps/AuthorizeRequesterDetails' import { PERMISSIONS_DESCRIPTIONS } from '../OAuthApps/OAuthApps.constants' import { ProjectClaimLayout } from './layout' import { useApiAuthorizationApproveMutation } from '@/data/api-authorization/api-authorization-approve-mutation' import { ApiAuthorizationResponse } from '@/data/api-authorization/api-authorization-query' import { useOrganizationProjectClaimMutation } from '@/data/organizations/organization-project-claim-mutation' import { OrganizationProjectClaimResponse } from '@/data/organizations/organization-project-claim-query' import { useInvalidateProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query' import { BASE_PATH } from '@/lib/constants' import type { Organization } from '@/types' export const ProjectClaimConfirm = ({ selectedOrganization, projectClaim, requester, setStep, }: { selectedOrganization: Organization projectClaim: OrganizationProjectClaimResponse requester: ApiAuthorizationResponse setStep: (step: 'choose-org' | 'benefits' | 'confirm') => void }) => { const router = useRouter() const { auth_id, token: claimToken } = useParams() const { invalidateProjectsQuery } = useInvalidateProjectsInfiniteQuery() const { mutateAsync: approveRequest, isPending: isApproving } = useApiAuthorizationApproveMutation({ onError: () => {} }) const { mutateAsync: claimProject, isPending: isClaiming } = useOrganizationProjectClaimMutation() const onClaimProject = async () => { try { const response = await approveRequest({ id: auth_id!, slug: selectedOrganization.slug }) await claimProject({ slug: selectedOrganization.slug, token: claimToken!, }) toast.success('Project claimed successfully') try { // check if the redirect url is valid. If not, redirect the user to the org dashboard const url = new URL(response.url) window.location.href = url.toString() } catch { // invalidate the org projects to force them to be refetched await invalidateProjectsQuery() router.push(`/org/${selectedOrganization.slug}`) } } catch (error: any) { toast.error(`Failed to claim project ${error.message}`) } } const isLoading = isApproving || isClaiming return ( Claim a project {projectClaim?.project?.name} from{' '} {requester?.name} } >
{!requester.icon && (

{requester.name[0]}

)}
Briven Logo

By claiming the {projectClaim?.project?.name}{' '} project from {requester?.name}, the following will happen:

Upon claiming, the project may undergo a short downtime (less than 10 minutes) for resizing.
{requester.scopes.length === 0 ? ( {requester?.name} hasn't requested any permissions to operate. This is normal and no action is needed from your side. ) : (

List of permissions that{' '} {requester.name} will have for the{' '} selected organization and all of its projects.

)}
) }