github.com/minio/console@v1.4.1/web-app/src/screens/Console/IDP/DeleteIDPConfigurationModal.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React, { Fragment, useState } from "react"; 18 import { ConfirmDeleteIcon } from "mds"; 19 import { 20 setErrorSnackMessage, 21 setServerNeedsRestart, 22 } from "../../../systemSlice"; 23 import { useAppDispatch } from "../../../store"; 24 import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog"; 25 import { api } from "api"; 26 import { SetIDPResponse } from "../../../api/consoleApi"; 27 import { errorToHandler } from "../../../api/errors"; 28 29 interface IDeleteIDPConfigurationModalProps { 30 closeDeleteModalAndRefresh: (refresh: boolean) => void; 31 deleteOpen: boolean; 32 idp: string; 33 idpType: string; 34 } 35 36 const DeleteIDPConfigurationModal = ({ 37 closeDeleteModalAndRefresh, 38 deleteOpen, 39 idp, 40 idpType, 41 }: IDeleteIDPConfigurationModalProps) => { 42 const dispatch = useAppDispatch(); 43 const onDelSuccess = (res: SetIDPResponse) => { 44 closeDeleteModalAndRefresh(true); 45 dispatch(setServerNeedsRestart(res.restart === true)); 46 }; 47 48 const onClose = () => closeDeleteModalAndRefresh(false); 49 const [deleteLoading, setDeleteLoading] = useState<boolean>(false); 50 51 if (!idp) { 52 return null; 53 } 54 55 const onConfirmDelete = () => { 56 setDeleteLoading(true); 57 api.idp 58 .deleteConfiguration(idp, idpType) 59 .then((res) => { 60 onDelSuccess(res.data); 61 }) 62 .catch((err) => dispatch(setErrorSnackMessage(errorToHandler(err.error)))) 63 .finally(() => setDeleteLoading(false)); 64 }; 65 66 const displayName = idp === "_" ? "Default" : idp; 67 68 return ( 69 <ConfirmDialog 70 title={`Delete ${displayName}`} 71 confirmText={"Delete"} 72 isOpen={deleteOpen} 73 titleIcon={<ConfirmDeleteIcon />} 74 isLoading={deleteLoading} 75 onConfirm={onConfirmDelete} 76 onClose={onClose} 77 confirmButtonProps={{ 78 disabled: deleteLoading, 79 }} 80 confirmationContent={ 81 <Fragment> 82 Are you sure you want to delete IDP <b>{displayName}</b>{" "} 83 configuration? <br /> 84 </Fragment> 85 } 86 /> 87 ); 88 }; 89 90 export default DeleteIDPConfigurationModal;