DeleteQueue.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { useRouter } from 'next/router'
  2. import { toast } from 'sonner'
  3. import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
  4. import { useDatabaseQueueDeleteMutation } from '@/data/database-queues/database-queues-delete-mutation'
  5. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  6. interface DeleteQueueProps {
  7. queueName: string
  8. visible: boolean
  9. onClose: () => void
  10. }
  11. export const DeleteQueue = ({ queueName, visible, onClose }: DeleteQueueProps) => {
  12. const router = useRouter()
  13. const { data: project } = useSelectedProjectQuery()
  14. const { mutate: deleteDatabaseQueue, isPending } = useDatabaseQueueDeleteMutation({
  15. onSuccess: () => {
  16. toast.success(`Successfully removed queue ${queueName}`)
  17. router.push(`/project/${project?.ref}/integrations/queues/queues`)
  18. onClose()
  19. },
  20. })
  21. async function handleDelete() {
  22. if (!project) return console.error('Project is required')
  23. deleteDatabaseQueue({
  24. queueName: queueName,
  25. projectRef: project.ref,
  26. connectionString: project.connectionString,
  27. })
  28. }
  29. if (!queueName) {
  30. return null
  31. }
  32. return (
  33. <TextConfirmModal
  34. variant="destructive"
  35. visible={visible}
  36. onCancel={() => onClose()}
  37. onConfirm={handleDelete}
  38. title="Delete this queue"
  39. loading={isPending}
  40. confirmLabel={`Delete queue ${queueName}`}
  41. confirmPlaceholder="Type in name of queue"
  42. confirmString={queueName ?? 'Unknown'}
  43. text={
  44. <>
  45. <span>This will delete the queue</span>{' '}
  46. <span className="text-bold text-foreground">{queueName}</span>
  47. </>
  48. }
  49. alert={{ title: 'You cannot recover this queue and its messages once deleted.' }}
  50. />
  51. )
  52. }