mirror of
https://github.com/OpenMaxIO/openmaxio-object-browser
synced 2026-07-01 07:41:18 -07:00
Use swagger api for delete group (#3196)
This commit is contained in:
@@ -14,14 +14,15 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import React, { Fragment } from "react";
|
import React, { Fragment, useState } from "react";
|
||||||
import { ErrorResponseHandler } from "../../../common/types";
|
|
||||||
import { ConfirmDeleteIcon } from "mds";
|
import { ConfirmDeleteIcon } from "mds";
|
||||||
import { encodeURLString } from "../../../common/utils";
|
import { encodeURLString } from "../../../common/utils";
|
||||||
import { setErrorSnackMessage } from "../../../systemSlice";
|
import { setErrorSnackMessage } from "../../../systemSlice";
|
||||||
import { useAppDispatch } from "../../../store";
|
import { useAppDispatch } from "../../../store";
|
||||||
import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog";
|
import ConfirmDialog from "../Common/ModalWrapper/ConfirmDialog";
|
||||||
import useApi from "../Common/Hooks/useApi";
|
import { api } from "api";
|
||||||
|
import { errorToHandler } from "api/errors";
|
||||||
|
import { ApiError, HttpResponse } from "api/consoleApi";
|
||||||
|
|
||||||
interface IDeleteGroup {
|
interface IDeleteGroup {
|
||||||
selectedGroups: string[];
|
selectedGroups: string[];
|
||||||
@@ -35,21 +36,26 @@ const DeleteGroup = ({
|
|||||||
closeDeleteModalAndRefresh,
|
closeDeleteModalAndRefresh,
|
||||||
}: IDeleteGroup) => {
|
}: IDeleteGroup) => {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const onDelSuccess = () => closeDeleteModalAndRefresh(true);
|
|
||||||
const onDelError = (err: ErrorResponseHandler) => {
|
|
||||||
dispatch(setErrorSnackMessage(err));
|
|
||||||
closeDeleteModalAndRefresh(false);
|
|
||||||
};
|
|
||||||
const onClose = () => closeDeleteModalAndRefresh(false);
|
const onClose = () => closeDeleteModalAndRefresh(false);
|
||||||
|
const [loadingDelete, setLoadingDelete] = useState<boolean>(false);
|
||||||
const [deleteLoading, invokeDeleteApi] = useApi(onDelSuccess, onDelError);
|
|
||||||
|
|
||||||
if (!selectedGroups) {
|
if (!selectedGroups) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const onDeleteGroups = () => {
|
const onDeleteGroups = () => {
|
||||||
for (let group of selectedGroups) {
|
for (let group of selectedGroups) {
|
||||||
invokeDeleteApi("DELETE", `/api/v1/group/${encodeURLString(group)}`);
|
setLoadingDelete(true);
|
||||||
|
api.group
|
||||||
|
.removeGroup(encodeURLString(group))
|
||||||
|
.then((_) => {
|
||||||
|
closeDeleteModalAndRefresh(true);
|
||||||
|
})
|
||||||
|
.catch(async (res: HttpResponse<void, ApiError>) => {
|
||||||
|
const err = (await res.json()) as ApiError;
|
||||||
|
dispatch(setErrorSnackMessage(errorToHandler(err)));
|
||||||
|
closeDeleteModalAndRefresh(false);
|
||||||
|
})
|
||||||
|
.finally(() => setLoadingDelete(false));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,7 +71,7 @@ const DeleteGroup = ({
|
|||||||
confirmText={"Delete"}
|
confirmText={"Delete"}
|
||||||
isOpen={deleteOpen}
|
isOpen={deleteOpen}
|
||||||
titleIcon={<ConfirmDeleteIcon />}
|
titleIcon={<ConfirmDeleteIcon />}
|
||||||
isLoading={deleteLoading}
|
isLoading={loadingDelete}
|
||||||
onConfirm={onDeleteGroups}
|
onConfirm={onDeleteGroups}
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
confirmationContent={
|
confirmationContent={
|
||||||
|
|||||||
Reference in New Issue
Block a user