import { useParams } from 'common' import { ComponentProps } from 'react' import { toast } from 'sonner' import { AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Button, } from 'ui' import { AlertError } from '@/components/ui/AlertError' import { OAuthApproval } from '@/data/oauth-apps/oauth-apps-approvals-query' import { useOAuthAppRevokeMutation } from '@/data/oauth-apps/oauth-apps-revoke-mutation' import { getOAuthDatabaseTokenAccess } from '@/data/oauth-apps/types' export interface OAuthAppsRevokeDialogProps extends ComponentProps { approval?: OAuthApproval onClose: (revoked: boolean) => void } export const OAuthAppsRevokeDialogContent = ({ approval, onClose, onEscapeKeyDown, ...props }: OAuthAppsRevokeDialogProps) => { const { slug } = useParams() const { mutate: revokeApp, isPending, isError, error, reset, } = useOAuthAppRevokeMutation({ onSuccess: () => { toast.success(`Revoked access for ${approval?.attributes.app.name}`) onClose(true) }, onError: () => { // Do nothing, we just want to avoid the default toast. // Error is displayed in the AlertError below }, }) if (!approval) return null const hasDirectDatabaseAccess = !!getOAuthDatabaseTokenAccess( approval.attributes.org_grant?.approved_scopes ) return ( { onEscapeKeyDown?.(event) if (isPending) event.preventDefault() }} > Revoke access

“{approval.attributes.app.name}” will lose access for this organization and all its members on its next request.

{hasDirectDatabaseAccess && (

Database access will be revoked. New connections are blocked immediately, and existing connections will close shortly. The app’s database role and any objects it created are not deleted.

)}
{isError && }
) }