Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions packages/console/src/pages/OrganizationRoleDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand All @@ -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();
Expand All @@ -54,18 +58,18 @@ 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);
}
};

return (
<DetailsPage
backLink={orgRolesPath}
backLink={organizationRolesPath}
backLinkTitle="organization_role_details.back_to_org_roles"
isLoading={isLoading}
error={error}
Expand Down Expand Up @@ -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>
Expand Down
Loading