0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

fix(console): mutate org roles once a org role is deleted (#5716)

This commit is contained in:
Xiao Yijun 2024-04-15 21:12:21 +08:00 committed by GitHub
parent 70d8b1de2f
commit e86ffa3a80
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -23,7 +23,11 @@ import useTenantPathname from '@/hooks/use-tenant-pathname';
import * as styles from './index.module.scss';
import { type OrganizationRoleDetailsOutletContext } from './types';
const orgRolesPath = `/organization-template/${OrganizationTemplateTabs.OrganizationRoles}`;
// Console path for organization roles
const organizationRolesPath = `/organization-template/${OrganizationTemplateTabs.OrganizationRoles}`;
// API endpoint for organization roles
const organizationRolesEndpoint = 'api/organization-roles';
function OrganizationRoleDetails() {
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
@ -34,7 +38,7 @@ function OrganizationRoleDetails() {
const isPageHasTable = pathname.endsWith(OrganizationRoleDetailsTabs.Permissions);
const { data, error, mutate, isLoading } = useSWR<OrganizationRole, RequestError>(
id && `api/organization-roles/${id}`
id && `${organizationRolesEndpoint}/${id}`
);
const api = useApi();
const { mutate: mutateGlobal } = useSWRConfig();
@ -54,10 +58,10 @@ function OrganizationRoleDetails() {
setIsDeleting(true);
try {
await api.delete(`api/organization-roles/${data.id}`);
await api.delete(`${organizationRolesEndpoint}/${data.id}`);
toast.success(t('organization_role_details.deleted', { name: data.name }));
await mutateGlobal('api/roles');
navigate(orgRolesPath, { replace: true });
await mutateGlobal(organizationRolesEndpoint);
navigate(organizationRolesPath, { replace: true });
} finally {
setIsDeleting(false);
}
@ -65,7 +69,7 @@ function OrganizationRoleDetails() {
return (
<DetailsPage
backLink={orgRolesPath}
backLink={organizationRolesPath}
backLinkTitle="organization_role_details.back_to_org_roles"
isLoading={isLoading}
error={error}
@ -104,11 +108,13 @@ function OrganizationRoleDetails() {
</ConfirmModal>
<TabNav>
<TabNavItem
href={`${orgRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.Permissions}`}
href={`${organizationRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.Permissions}`}
>
<DynamicT forKey="organization_role_details.permissions.tab" />
</TabNavItem>
<TabNavItem href={`${orgRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.General}`}>
<TabNavItem
href={`${organizationRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.General}`}
>
<DynamicT forKey="organization_role_details.general.tab" />
</TabNavItem>
</TabNav>