github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/ListBuckets/DeleteBucket.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 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 } from "react"; 18 import { ConfirmDeleteIcon } from "mds"; 19 import { ErrorResponseHandler } from "../../../../common/types"; 20 import { setErrorSnackMessage } from "../../../../systemSlice"; 21 import { useAppDispatch } from "../../../../store"; 22 import useApi from "../../Common/Hooks/useApi"; 23 import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog"; 24 25 interface IDeleteBucketProps { 26 closeDeleteModalAndRefresh: (refresh: boolean) => void; 27 deleteOpen: boolean; 28 selectedBucket: string; 29 } 30 31 const DeleteBucket = ({ 32 closeDeleteModalAndRefresh, 33 deleteOpen, 34 selectedBucket, 35 }: IDeleteBucketProps) => { 36 const dispatch = useAppDispatch(); 37 const onDelSuccess = () => closeDeleteModalAndRefresh(true); 38 const onDelError = (err: ErrorResponseHandler) => 39 dispatch(setErrorSnackMessage(err)); 40 const onClose = () => closeDeleteModalAndRefresh(false); 41 42 const [deleteLoading, invokeDeleteApi] = useApi(onDelSuccess, onDelError); 43 44 if (!selectedBucket) { 45 return null; 46 } 47 48 const onConfirmDelete = () => { 49 invokeDeleteApi("DELETE", `/api/v1/buckets/${selectedBucket}`, { 50 name: selectedBucket, 51 }); 52 }; 53 54 return ( 55 <ConfirmDialog 56 title={`Delete Bucket`} 57 confirmText={"Delete"} 58 isOpen={deleteOpen} 59 titleIcon={<ConfirmDeleteIcon />} 60 isLoading={deleteLoading} 61 onConfirm={onConfirmDelete} 62 onClose={onClose} 63 confirmationContent={ 64 <Fragment> 65 Are you sure you want to delete bucket <b>{selectedBucket}</b>? <br /> 66 A bucket can only be deleted if it's empty. 67 </Fragment> 68 } 69 /> 70 ); 71 }; 72 73 export default DeleteBucket;