2022-04-04 17:35:44 +05:30
|
|
|
import { ExclamationCircleOutlined } from '@ant-design/icons';
|
|
|
|
|
import { Modal } from 'antd';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
|
|
|
|
import { useDeleteDashboard } from 'hooks/dashboard/useDeleteDashboard';
|
2023-08-08 14:09:32 +03:00
|
|
|
import { useCallback } from 'react';
|
2023-10-08 23:21:17 +05:30
|
|
|
import { useQueryClient } from 'react-query';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
import { Data } from '../index';
|
2022-03-29 12:24:03 +05:30
|
|
|
import { TableLinkText } from './styles';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
function DeleteButton({ id }: Data): JSX.Element {
|
2023-08-08 14:09:32 +03:00
|
|
|
const [modal, contextHolder] = Modal.useModal();
|
|
|
|
|
|
2023-10-08 23:21:17 +05:30
|
|
|
const queryClient = useQueryClient();
|
|
|
|
|
|
|
|
|
|
const deleteDashboardMutation = useDeleteDashboard(id);
|
|
|
|
|
|
2023-08-08 14:09:32 +03:00
|
|
|
const openConfirmationDialog = useCallback((): void => {
|
|
|
|
|
modal.confirm({
|
2022-04-04 17:35:44 +05:30
|
|
|
title: 'Do you really want to delete this dashboard?',
|
|
|
|
|
icon: <ExclamationCircleOutlined style={{ color: '#e42b35' }} />,
|
|
|
|
|
onOk() {
|
2023-10-08 23:21:17 +05:30
|
|
|
deleteDashboardMutation.mutateAsync(undefined, {
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
queryClient.invalidateQueries([REACT_QUERY_KEY.GET_ALL_DASHBOARDS]);
|
|
|
|
|
},
|
2022-04-04 17:35:44 +05:30
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
okText: 'Delete',
|
|
|
|
|
okButtonProps: { danger: true },
|
|
|
|
|
centered: true,
|
2021-09-23 15:43:43 +05:30
|
|
|
});
|
2023-10-08 23:21:17 +05:30
|
|
|
}, [modal, deleteDashboardMutation, queryClient]);
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2022-04-04 17:35:44 +05:30
|
|
|
return (
|
2023-08-08 14:09:32 +03:00
|
|
|
<>
|
|
|
|
|
<TableLinkText type="danger" onClick={openConfirmationDialog}>
|
|
|
|
|
Delete
|
|
|
|
|
</TableLinkText>
|
|
|
|
|
|
|
|
|
|
{contextHolder}
|
|
|
|
|
</>
|
2022-04-04 17:35:44 +05:30
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
// This is to avoid the type collision
|
2022-03-22 12:10:31 +05:30
|
|
|
function Wrapper(props: Data): JSX.Element {
|
2023-10-08 23:21:17 +05:30
|
|
|
const { createdBy, description, id, key, lastUpdatedTime, name, tags } = props;
|
2022-03-24 12:06:57 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
return (
|
2023-10-08 23:21:17 +05:30
|
|
|
<DeleteButton
|
2021-09-23 15:43:43 +05:30
|
|
|
{...{
|
2022-03-24 12:06:57 +05:30
|
|
|
createdBy,
|
|
|
|
|
description,
|
|
|
|
|
id,
|
|
|
|
|
key,
|
|
|
|
|
lastUpdatedTime,
|
|
|
|
|
name,
|
|
|
|
|
tags,
|
2021-09-23 15:43:43 +05:30
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
export default Wrapper;
|