github.com/minio/console@v1.4.1/web-app/src/screens/Console/EventDestinations/CustomForms/ResetConfigurationModal.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, useEffect, useState } from "react"; 18 import { api } from "api"; 19 import { errorToHandler } from "api/errors"; 20 import ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog"; 21 22 import { ConfirmDeleteIcon, ProgressBar } from "mds"; 23 import { setErrorSnackMessage } from "../../../../systemSlice"; 24 import { useAppDispatch } from "../../../../store"; 25 26 interface IResetConfiguration { 27 configurationName: string; 28 closeResetModalAndRefresh: (reloadConfiguration: boolean) => void; 29 resetOpen: boolean; 30 } 31 32 const ResetConfigurationModal = ({ 33 configurationName, 34 closeResetModalAndRefresh, 35 resetOpen, 36 }: IResetConfiguration) => { 37 const dispatch = useAppDispatch(); 38 const [resetLoading, setResetLoading] = useState<boolean>(false); 39 40 useEffect(() => { 41 if (resetLoading) { 42 api.configs 43 .resetConfig(configurationName) 44 .then(() => { 45 setResetLoading(false); 46 closeResetModalAndRefresh(true); 47 }) 48 .catch((err) => { 49 setResetLoading(false); 50 dispatch(setErrorSnackMessage(errorToHandler(err.error))); 51 }); 52 } 53 }, [closeResetModalAndRefresh, configurationName, resetLoading, dispatch]); 54 55 const resetConfiguration = () => { 56 setResetLoading(true); 57 }; 58 59 return ( 60 <ConfirmDialog 61 title={`Restore Defaults`} 62 confirmText={"Yes, Reset Configuration"} 63 isOpen={resetOpen} 64 titleIcon={<ConfirmDeleteIcon />} 65 isLoading={resetLoading} 66 onConfirm={resetConfiguration} 67 onClose={() => { 68 closeResetModalAndRefresh(false); 69 }} 70 confirmationContent={ 71 <Fragment> 72 {resetLoading && <ProgressBar />} 73 <Fragment> 74 Are you sure you want to restore these configurations to default 75 values? 76 <br /> 77 <b 78 style={{ 79 maxWidth: "200px", 80 whiteSpace: "normal", 81 wordWrap: "break-word", 82 }} 83 > 84 Please note that this may cause your system to not be accessible 85 </b> 86 </Fragment> 87 </Fragment> 88 } 89 /> 90 ); 91 }; 92 93 export default ResetConfigurationModal;