DeleteAppModal.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { useParams } from 'common'
  2. import { Lock } from 'lucide-react'
  3. import { toast } from 'sonner'
  4. import { Modal } from 'ui'
  5. import { Admonition } from 'ui-patterns'
  6. import { useOAuthAppDeleteMutation } from '@/data/oauth/oauth-app-delete-mutation'
  7. import type { OAuthApp } from '@/data/oauth/oauth-apps-query'
  8. export interface DeleteAppModalProps {
  9. selectedApp?: OAuthApp
  10. onClose: () => void
  11. }
  12. export const DeleteAppModal = ({ selectedApp, onClose }: DeleteAppModalProps) => {
  13. const { slug } = useParams()
  14. const { mutate: deleteOAuthApp, isPending: isDeleting } = useOAuthAppDeleteMutation({
  15. onSuccess: () => {
  16. toast.success(`Successfully deleted the app "${selectedApp?.name}"`)
  17. onClose()
  18. },
  19. })
  20. const onConfirmDelete = async () => {
  21. if (!slug) return console.error('Slug is required')
  22. if (!selectedApp?.id) return console.error('App ID is required')
  23. deleteOAuthApp({ slug, id: selectedApp?.id })
  24. }
  25. return (
  26. <Modal
  27. size="medium"
  28. alignFooter="right"
  29. header={`Confirm to delete ${selectedApp?.name}`}
  30. visible={selectedApp !== undefined}
  31. loading={isDeleting}
  32. onCancel={onClose}
  33. onConfirm={onConfirmDelete}
  34. >
  35. <Modal.Content>
  36. <Admonition
  37. type="warning"
  38. title="This action cannot be undone"
  39. description={`Deleting ${selectedApp?.name} will invalidate any access tokens from this application that
  40. were authorized by users.`}
  41. />
  42. </Modal.Content>
  43. <Modal.Content>
  44. <ul className="space-y-5">
  45. <li className="flex gap-3 text-sm">
  46. <Lock size={14} className="shrink-0" />
  47. <div>
  48. <strong>Before you remove this application, consider:</strong>
  49. <ul className="space-y-2 mt-2">
  50. <li className="list-disc ml-4">
  51. No users are currently using this application. It will no longer be available for
  52. use after deletion.
  53. </li>
  54. </ul>
  55. </div>
  56. </li>
  57. </ul>
  58. </Modal.Content>
  59. </Modal>
  60. )
  61. }