github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/BucketDetails/DeleteAccessRule.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, useState } from "react"; 18 import { ConfirmDeleteIcon } from "mds"; 19 import { setErrorSnackMessage } from "../../../../systemSlice"; 20 import { useAppDispatch } from "../../../../store"; 21 import { api } from "api"; 22 import { ApiError, HttpResponse, PrefixWrapper } from "api/consoleApi"; 23 import { errorToHandler } from "api/errors"; 24 import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog"; 25 26 interface IDeleteAccessRule { 27 modalOpen: boolean; 28 onClose: () => any; 29 bucket: string; 30 toDelete: string; 31 } 32 33 const DeleteAccessRule = ({ 34 onClose, 35 modalOpen, 36 bucket, 37 toDelete, 38 }: IDeleteAccessRule) => { 39 const dispatch = useAppDispatch(); 40 41 const [loadingDeleteAccessRule, setLoadingDeleteAccessRule] = 42 useState<boolean>(false); 43 44 const onConfirmDelete = () => { 45 setLoadingDeleteAccessRule(true); 46 let wrapper: PrefixWrapper = { prefix: toDelete }; 47 api.bucket 48 .deleteAccessRuleWithBucket(bucket, wrapper) 49 .then(() => { 50 onClose(); 51 }) 52 .catch((res: HttpResponse<boolean, ApiError>) => { 53 dispatch(setErrorSnackMessage(errorToHandler(res.error))); 54 onClose(); 55 }) 56 .finally(() => setLoadingDeleteAccessRule(false)); 57 }; 58 59 return ( 60 <ConfirmDialog 61 title={`Delete Anonymous Access Rule`} 62 confirmText={"Delete"} 63 isOpen={modalOpen} 64 isLoading={loadingDeleteAccessRule} 65 onConfirm={onConfirmDelete} 66 titleIcon={<ConfirmDeleteIcon />} 67 onClose={onClose} 68 confirmationContent={ 69 <Fragment>Are you sure you want to delete this access rule?</Fragment> 70 } 71 /> 72 ); 73 }; 74 75 export default DeleteAccessRule;