github.com/minio/console@v1.4.1/web-app/src/screens/Console/Buckets/BucketDetails/DeleteBucketLifecycleRule.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, { useEffect, useState, Fragment } from "react"; 18 import { ConfirmDeleteIcon } from "mds"; 19 import { api } from "api"; 20 import { errorToHandler } from "api/errors"; 21 import { setErrorSnackMessage } from "../../../../systemSlice"; 22 import { useAppDispatch } from "../../../../store"; 23 import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog"; 24 25 interface IDeleteLifecycleRule { 26 deleteOpen: boolean; 27 onCloseAndRefresh: (refresh: boolean) => any; 28 bucket: string; 29 id: string; 30 } 31 32 const DeleteBucketLifecycleRule = ({ 33 onCloseAndRefresh, 34 deleteOpen, 35 bucket, 36 id, 37 }: IDeleteLifecycleRule) => { 38 const dispatch = useAppDispatch(); 39 const [deletingRule, setDeletingRule] = useState<boolean>(false); 40 41 useEffect(() => { 42 if (deletingRule) { 43 api.buckets 44 .deleteBucketLifecycleRule(bucket, id) 45 .then(() => { 46 setDeletingRule(false); 47 onCloseAndRefresh(true); 48 }) 49 .catch((err) => { 50 setDeletingRule(false); 51 dispatch(setErrorSnackMessage(errorToHandler(err.error))); 52 }); 53 } 54 }, [deletingRule, bucket, id, onCloseAndRefresh, dispatch]); 55 56 const onConfirmDelete = () => { 57 setDeletingRule(true); 58 }; 59 60 return ( 61 <ConfirmDialog 62 title={`Delete Lifecycle Rule`} 63 confirmText={"Delete"} 64 isOpen={deleteOpen} 65 isLoading={deletingRule} 66 onConfirm={onConfirmDelete} 67 titleIcon={<ConfirmDeleteIcon />} 68 onClose={() => onCloseAndRefresh(false)} 69 confirmationContent={ 70 <Fragment> 71 Are you sure you want to delete the <strong>{id}</strong> rule? 72 </Fragment> 73 } 74 /> 75 ); 76 }; 77 78 export default DeleteBucketLifecycleRule;