From 2d5cb9c7507120ccbecb39244aa6517fde198026 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Thu, 31 Aug 2023 15:06:17 +0200 Subject: [PATCH] Fix person deletion not reflected on Opportunities POC (#1387) * Fix person deletion not reflected on Opportunities POC * Fix companies, user deletion --- .../companies/hooks/useDeleteCompanies.ts | 7 ++----- .../hooks/usePersonTableActionBarEntries.tsx | 6 +++++- .../pages/settings/SettingsWorkspaceMembers.tsx | 17 +++++++++++------ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/front/src/modules/companies/hooks/useDeleteCompanies.ts b/front/src/modules/companies/hooks/useDeleteCompanies.ts index 56687fb891..87f741ee99 100644 --- a/front/src/modules/companies/hooks/useDeleteCompanies.ts +++ b/front/src/modules/companies/hooks/useDeleteCompanies.ts @@ -38,14 +38,11 @@ export function useDeleteSelectedComapnies() { tableRowIds.filter((id) => !rowIdsToDelete.includes(id)), ); - // Manually update the cache to match the mutations rowIdsToDelete.forEach((companyId) => { cache.evict({ - id: cache.identify({ - __typename: 'Company', - id: companyId, - }), + id: cache.identify({ __typename: 'Company', id: companyId }), }); + cache.gc(); }); }, }); diff --git a/front/src/modules/people/hooks/usePersonTableActionBarEntries.tsx b/front/src/modules/people/hooks/usePersonTableActionBarEntries.tsx index 0e3068e1de..243990417f 100644 --- a/front/src/modules/people/hooks/usePersonTableActionBarEntries.tsx +++ b/front/src/modules/people/hooks/usePersonTableActionBarEntries.tsx @@ -47,10 +47,14 @@ export function usePersonTableActionBarEntries() { count: rowIdsToDelete.length, }, }, - update: () => { + update: (cache) => { setTableRowIds( tableRowIds.filter((id) => !rowIdsToDelete.includes(id)), ); + rowIdsToDelete.forEach((id) => { + cache.evict({ id: cache.identify({ id, __typename: 'Person' }) }); + cache.gc(); + }); }, }); } diff --git a/front/src/pages/settings/SettingsWorkspaceMembers.tsx b/front/src/pages/settings/SettingsWorkspaceMembers.tsx index 8ce26292e1..c5ba14ea9c 100644 --- a/front/src/pages/settings/SettingsWorkspaceMembers.tsx +++ b/front/src/pages/settings/SettingsWorkspaceMembers.tsx @@ -64,15 +64,20 @@ export function SettingsWorkspaceMembers() { return; } - const normalizedId = cache.identify({ - id: responseData.deleteWorkspaceMember.id, - __typename: 'WorkspaceMember', + cache.evict({ + id: cache.identify({ + id: responseData.deleteWorkspaceMember.id, + __typename: 'WorkspaceMember', + }), }); - // Evict object from cache - cache.evict({ id: normalizedId }); + cache.evict({ + id: cache.identify({ + id: userId, + __typename: 'User', + }), + }); - // Clean up relation to this object cache.gc(); }, });