F: Add query invalidation after error in mutation
This commit is contained in:
parent
8c0d5bfca7
commit
be1edcd949
|
@ -10,7 +10,8 @@ export const useCloneItem = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'clone-item'],
|
||||
mutationFn: libraryApi.cloneItem,
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: [libraryApi.baseKey] })
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: [libraryApi.baseKey] }),
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cloneItem: (data: ICloneLibraryItemDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -10,7 +10,8 @@ export const useCreateItem = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'create-item'],
|
||||
mutationFn: libraryApi.createItem,
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: [libraryApi.baseKey] })
|
||||
onSuccess: () => client.invalidateQueries({ queryKey: [libraryApi.baseKey] }),
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
createItem: (data: ICreateLibraryItemDTO) => mutation.mutateAsync(data),
|
||||
|
|
|
@ -21,7 +21,8 @@ export const useDeleteItem = () => {
|
|||
]).catch(console.error),
|
||||
PARAMETER.navigationDuration
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
deleteItem: (target: number) => mutation.mutateAsync(target),
|
||||
|
|
|
@ -15,7 +15,8 @@ export const useRenameLocation = () => {
|
|||
client.invalidateQueries({ queryKey: [KEYS.library] }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] })
|
||||
])
|
||||
]),
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
renameLocation: (data: IRenameLocationDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -39,7 +39,8 @@ export const useSetAccessPolicy = () => {
|
|||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, access_policy: variables.policy } : item))
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -34,7 +34,8 @@ export const useSetEditors = () => {
|
|||
client.setQueryData(rsKey, (prev: IRSFormDTO | undefined) =>
|
||||
!prev ? undefined : { ...prev, editors: variables.editors }
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -39,7 +39,8 @@ export const useSetLocation = () => {
|
|||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, location: variables.location } : item))
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -39,7 +39,8 @@ export const useSetOwner = () => {
|
|||
client.setQueryData(libraryApi.libraryListKey, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === variables.itemID ? { ...item, owner: variables.owner } : item))
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
|
||||
return {
|
||||
|
|
|
@ -32,7 +32,8 @@ export const useUpdateItem = () => {
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
updateItem: (data: IUpdateLibraryItemDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -15,7 +15,8 @@ export const useVersionCreate = () => {
|
|||
onSuccess: data => {
|
||||
client.setQueryData(KEYS.composite.rsItem({ itemID: data.schema.id }), data.schema);
|
||||
updateTimestamp(data.schema.id);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
versionCreate: (data: { itemID: number; data: IVersionCreateDTO }) =>
|
||||
|
|
|
@ -20,7 +20,8 @@ export const useVersionDelete = () => {
|
|||
versions: prev.versions.filter(version => version.id !== variables.versionID)
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
versionDelete: (data: { itemID: number; versionID: number }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -12,7 +12,8 @@ export const useVersionRestore = () => {
|
|||
onSuccess: data => {
|
||||
client.setQueryData(KEYS.composite.rsItem({ itemID: data.id }), data);
|
||||
return client.invalidateQueries({ queryKey: [libraryApi.baseKey] });
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
versionRestore: (data: { versionID: number }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -23,7 +23,8 @@ export const useVersionUpdate = () => {
|
|||
)
|
||||
}
|
||||
);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
versionUpdate: (data: { itemID: number; version: IVersionUpdateDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { ossApi } from './api';
|
||||
|
||||
export const useFindPredecessor = () => {
|
||||
const client = useQueryClient();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [ossApi.baseKey, 'find-predecessor'],
|
||||
mutationFn: ossApi.getPredecessor
|
||||
mutationFn: ossApi.getPredecessor,
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
findPredecessor: (target: number) => mutation.mutateAsync({ target: target })
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useInputCreate = () => {
|
|||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
inputCreate: (data: { itemID: number; data: ITargetOperation }) =>
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useInputUpdate = () => {
|
|||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
inputUpdate: (data: { itemID: number; data: IInputUpdateDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useOperationCreate = () => {
|
|||
onSuccess: response => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: response.oss.id }).queryKey, response.oss);
|
||||
updateTimestamp(response.oss.id);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
operationCreate: (data: { itemID: number; data: IOperationCreateDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useOperationDelete = () => {
|
|||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
operationDelete: (data: { itemID: number; data: IOperationDeleteDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useOperationExecute = () => {
|
|||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
operationExecute: (data: { itemID: number; data: ITargetOperation }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -28,7 +28,8 @@ export const useOperationUpdate = () => {
|
|||
return client.invalidateQueries({
|
||||
queryKey: KEYS.composite.rsItem({ itemID: schemaID })
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
operationUpdate: (data: { itemID: number; data: IOperationUpdateDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useRelocateConstituents = () => {
|
|||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
relocateConstituents: (data: ICstRelocateDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { useMutation } from '@tanstack/react-query';
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { useUpdateTimestamp } from '@/features/library';
|
||||
|
||||
|
@ -8,11 +8,13 @@ import { ossApi } from './api';
|
|||
import { IOperationPosition } from './types';
|
||||
|
||||
export const useUpdatePositions = () => {
|
||||
const client = useQueryClient();
|
||||
const { updateTimestamp } = useUpdateTimestamp();
|
||||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'update-positions'],
|
||||
mutationFn: ossApi.updatePositions,
|
||||
onSuccess: (_, variables) => updateTimestamp(variables.itemID)
|
||||
onSuccess: (_, variables) => updateTimestamp(variables.itemID),
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
updatePositions: (data: {
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useCstCreate = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.schema.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstCreate: (data: { itemID: number; data: ICstCreateDTO }) =>
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useCstDelete = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstDelete: (data: { itemID: number; data: IConstituentaList }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -16,7 +16,8 @@ export const useCstMove = () => {
|
|||
onSuccess: data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstMove: (data: { itemID: number; data: ICstMoveDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useCstRename = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.schema.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstRename: (data: { itemID: number; data: ICstRenameDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useCstSubstitute = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstSubstitute: (data: { itemID: number; data: ICstSubstitutionsDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -20,7 +20,8 @@ export const useCstUpdate = () => {
|
|||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({ queryKey: [rsformsApi.baseKey] })
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
cstUpdate: (data: { itemID: number; data: ICstUpdateDTO }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useInlineSynthesis = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
inlineSynthesis: (data: IInlineSynthesisDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -24,7 +24,8 @@ export const useProduceStructure = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.schema.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
produceStructure: (data: { itemID: number; data: ITargetCst }) =>
|
||||
|
|
|
@ -23,7 +23,8 @@ export const useResetAliases = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
resetAliases: (data: { itemID: number }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -15,7 +15,8 @@ export const useRestoreOrder = () => {
|
|||
onSuccess: data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
restoreOrder: (data: { itemID: number }) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -25,7 +25,8 @@ export const useUploadTRS = () => {
|
|||
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
||||
})
|
||||
]);
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
upload: (data: IRSFormUploadDTO) => mutation.mutateAsync(data)
|
||||
|
|
|
@ -13,7 +13,8 @@ export const useUpdateProfile = () => {
|
|||
onSuccess: data => {
|
||||
client.setQueryData(usersApi.getProfileQueryOptions().queryKey, data);
|
||||
return client.invalidateQueries({ queryKey: usersApi.getUsersQueryOptions().queryKey });
|
||||
}
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
updateProfile: (data: IUpdateProfileDTO) => mutation.mutateAsync(data),
|
||||
|
|
Loading…
Reference in New Issue
Block a user