PurgeQueue.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { toast } from 'sonner'
  2. import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
  3. import { useDatabaseQueuePurgeMutation } from '@/data/database-queues/database-queues-purge-mutation'
  4. import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
  5. interface PurgeQueueProps {
  6. queueName: string
  7. visible: boolean
  8. onClose: () => void
  9. }
  10. export const PurgeQueue = ({ queueName, visible, onClose }: PurgeQueueProps) => {
  11. const { data: project } = useSelectedProjectQuery()
  12. const { mutate: purgeDatabaseQueue, isPending } = useDatabaseQueuePurgeMutation({
  13. onSuccess: () => {
  14. toast.success(`Successfully purged queue ${queueName}`)
  15. onClose()
  16. },
  17. })
  18. async function handlePurge() {
  19. if (!project) return console.error('Project is required')
  20. purgeDatabaseQueue({
  21. queueName: queueName,
  22. projectRef: project.ref,
  23. connectionString: project.connectionString,
  24. })
  25. }
  26. if (!queueName) {
  27. return null
  28. }
  29. return (
  30. <TextConfirmModal
  31. variant="warning"
  32. visible={visible}
  33. onCancel={() => onClose()}
  34. onConfirm={handlePurge}
  35. title="Purge this queue"
  36. loading={isPending}
  37. confirmLabel={`Purge queue ${queueName}`}
  38. confirmPlaceholder="Type in name of queue"
  39. confirmString={queueName ?? 'Unknown'}
  40. text={
  41. <>
  42. <span>This will purge the queue</span>{' '}
  43. <span className="text-bold text-foreground">{queueName}</span>
  44. </>
  45. }
  46. alert={{
  47. title:
  48. "This action will delete all messages from the queue. They can't be recovered afterwards.",
  49. }}
  50. />
  51. )
  52. }