mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* Reinstate copy action for TextConfirmModal for staff only * Clean --------- Co-authored-by: Ali Waseem <waseema393@gmail.com>
96 lines
3.1 KiB
TypeScript
96 lines
3.1 KiB
TypeScript
import { parseAsString, useQueryState } from 'nuqs'
|
|
import { toast } from 'sonner'
|
|
|
|
import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper'
|
|
import { useDatabaseCronJobDeleteMutation } from 'data/database-cron-jobs/database-cron-jobs-delete-mutation'
|
|
import { CronJob } from 'data/database-cron-jobs/database-cron-jobs-infinite-query'
|
|
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
|
|
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
|
|
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
|
|
import { cleanPointerEventsNoneOnBody } from 'lib/helpers'
|
|
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
interface DeleteCronJobProps {
|
|
cronJob: CronJob
|
|
visible: boolean
|
|
onClose: () => void
|
|
onDeleteStart?: (jobId: string) => void
|
|
}
|
|
|
|
export const DeleteCronJob = ({ cronJob, visible, onClose, onDeleteStart }: DeleteCronJobProps) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: org } = useSelectedOrganizationQuery()
|
|
const [searchQuery] = useQueryState('search', parseAsString.withDefault(''))
|
|
|
|
const { mutate: sendEvent } = useSendEventMutation()
|
|
const { mutate: deleteDatabaseCronJob, isPending } = useDatabaseCronJobDeleteMutation({
|
|
onSuccess: () => {
|
|
sendEvent({
|
|
action: 'cron_job_deleted',
|
|
groups: { project: project?.ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
|
|
})
|
|
toast.success(`Successfully removed cron job ${cronJob.jobname}`)
|
|
onClose()
|
|
},
|
|
})
|
|
|
|
async function handleDelete() {
|
|
if (!project) return console.error('Project is required')
|
|
|
|
onDeleteStart?.(cronJob.jobid.toString())
|
|
deleteDatabaseCronJob({
|
|
jobId: cronJob.jobid,
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
searchTerm: searchQuery,
|
|
})
|
|
}
|
|
|
|
if (!cronJob) {
|
|
return null
|
|
}
|
|
|
|
// Cron job name is optional. If the cron job has no name, show a simplified modal which doesn't require the user to input the name.
|
|
if (!cronJob.jobname) {
|
|
return (
|
|
<ConfirmationModal
|
|
variant="destructive"
|
|
visible={visible}
|
|
onCancel={() => {
|
|
onClose()
|
|
cleanPointerEventsNoneOnBody()
|
|
}}
|
|
onConfirm={handleDelete}
|
|
title={`Delete the cron job`}
|
|
loading={isPending}
|
|
confirmLabel={`Delete`}
|
|
alert={{ title: 'You cannot recover this cron job once deleted.' }}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<TextConfirmModal
|
|
variant="destructive"
|
|
visible={visible}
|
|
onConfirm={handleDelete}
|
|
onCancel={() => {
|
|
onClose()
|
|
cleanPointerEventsNoneOnBody()
|
|
}}
|
|
title="Delete this cron job"
|
|
loading={isPending}
|
|
confirmLabel={`Delete cron job ${cronJob.jobname}`}
|
|
confirmPlaceholder="Type in name of cron job"
|
|
confirmString={cronJob.jobname ?? 'Unknown'}
|
|
text={
|
|
<>
|
|
<span>This will delete the cron job</span>{' '}
|
|
<span className="text-bold text-foreground">{cronJob.jobname}</span>
|
|
</>
|
|
}
|
|
alert={{ title: 'You cannot recover this cron job once deleted.' }}
|
|
/>
|
|
)
|
|
}
|