github.com/minio/console@v1.4.1/web-app/src/screens/Console/EventDestinations/WebhookSettings/DeleteWebhookEndpoint.tsx (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2023 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 ConfirmDialog from "../../Common/ModalWrapper/ConfirmDialog";
    22  import {
    23    configurationIsLoading,
    24    setErrorSnackMessage,
    25    setServerNeedsRestart,
    26  } from "../../../../systemSlice";
    27  import { useAppDispatch } from "../../../../store";
    28  
    29  interface IDeleteWebhookEndpoint {
    30    modalOpen: boolean;
    31    onClose: () => void;
    32    selectedARN: string;
    33    type: string;
    34  }
    35  
    36  const DeleteWebhookEndpoint = ({
    37    modalOpen,
    38    onClose,
    39    selectedARN,
    40  }: IDeleteWebhookEndpoint) => {
    41    const [deleteLoading, setDeleteLoading] = useState<boolean>(false);
    42  
    43    const dispatch = useAppDispatch();
    44  
    45    useEffect(() => {
    46      if (deleteLoading) {
    47        api.configs
    48          .resetConfig(selectedARN)
    49          .then(() => {
    50            setDeleteLoading(false);
    51            dispatch(setServerNeedsRestart(true));
    52            dispatch(configurationIsLoading(true));
    53            onClose();
    54          })
    55          .catch((err) => {
    56            setDeleteLoading(false);
    57            dispatch(setErrorSnackMessage(errorToHandler(err.error)));
    58          });
    59      }
    60    }, [deleteLoading, dispatch, onClose, selectedARN]);
    61  
    62    const onConfirmDelete = () => {
    63      setDeleteLoading(true);
    64    };
    65  
    66    const defaultWH = !selectedARN.includes(":");
    67  
    68    let message = "Are you sure you want to delete the Configured Endpoint";
    69  
    70    // Main webhook, we just reset
    71    if (defaultWH) {
    72      message = "Are you sure you want to reset the Default";
    73    }
    74  
    75    return (
    76      <ConfirmDialog
    77        title={defaultWH ? `Reset Default Webhook` : `Delete Webhook`}
    78        confirmText={defaultWH ? "Reset" : "Delete"}
    79        isOpen={modalOpen}
    80        isLoading={deleteLoading}
    81        onConfirm={onConfirmDelete}
    82        titleIcon={<ConfirmDeleteIcon />}
    83        onClose={onClose}
    84        confirmationContent={
    85          <Fragment>
    86            {`${message} `}
    87            <strong>{selectedARN}</strong>?
    88          </Fragment>
    89        }
    90      />
    91    );
    92  };
    93  
    94  export default DeleteWebhookEndpoint;