mirror of
https://github.com/supabase/supabase.git
synced 2026-06-14 23:25:16 +08:00
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { toast } from 'sonner'
|
|
|
|
import { TextConfirmModal } from '@/components/ui/TextConfirmModalWrapper'
|
|
import { useDatabaseQueuePurgeMutation } from '@/data/database-queues/database-queues-purge-mutation'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
interface PurgeQueueProps {
|
|
queueName: string
|
|
visible: boolean
|
|
onClose: () => void
|
|
}
|
|
|
|
export const PurgeQueue = ({ queueName, visible, onClose }: PurgeQueueProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const { mutate: purgeDatabaseQueue, isPending } = useDatabaseQueuePurgeMutation({
|
|
onSuccess: () => {
|
|
toast.success(`Successfully purged queue ${queueName}`)
|
|
onClose()
|
|
},
|
|
})
|
|
|
|
async function handlePurge() {
|
|
if (!project) return console.error('Project is required')
|
|
|
|
purgeDatabaseQueue({
|
|
queueName: queueName,
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
})
|
|
}
|
|
|
|
if (!queueName) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<TextConfirmModal
|
|
variant="warning"
|
|
visible={visible}
|
|
onCancel={() => onClose()}
|
|
onConfirm={handlePurge}
|
|
title="Purge this queue"
|
|
loading={isPending}
|
|
confirmLabel={`Purge queue ${queueName}`}
|
|
confirmPlaceholder="Type in name of queue"
|
|
confirmString={queueName ?? 'Unknown'}
|
|
text={
|
|
<>
|
|
<span>This will purge the queue</span>{' '}
|
|
<span className="text-bold text-foreground">{queueName}</span>
|
|
</>
|
|
}
|
|
alert={{
|
|
title:
|
|
"This action will delete all messages from the queue. They can't be recovered afterwards.",
|
|
}}
|
|
/>
|
|
)
|
|
}
|