diff --git a/catalog-rest-service/src/main/resources/ui/src/components/Modals/ConfirmationModal/ConfirmationModal.tsx b/catalog-rest-service/src/main/resources/ui/src/components/Modals/ConfirmationModal/ConfirmationModal.tsx new file mode 100644 index 00000000000..65523b75257 --- /dev/null +++ b/catalog-rest-service/src/main/resources/ui/src/components/Modals/ConfirmationModal/ConfirmationModal.tsx @@ -0,0 +1,70 @@ +import classNames from 'classnames'; +import React from 'react'; +import { Button } from '../../buttons/Button/Button'; +type Props = { + cancelText: string; + confirmText: string; + bodyText: string; + header: string; + headerClassName?: string; + bodyClassName?: string; + footerClassName?: string; + confirmButtonCss?: string; + cancelButtonCss?: string; + onConfirm: () => void; + onCancel: () => void; +}; +const ConfirmationModal = ({ + cancelText, + confirmText, + header, + headerClassName = '', + bodyClassName = '', + footerClassName = '', + confirmButtonCss = '', + cancelButtonCss = '', + onConfirm, + onCancel, + bodyText, +}: Props) => { + return ( + +
+
+
+

{header}

+
+
+

{bodyText}

+
+
+ + +
+
+
+ ); +}; + +export default ConfirmationModal; diff --git a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx index 30aaf4db589..458ef92cbcb 100644 --- a/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx +++ b/catalog-rest-service/src/main/resources/ui/src/pages/services/index.tsx @@ -16,6 +16,7 @@ */ import { AxiosError, AxiosResponse } from 'axios'; +import classNames from 'classnames'; import { isNull, lowerCase } from 'lodash'; import { ServiceCollection, ServiceData, ServiceTypes } from 'Models'; import React, { useEffect, useState } from 'react'; @@ -39,6 +40,7 @@ import { EditObj, ServiceDataObj, } from '../../components/Modals/AddServiceModal/AddServiceModal'; +import ConfirmationModal from '../../components/Modals/ConfirmationModal/ConfirmationModal'; import { getServiceDetailsPath, TITLE_FOR_NON_ADMIN_ACTION, @@ -56,6 +58,7 @@ import { import { DatabaseService } from '../../generated/entity/services/databaseService'; import { MessagingService } from '../../generated/entity/services/messagingService'; import { PipelineService } from '../../generated/entity/services/pipelineService'; +import { useAuth } from '../../hooks/authHooks'; import useToastContext from '../../hooks/useToastContext'; import { getCountBadge, getTabClasses } from '../../utils/CommonUtils'; import { getFrequencyTime, serviceTypeLogo } from '../../utils/ServiceUtils'; @@ -80,7 +83,13 @@ export type ApiData = { const ServicesPage = () => { const showToast = useToastContext(); + const { isAdminUser, isAuthDisabled } = useAuth(); const [isModalOpen, setIsModalOpen] = useState(false); + const [isConfirmationModalOpen, setIsConfirmationModalOpen] = useState(false); + const [deleteSelection, setDeleteSelection] = useState({ + id: '', + name: '', + }); const [serviceName, setServiceName] = useState('databaseServices'); const [services, setServices] = useState({ @@ -238,6 +247,14 @@ const ServicesPage = () => { }); }; + const handleCancelConfirmationModal = () => { + setIsConfirmationModalOpen(false); + setDeleteSelection({ + id: '', + name: '', + }); + }; + const handleDelete = (id: string) => { deleteService(serviceName, id).then((res: AxiosResponse) => { if (res.statusText === 'OK') { @@ -250,6 +267,16 @@ const ServicesPage = () => { setServiceList(updatedServiceList); } }); + + handleCancelConfirmationModal(); + }; + + const ConfirmDelete = (id: string, name: string) => { + setDeleteSelection({ + id, + name, + }); + setIsConfirmationModalOpen(true); }; const getServiceLogo = (serviceType: string): JSX.Element | null => { @@ -411,7 +438,9 @@ const ServicesPage = () => { position="bottom" title={TITLE_FOR_NON_ADMIN_ACTION}>