mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
## Context Related to FE-2461 More refactoring to clean up usage of `useQueryStateWithSelect`, in the following pages - Auth OAuth Apps - Cron Jobs - Vaults Secrets Management - Database Hooks - Wrappers ## To test In each of those pages, verify that - [ ] Clicking the "new" cta updates the URL params, and refreshing should re-open the sheet - [ ] Editing an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param - [ ] Deleting an existing item should update URL params, and refreshing should re-open the sheet with the right item - Verify that if the URL param has the wrong id, page should not open the sheet, show a toast, and reset the URL param <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Added "item not found" toasts and clearer feedback after create/update/delete actions; prevent opening create flows when server features are disabled. * **Style** * Standardized button labels, sizes and modal/dialog spacing; refined table column widths and inline code formatting for readability. * **Refactor** * Simplified UI state flows across OAuth Apps, Hooks/Webhooks, Cron Jobs, Vault Secrets, and Wrappers to use consistent URL-driven interactions and centralized modals. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
110 lines
3.6 KiB
TypeScript
110 lines
3.6 KiB
TypeScript
import { TextConfirmModal } from 'components/ui/TextConfirmModalWrapper'
|
|
import { useDatabaseCronJobDeleteMutation } from 'data/database-cron-jobs/database-cron-jobs-delete-mutation'
|
|
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 { parseAsString, useQueryState } from 'nuqs'
|
|
import { useEffect } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
|
|
import { useCronJobsData } from './CronJobsTab.useCronJobsData'
|
|
|
|
export const DeleteCronJob = () => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const { data: org } = useSelectedOrganizationQuery()
|
|
|
|
const [searchQuery] = useQueryState('search', parseAsString.withDefault(''))
|
|
const [cronJobIdForDeletion, setCronJobForDeletion] = useQueryState('delete', parseAsString)
|
|
|
|
const { grid } = useCronJobsData({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
searchQuery,
|
|
})
|
|
const cronJob = grid.rows.find((j) => j.jobid.toString() === cronJobIdForDeletion)
|
|
|
|
const { mutate: sendEvent } = useSendEventMutation()
|
|
const {
|
|
mutate: deleteDatabaseCronJob,
|
|
isPending,
|
|
isSuccess: isSuccessDelete,
|
|
} = useDatabaseCronJobDeleteMutation({
|
|
onSuccess: () => {
|
|
sendEvent({
|
|
action: 'cron_job_removed',
|
|
groups: { project: project?.ref ?? 'Unknown', organization: org?.slug ?? 'Unknown' },
|
|
})
|
|
toast.success(`Successfully removed cron job`)
|
|
setCronJobForDeletion(null)
|
|
},
|
|
})
|
|
|
|
async function handleDelete() {
|
|
if (!project) return console.error('Project is required')
|
|
if (!cronJob) return console.error('Cron job is missing')
|
|
|
|
deleteDatabaseCronJob({
|
|
jobId: cronJob.jobid,
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
searchTerm: searchQuery,
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (grid.isSuccess && !!cronJobIdForDeletion && !cronJob && !isSuccessDelete) {
|
|
toast('Cron job not found')
|
|
setCronJobForDeletion(null)
|
|
}
|
|
}, [cronJob, cronJobIdForDeletion, grid.isSuccess, isSuccessDelete, setCronJobForDeletion])
|
|
|
|
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={!!cronJob}
|
|
onCancel={() => {
|
|
setCronJobForDeletion(null)
|
|
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={!!cronJob}
|
|
onConfirm={handleDelete}
|
|
onCancel={() => {
|
|
setCronJobForDeletion(null)
|
|
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.' }}
|
|
/>
|
|
)
|
|
}
|