import type { PostgresRole } from '@supabase/postgres-meta' import { toast } from 'sonner' import { useDatabaseRoleDeleteMutation } from 'data/database-roles/database-role-delete-mutation' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' import { Modal } from 'ui' interface DeleteRoleModalProps { role: PostgresRole visible: boolean onClose: () => void onDelete?: () => void } export const DeleteRoleModal = ({ role, visible, onClose, onDelete }: DeleteRoleModalProps) => { const { data: project } = useSelectedProjectQuery() const { mutate: deleteDatabaseRole, isPending: isDeleting } = useDatabaseRoleDeleteMutation({ onSuccess: () => { toast.success(`Successfully deleted role: ${role.name}`) onClose() }, }) const deleteRole = async () => { if (!project) return console.error('Project is required') if (!role) return console.error('Failed to delete role: role is missing') onDelete?.() deleteDatabaseRole({ projectRef: project.ref, connectionString: project.connectionString, id: role.id, }) } return ( Confirm to delete role "{role?.name}"} loading={isDeleting} >

This will automatically revoke any membership of this role in other roles, and this action cannot be undone.

) }