0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

feat(console): delete permission (#2831)

This commit is contained in:
Xiao Yijun 2023-01-06 23:15:08 +08:00 committed by GitHub
parent fdd5af2582
commit fff081f1be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 2 deletions

View file

@ -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<Scope>();
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: () => (
<IconButton>
render: (scope) => (
<IconButton
onClick={() => {
setScopeToBeDeleted(scope);
}}
>
<Delete />
</IconButton>
),
@ -105,6 +131,19 @@ const ApiResourcePermissions = () => {
}}
/>
)}
{scopeToBeDeleted && (
<ConfirmModal
isOpen
isLoading={isDeleting}
confirmButtonText="general.delete"
onCancel={() => {
setScopeToBeDeleted(undefined);
}}
onConfirm={handleDelete}
>
{t('api_resource_details.permission.delete_description')}
</ConfirmModal>
)}
</>
);
};

View file

@ -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
},
};

View file

@ -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',
},
};

View file

@ -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
},
};

View file

@ -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
},
};

View file

@ -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
},
};

View file

@ -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
},
};

View file

@ -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
},
};

View file

@ -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
},
};