DeleteFactorModal.tsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { useQueryClient } from '@tanstack/react-query'
  2. import { LOCAL_STORAGE_KEYS } from 'common'
  3. import { toast } from 'sonner'
  4. import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
  5. import { organizationKeys } from '@/data/organizations/keys'
  6. import { useMfaUnenrollMutation } from '@/data/profile/mfa-unenroll-mutation'
  7. import { useLocalStorageQuery } from '@/hooks/misc/useLocalStorage'
  8. interface DeleteFactorModalProps {
  9. visible: boolean
  10. factorId: string | null
  11. lastFactorToBeDeleted: boolean
  12. onClose: () => void
  13. }
  14. const DeleteFactorModal = ({
  15. visible,
  16. factorId,
  17. lastFactorToBeDeleted,
  18. onClose,
  19. }: DeleteFactorModalProps) => {
  20. const queryClient = useQueryClient()
  21. const [lastVisitedOrganization] = useLocalStorageQuery(
  22. LOCAL_STORAGE_KEYS.LAST_VISITED_ORGANIZATION,
  23. ''
  24. )
  25. const { mutate: unenroll, isPending } = useMfaUnenrollMutation({
  26. onSuccess: async () => {
  27. if (lastVisitedOrganization) {
  28. await queryClient.invalidateQueries({
  29. queryKey: organizationKeys.members(lastVisitedOrganization),
  30. })
  31. }
  32. toast.success(`Successfully deleted factor`)
  33. onClose()
  34. },
  35. })
  36. return (
  37. <ConfirmationModal
  38. size="medium"
  39. visible={visible}
  40. variant={'destructive'}
  41. title="Confirm to delete factor"
  42. confirmLabel="Delete"
  43. confirmLabelLoading="Deleting"
  44. loading={isPending}
  45. onCancel={onClose}
  46. onConfirm={() => factorId && unenroll({ factorId })}
  47. alert={{
  48. title: lastFactorToBeDeleted
  49. ? 'Multi-factor authentication will be disabled'
  50. : 'This action cannot be undone',
  51. description: lastFactorToBeDeleted
  52. ? 'There are no other factors that are set up once you delete this factor, as such your account will no longer be guarded by multi-factor authentication'
  53. : 'You will no longer be able to use this authenticator app for multi-factor authentication when signing in to the dashboard',
  54. }}
  55. >
  56. <p className="text-sm">Before deleting this factor, consider:</p>
  57. <ul className="text-sm text-foreground-light py-1 list-disc mx-4 space-y-1">
  58. {lastFactorToBeDeleted ? (
  59. <>
  60. <li>Adding another authenticator app as a factor prior to deleting</li>
  61. <li>Ensure that your account does not need multi-factor authentication</li>
  62. <li>
  63. You will lose access to any organization that enforces multi-factor authentication
  64. </li>
  65. </>
  66. ) : (
  67. <>
  68. <li>Your backup authenticator app is still available to use</li>
  69. <li>Adding another authenticator app thereafter as a backup</li>
  70. </>
  71. )}
  72. </ul>
  73. </ConfirmationModal>
  74. )
  75. }
  76. export default DeleteFactorModal