Client:OAuth2: fix delete operation

This commit is contained in:
Timofey Boyko 2023-11-08 17:25:30 +03:00
parent 9067d28459
commit 8c8df8af5a
2 changed files with 24 additions and 86 deletions

View File

@ -1,71 +0,0 @@
import React, { useEffect } from "react";
import ModalDialog from "@docspace/components/modal-dialog";
import Button from "@docspace/components/button";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
const StyledBodyText = styled.div`
line-height: 20px;
`;
const Footer = styled.div`
width: 100%;
display: flex;
button {
width: 100%;
}
button:first-of-type {
margin-right: 10px;
}
`;
const DeleteDialog = ({
visible,
onClose,
header,
handleSubmit,
currentClient,
}) => {
const onKeyPress = (e) =>
(e.key === "Esc" || e.key === "Escape") && onClose();
const { t } = useTranslation(["Common", "EmptyTrashDialog"]);
useEffect(() => {
window.addEventListener("keyup", onKeyPress);
return () => window.removeEventListener("keyup", onKeyPress);
});
const handleDeleteClick = () => {
handleSubmit(currentClient.id);
onClose();
};
return (
<ModalDialog visible={visible} onClose={onClose} displayType="modal">
<ModalDialog.Header>{`Delete profile`}</ModalDialog.Header>
<ModalDialog.Body>
<StyledBodyText>{`Do you want to delete profile: ${currentClient.name}`}</StyledBodyText>
</ModalDialog.Body>
<ModalDialog.Footer>
<Footer>
<Button
label={t("Common:Delete")}
size="normal"
primary={true}
onClick={handleDeleteClick}
/>
<Button
label={t("Common:CancelButton")}
size="normal"
onClick={onClose}
/>
</Footer>
</ModalDialog.Footer>
</ModalDialog>
);
};
export default DeleteDialog;

View File

@ -41,9 +41,6 @@ export interface OAuthStoreProps {
previewDialogVisible: boolean; previewDialogVisible: boolean;
setPreviewDialogVisible: (value: boolean) => void; setPreviewDialogVisible: (value: boolean) => void;
deleteDialogVisible: boolean;
setDeleteDialogVisible: (value: boolean) => void;
clientsIsLoading: boolean; clientsIsLoading: boolean;
setClientsIsLoading: (value: boolean) => void; setClientsIsLoading: (value: boolean) => void;
@ -64,7 +61,7 @@ export interface OAuthStoreProps {
regenerateSecret: (clientId: string) => Promise<string | undefined>; regenerateSecret: (clientId: string) => Promise<string | undefined>;
deleteClient: (clientId: string) => Promise<void>; deleteClient: (clientId: string[]) => Promise<void>;
currentPage: number; currentPage: number;
nextPage: number | null; nextPage: number | null;
@ -106,7 +103,6 @@ class OAuthStore implements OAuthStoreProps {
infoDialogVisible: boolean = false; infoDialogVisible: boolean = false;
previewDialogVisible: boolean = false; previewDialogVisible: boolean = false;
deleteDialogVisible: boolean = false;
selection: string[] = []; selection: string[] = [];
@ -136,10 +132,6 @@ class OAuthStore implements OAuthStoreProps {
this.previewDialogVisible = value; this.previewDialogVisible = value;
}; };
setDeleteDialogVisible = (value: boolean) => {
this.deleteDialogVisible = value;
};
setSelection = (clientId: string) => { setSelection = (clientId: string) => {
if (!clientId) { if (!clientId) {
this.selection = []; this.selection = [];
@ -301,9 +293,24 @@ class OAuthStore implements OAuthStoreProps {
} }
}; };
deleteClient = async (clientId: string) => { deleteClient = async (clientsId: string[]) => {
try { try {
await deleteClient(clientId); const requests: Promise<void>[] = [];
clientsId.forEach((id) => {
this.setActiveClient(id);
requests.push(deleteClient(id));
});
await Promise.all(requests);
runInAction(() => {
this.clients = this.clients.filter(
(c) => !clientsId.includes(c.clientId)
);
});
this.setActiveClient("");
} catch (e) { } catch (e) {
console.log(e); console.log(e);
} }
@ -339,11 +346,12 @@ class OAuthStore implements OAuthStoreProps {
const onDelete = () => { const onDelete = () => {
this.setInfoDialogVisible(false); this.setInfoDialogVisible(false);
this.setPreviewDialogVisible(false); this.setPreviewDialogVisible(false);
if (!isGroupContext) {
this.setBufferSelection(clientId);
}
this.setDeleteDialogVisible(true); if (!isGroupContext) {
this.deleteClient([clientId]);
} else {
this.deleteClient(this.selection);
}
}; };
const onShowInfo = () => { const onShowInfo = () => {
@ -361,6 +369,7 @@ class OAuthStore implements OAuthStoreProps {
const onEnable = async (status: boolean) => { const onEnable = async (status: boolean) => {
this.setInfoDialogVisible(false); this.setInfoDialogVisible(false);
this.setPreviewDialogVisible(false); this.setPreviewDialogVisible(false);
if (isGroupContext) { if (isGroupContext) {
try { try {
const actions: Promise<void>[] = []; const actions: Promise<void>[] = [];