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:
parent
70d8b1de2f
commit
e86ffa3a80
1 changed files with 14 additions and 8 deletions
|
@ -23,7 +23,11 @@ import useTenantPathname from '@/hooks/use-tenant-pathname';
|
||||||
import * as styles from './index.module.scss';
|
import * as styles from './index.module.scss';
|
||||||
import { type OrganizationRoleDetailsOutletContext } from './types';
|
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() {
|
function OrganizationRoleDetails() {
|
||||||
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' });
|
||||||
|
@ -34,7 +38,7 @@ function OrganizationRoleDetails() {
|
||||||
const isPageHasTable = pathname.endsWith(OrganizationRoleDetailsTabs.Permissions);
|
const isPageHasTable = pathname.endsWith(OrganizationRoleDetailsTabs.Permissions);
|
||||||
|
|
||||||
const { data, error, mutate, isLoading } = useSWR<OrganizationRole, RequestError>(
|
const { data, error, mutate, isLoading } = useSWR<OrganizationRole, RequestError>(
|
||||||
id && `api/organization-roles/${id}`
|
id && `${organizationRolesEndpoint}/${id}`
|
||||||
);
|
);
|
||||||
const api = useApi();
|
const api = useApi();
|
||||||
const { mutate: mutateGlobal } = useSWRConfig();
|
const { mutate: mutateGlobal } = useSWRConfig();
|
||||||
|
@ -54,10 +58,10 @@ function OrganizationRoleDetails() {
|
||||||
setIsDeleting(true);
|
setIsDeleting(true);
|
||||||
|
|
||||||
try {
|
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 }));
|
toast.success(t('organization_role_details.deleted', { name: data.name }));
|
||||||
await mutateGlobal('api/roles');
|
await mutateGlobal(organizationRolesEndpoint);
|
||||||
navigate(orgRolesPath, { replace: true });
|
navigate(organizationRolesPath, { replace: true });
|
||||||
} finally {
|
} finally {
|
||||||
setIsDeleting(false);
|
setIsDeleting(false);
|
||||||
}
|
}
|
||||||
|
@ -65,7 +69,7 @@ function OrganizationRoleDetails() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DetailsPage
|
<DetailsPage
|
||||||
backLink={orgRolesPath}
|
backLink={organizationRolesPath}
|
||||||
backLinkTitle="organization_role_details.back_to_org_roles"
|
backLinkTitle="organization_role_details.back_to_org_roles"
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
error={error}
|
error={error}
|
||||||
|
@ -104,11 +108,13 @@ function OrganizationRoleDetails() {
|
||||||
</ConfirmModal>
|
</ConfirmModal>
|
||||||
<TabNav>
|
<TabNav>
|
||||||
<TabNavItem
|
<TabNavItem
|
||||||
href={`${orgRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.Permissions}`}
|
href={`${organizationRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.Permissions}`}
|
||||||
>
|
>
|
||||||
<DynamicT forKey="organization_role_details.permissions.tab" />
|
<DynamicT forKey="organization_role_details.permissions.tab" />
|
||||||
</TabNavItem>
|
</TabNavItem>
|
||||||
<TabNavItem href={`${orgRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.General}`}>
|
<TabNavItem
|
||||||
|
href={`${organizationRolesPath}/${data.id}/${OrganizationRoleDetailsTabs.General}`}
|
||||||
|
>
|
||||||
<DynamicT forKey="organization_role_details.general.tab" />
|
<DynamicT forKey="organization_role_details.general.tab" />
|
||||||
</TabNavItem>
|
</TabNavItem>
|
||||||
</TabNav>
|
</TabNav>
|
||||||
|
|
Loading…
Reference in a new issue