Skip to content

Commit ba6ec7b

Browse files
committed
fix: Don’t re-request a deleted role in the background
https://harperdb.atlassian.net/browse/FAB-402
1 parent 6435775 commit ba6ec7b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/features/organization/roles/modals/EditOrganizationRoleModal.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { SchemaOrganizationRole } from '@/integrations/api/api.gen';
2222
import { safeParse } from '@/lib/string/safeParse';
2323
import { zodResolver } from '@hookform/resolvers/zod';
2424
import { Editor } from '@monaco-editor/react';
25-
import { useSuspenseQuery } from '@tanstack/react-query';
25+
import { useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
2626
import { useCallback, useState } from 'react';
2727
import { useForm } from 'react-hook-form';
2828
import { toast } from 'sonner';
@@ -37,6 +37,7 @@ export function EditOrganizationRoleModal({
3737
isModalOpen: boolean;
3838
closeModal: (madeChanges: boolean) => void;
3939
}) {
40+
const queryClient = useQueryClient();
4041
const { data: roleInfo } = useSuspenseQuery(
4142
getOrganizationRoleInfoQueryOptions({ roleId: data.id, organizationId: data.organizationId }),
4243
);
@@ -52,8 +53,8 @@ export function EditOrganizationRoleModal({
5253
resolver: zodResolver(OrganizationRoleOverviewSchema),
5354
defaultValues: {
5455
name: data.roleName,
55-
update: roleInfo?.organization.update || false,
56-
delete: roleInfo?.organization.delete || false,
56+
update: roleInfo.organization.update || false,
57+
delete: roleInfo.organization.delete || false,
5758
},
5859
});
5960

@@ -120,9 +121,12 @@ export function EditOrganizationRoleModal({
120121
updatedRoleInfo: updatedFormData,
121122
},
122123
{
123-
onSuccess: () => {
124+
onSuccess: async () => {
124125
toast.success('Role updated successfully!');
125-
closeModal(true);
126+
await queryClient.invalidateQueries({
127+
queryKey: [data.organizationId, 'roles', data.id],
128+
});
129+
closeModal(false);
126130
form.reset();
127131
},
128132
onError: (error: Error | unknown) => {
@@ -144,6 +148,7 @@ export function EditOrganizationRoleModal({
144148
data.organizationId,
145149
form,
146150
isValidJSON,
151+
queryClient,
147152
roleInfo,
148153
update,
149154
updatedPermissions,

0 commit comments

Comments
 (0)