From fff081f1beeba75a331b0b0a34fc824680bc3124 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Fri, 6 Jan 2023 23:15:08 +0800 Subject: [PATCH] feat(console): delete permission (#2831) --- .../ApiResourcePermissions/index.tsx | 43 ++++++++++++++++++- .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ .../admin-console/api-resource-details.ts | 3 ++ 9 files changed, 65 insertions(+), 2 deletions(-) diff --git a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx index 83353ca38..d3f1b15a3 100644 --- a/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx +++ b/packages/console/src/pages/ApiResourceDetails/ApiResourcePermissions/index.tsx @@ -8,10 +8,12 @@ import useSWR from 'swr'; import Delete from '@/assets/images/delete.svg'; import Plus from '@/assets/images/plus.svg'; import Button from '@/components/Button'; +import ConfirmModal from '@/components/ConfirmModal'; import IconButton from '@/components/IconButton'; import Search from '@/components/Search'; import Table from '@/components/Table'; import type { RequestError } from '@/hooks/use-api'; +import useApi from '@/hooks/use-api'; import type { ApiResourceDetailsOutletContext } from '../types'; import CreatePermissionModal from './components/CreatePermissionModal'; @@ -30,7 +32,27 @@ const ApiResourcePermissions = () => { const isLoading = !scopes && !error; + const api = useApi(); + const [isCreateFormOpen, setIsCreateFormOpen] = useState(false); + const [scopeToBeDeleted, setScopeToBeDeleted] = useState(); + const [isDeleting, setIsDeleting] = useState(false); + + const handleDelete = async () => { + if (!scopeToBeDeleted || isDeleting) { + return; + } + setIsDeleting(true); + + try { + await api.delete(`/api/resources/${resourceId}/scopes/${scopeToBeDeleted.id}`); + toast.success(t('api_resource_details.permission.deleted', { name: scopeToBeDeleted.name })); + await mutate(); + setScopeToBeDeleted(undefined); + } finally { + setIsDeleting(false); + } + }; return ( <> @@ -55,8 +77,12 @@ const ApiResourcePermissions = () => { title: null, dataIndex: 'delete', colSpan: 1, - render: () => ( - + render: (scope) => ( + { + setScopeToBeDeleted(scope); + }} + > ), @@ -105,6 +131,19 @@ const ApiResourcePermissions = () => { }} /> )} + {scopeToBeDeleted && ( + { + setScopeToBeDeleted(undefined); + }} + onConfirm={handleDelete} + > + {t('api_resource_details.permission.delete_description')} + + )} ); }; diff --git a/packages/phrases/src/locales/de/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/de/translation/admin-console/api-resource-details.ts index 0c6695ef9..04d7b9076 100644 --- a/packages/phrases/src/locales/de/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/de/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/en/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/en/translation/admin-console/api-resource-details.ts index 3665eb75b..c79550d92 100644 --- a/packages/phrases/src/locales/en/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/en/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', name_column: 'Permission', description_column: 'Description', + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', + deleted: 'The permission {{name}} has been successfully deleted', }, }; diff --git a/packages/phrases/src/locales/fr/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/fr/translation/admin-console/api-resource-details.ts index e3f14dfb0..6dbb2e580 100644 --- a/packages/phrases/src/locales/fr/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/fr/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/ko/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/ko/translation/admin-console/api-resource-details.ts index aa2aa50e9..82cab50b8 100644 --- a/packages/phrases/src/locales/ko/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/ko/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/pt-br/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/pt-br/translation/admin-console/api-resource-details.ts index 274b9e7a6..456c657fa 100644 --- a/packages/phrases/src/locales/pt-br/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/pt-br/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/pt-pt/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/pt-pt/translation/admin-console/api-resource-details.ts index 7740f1036..c8983d596 100644 --- a/packages/phrases/src/locales/pt-pt/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/pt-pt/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/tr-tr/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/tr-tr/translation/admin-console/api-resource-details.ts index 49b9f8f2a..3e493a5cb 100644 --- a/packages/phrases/src/locales/tr-tr/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/tr-tr/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, }; diff --git a/packages/phrases/src/locales/zh-cn/translation/admin-console/api-resource-details.ts b/packages/phrases/src/locales/zh-cn/translation/admin-console/api-resource-details.ts index 306c2b084..fa05e2ebd 100644 --- a/packages/phrases/src/locales/zh-cn/translation/admin-console/api-resource-details.ts +++ b/packages/phrases/src/locales/zh-cn/translation/admin-console/api-resource-details.ts @@ -23,6 +23,9 @@ const api_resource_details = { permission_created: 'The permission {{name}} has been successfully created', // UNTRANSLATED name_column: 'Permission', // UNTRANSLATED description_column: 'Description', // UNTRANSLATED + delete_description: + 'If this permission is deleted, the user who had this permission will lose the access granted by it.', // UNTRANSLATED + deleted: 'The permission {{name}} has been successfully deleted', // UNTRANSLATED }, };