DeleteCustomProviderModal.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type { CustomOAuthProvider } from '@supabase/auth-js'
  2. import { useParams } from 'common'
  3. import { toast } from 'sonner'
  4. import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
  5. import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
  6. import { useOAuthCustomProviderDeleteMutation } from '@/data/oauth-custom-providers/oauth-custom-provider-delete-mutation'
  7. interface DeleteCustomProviderModalProps {
  8. visible: boolean
  9. selectedProvider?: CustomOAuthProvider
  10. onClose: () => void
  11. }
  12. export const DeleteCustomProviderModal = ({
  13. visible,
  14. selectedProvider,
  15. onClose,
  16. }: DeleteCustomProviderModalProps) => {
  17. const { ref: projectRef } = useParams()
  18. const { hostEndpoint: clientEndpoint } = useProjectApiUrl({ projectRef })
  19. const { mutate, isPending } = useOAuthCustomProviderDeleteMutation({
  20. onSuccess: () => {
  21. toast.success('Custom provider deleted successfully')
  22. onClose()
  23. },
  24. })
  25. const onConfirmDelete = () => {
  26. mutate({
  27. identifier: selectedProvider?.identifier,
  28. projectRef,
  29. clientEndpoint,
  30. })
  31. }
  32. return (
  33. <ConfirmationModal
  34. variant="destructive"
  35. size="medium"
  36. loading={isPending}
  37. visible={visible}
  38. title={
  39. <>
  40. Confirm to delete custom provider{' '}
  41. <code className="text-sm">{selectedProvider?.name}</code>
  42. </>
  43. }
  44. confirmLabel="Confirm delete"
  45. confirmLabelLoading="Deleting..."
  46. onCancel={() => onClose()}
  47. onConfirm={() => onConfirmDelete()}
  48. alert={{
  49. title: 'This action cannot be undone',
  50. description:
  51. 'You will need to re-create the custom provider if you want to revert the deletion.',
  52. }}
  53. >
  54. <p className="text-sm">Before deleting this custom provider, consider:</p>
  55. <ul className="space-y-2 mt-2 text-sm text-foreground-light">
  56. <li className="list-disc ml-6">
  57. Any users authenticating with this provider will lose access
  58. </li>
  59. <li className="list-disc ml-6">This provider is no longer in use by any applications</li>
  60. </ul>
  61. </ConfirmationModal>
  62. )
  63. }