@@ -16,17 +16,10 @@ import {
1616 type organizationsMembersListResponse ,
1717 type organizationsMembersRetrieveResponse ,
1818} from '#/api/react-query/user-team-organization-usage'
19- import { queryClient } from '#/query/queryClient'
2019import session from '#/stores/session'
2120import { getAssetUIDFromUrl } from '#/utils'
22- import {
23- invalidateItem ,
24- invalidateList ,
25- onErrorRestoreSnapshots ,
26- onSettledInvalidateSnapshots ,
27- optimisticallyUpdateItem ,
28- optimisticallyUpdateList ,
29- } from './common'
21+ import { queryClient } from '../queryClient'
22+ import { invalidateItem , invalidateList , optimisticallyUpdateItem , optimisticallyUpdateList } from './common'
3023
3124queryClient . setMutationDefaults (
3225 getOrganizationsPartialUpdateMutationOptions ( ) . mutationKey ! ,
@@ -52,6 +45,10 @@ queryClient.setMutationDefaults(
5245 * Note that:
5346 * - when creating an item then no need to invalidate any of existing items.
5447 * - when creating an item then invalidate member list as well, because KPI placeholds members based on invites.
48+ *
49+ * Also a good example when NOT to use optimistic updates, because:
50+ * - in current UI it would gain nothing to insert the single item cache
51+ * - it's impossible to guess the order of items in the lists, so don't even try
5552 */
5653 mutation : {
5754 onSettled : ( _data , _error , variables ) => {
@@ -94,8 +91,6 @@ queryClient.setMutationDefaults(
9491 snapshots : [ ...listSnapshots , itemSnapshot ] ,
9592 }
9693 } ,
97- onError : onErrorRestoreSnapshots ,
98- onSettled : onSettledInvalidateSnapshots ,
9994 } ,
10095 } ) ,
10196)
@@ -189,8 +184,6 @@ queryClient.setMutationDefaults(
189184 snapshots : [ ...invitesSnapshots , ...membersSnapshots , inviteSnapshot , memberSnapshot ] ,
190185 }
191186 } ,
192- onError : onErrorRestoreSnapshots ,
193- onSettled : onSettledInvalidateSnapshots ,
194187 } ,
195188 } ) ,
196189)
@@ -232,8 +225,6 @@ queryClient.setMutationDefaults(
232225 // If user is removing themselves, we need to clear the session
233226 if ( username === session . currentAccount ?. username ) session . refreshAccount ( )
234227 } ,
235- onError : onErrorRestoreSnapshots ,
236- onSettled : onSettledInvalidateSnapshots ,
237228 } ,
238229 } ) ,
239230)
@@ -282,8 +273,6 @@ queryClient.setMutationDefaults(
282273 snapshots : [ ...listSnapshots , memberSnapshot ] ,
283274 }
284275 } ,
285- onError : onErrorRestoreSnapshots ,
286- onSettled : onSettledInvalidateSnapshots ,
287276 } ,
288277 } ) ,
289278)
0 commit comments