github.com/minio/console@v1.4.1/web-app/src/screens/Console/Users/DeleteMultipleServiceAccounts.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 ConfirmDialog from "../../../screens/Console/Common/ModalWrapper/ConfirmDialog"; 20 import { setErrorSnackMessage } from "../../../systemSlice"; 21 import { useAppDispatch } from "../../../store"; 22 import { api } from "api"; 23 import { ApiError, HttpResponse } from "api/consoleApi"; 24 import { errorToHandler } from "api/errors"; 25 26 interface IDeleteMultiSAsProps { 27 closeDeleteModalAndRefresh: (refresh: boolean) => void; 28 deleteOpen: boolean; 29 selectedSAs: string[]; 30 } 31 32 const DeleteMultipleSAs = ({ 33 closeDeleteModalAndRefresh, 34 deleteOpen, 35 selectedSAs, 36 }: IDeleteMultiSAsProps) => { 37 const dispatch = useAppDispatch(); 38 const onClose = () => closeDeleteModalAndRefresh(false); 39 const [loadingDelete, setLoadingDelete] = useState<boolean>(false); 40 41 if (!selectedSAs) { 42 return null; 43 } 44 const onConfirmDelete = () => { 45 setLoadingDelete(true); 46 api.serviceAccounts 47 .deleteMultipleServiceAccounts(selectedSAs) 48 .then((_) => { 49 closeDeleteModalAndRefresh(true); 50 }) 51 .catch(async (res: HttpResponse<void, ApiError>) => { 52 const err = (await res.json()) as ApiError; 53 dispatch(setErrorSnackMessage(errorToHandler(err))); 54 closeDeleteModalAndRefresh(false); 55 }) 56 .finally(() => setLoadingDelete(false)); 57 }; 58 return ( 59 <ConfirmDialog 60 title={`Delete Access Keys`} 61 confirmText={"Delete"} 62 isOpen={deleteOpen} 63 titleIcon={<ConfirmDeleteIcon />} 64 isLoading={loadingDelete} 65 onConfirm={onConfirmDelete} 66 onClose={onClose} 67 confirmationContent={ 68 <Fragment> 69 Are you sure you want to delete the selected {selectedSAs.length}{" "} 70 Access Keys?{" "} 71 </Fragment> 72 } 73 /> 74 ); 75 }; 76 77 export default DeleteMultipleSAs;