diff --git a/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx b/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx index 389518dc204..82ae09f6c11 100644 --- a/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx +++ b/public/app/features/dashboard/components/DeleteDashboard/DeleteDashboardModal.tsx @@ -4,12 +4,12 @@ import React from 'react'; import { connect, ConnectedProps } from 'react-redux'; import useAsyncFn from 'react-use/lib/useAsyncFn'; +import { locationService } from '@grafana/runtime'; import { Modal, ConfirmModal, Button } from '@grafana/ui'; import { config } from 'app/core/config'; import { DashboardModel, PanelModel } from 'app/features/dashboard/state'; import { cleanUpDashboardAndVariables } from 'app/features/dashboard/state/actions'; - -import { useDashboardDelete } from './useDashboardDelete'; +import { deleteDashboard } from 'app/features/manage-dashboards/state/actions'; type DeleteDashboardModalProps = { hideModal(): void; @@ -26,11 +26,12 @@ type Props = DeleteDashboardModalProps & ConnectedProps; const DeleteDashboardModalUnconnected = ({ hideModal, cleanUpDashboardAndVariables, dashboard }: Props) => { const isProvisioned = dashboard.meta.provisioned; - const { onDeleteDashboard } = useDashboardDelete(dashboard.uid, cleanUpDashboardAndVariables); const [, onConfirm] = useAsyncFn(async () => { - await onDeleteDashboard(); + await deleteDashboard(dashboard.uid, true); + cleanUpDashboardAndVariables(); hideModal(); + locationService.replace('/'); }, [hideModal]); const modalBody = getModalBody(dashboard.panels, dashboard.title); diff --git a/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx b/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx deleted file mode 100644 index 630ae39be28..00000000000 --- a/public/app/features/dashboard/components/DeleteDashboard/useDashboardDelete.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import { useEffect } from 'react'; -import { useAsyncFn } from 'react-use'; - -import { locationService } from '@grafana/runtime'; -import { useAppNotification } from 'app/core/copy/appNotification'; -import { deleteDashboard } from 'app/features/manage-dashboards/state/actions'; - -export const useDashboardDelete = (uid: string, cleanUpDashboardAndVariables: () => void) => { - const [state, onDeleteDashboard] = useAsyncFn(() => deleteDashboard(uid, false), []); - const notifyApp = useAppNotification(); - - useEffect(() => { - if (state.value) { - cleanUpDashboardAndVariables(); - locationService.replace('/'); - notifyApp.success('Dashboard Deleted', `${state.value.title} has been deleted`); - } - }, [state, notifyApp, cleanUpDashboardAndVariables]); - - return { state, onDeleteDashboard }; -};