mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
R: Fix onSuccess typing for react-query
This commit is contained in:
parent
ab86e0d7de
commit
46f3099b01
|
@ -10,12 +10,13 @@ export const useRenameLocation = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [libraryApi.baseKey, 'rename-location'],
|
||||
mutationFn: libraryApi.renameLocation,
|
||||
onSuccess: () =>
|
||||
Promise.allSettled([
|
||||
onSuccess: async () => {
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.library] }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] })
|
||||
]),
|
||||
]);
|
||||
},
|
||||
onError: () => client.invalidateQueries()
|
||||
});
|
||||
return {
|
||||
|
|
|
@ -16,12 +16,12 @@ export const useSetAccessPolicy = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-location'],
|
||||
mutationFn: libraryApi.setAccessPolicy,
|
||||
onSuccess: (_, variables) => {
|
||||
onSuccess: async (_, variables) => {
|
||||
const ossKey = KEYS.composite.ossItem({ itemID: variables.itemID });
|
||||
const ossData: IOperationSchemaDTO | undefined = client.getQueryData(ossKey);
|
||||
if (ossData) {
|
||||
client.setQueryData(ossKey, { ...ossData, access_policy: variables.policy });
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
...ossData.operations
|
||||
.map(item => {
|
||||
|
@ -33,6 +33,7 @@ export const useSetAccessPolicy = () => {
|
|||
})
|
||||
.filter(item => !!item)
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
const rsKey = KEYS.composite.rsItem({ itemID: variables.itemID });
|
||||
|
|
|
@ -12,12 +12,12 @@ export const useSetEditors = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-location'],
|
||||
mutationFn: libraryApi.setEditors,
|
||||
onSuccess: (_, variables) => {
|
||||
onSuccess: async (_, variables) => {
|
||||
const ossKey = KEYS.composite.ossItem({ itemID: variables.itemID });
|
||||
const ossData: IOperationSchemaDTO | undefined = client.getQueryData(ossKey);
|
||||
if (ossData) {
|
||||
client.setQueryData(ossKey, { ...ossData, editors: variables.editors });
|
||||
return Promise.allSettled(
|
||||
await Promise.allSettled(
|
||||
ossData.operations
|
||||
.map(item => {
|
||||
if (!item.result) {
|
||||
|
@ -28,6 +28,7 @@ export const useSetEditors = () => {
|
|||
})
|
||||
.filter(item => !!item)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const rsKey = KEYS.composite.rsItem({ itemID: variables.itemID });
|
||||
|
|
|
@ -16,12 +16,12 @@ export const useSetLocation = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-location'],
|
||||
mutationFn: libraryApi.setLocation,
|
||||
onSuccess: (_, variables) => {
|
||||
onSuccess: async (_, variables) => {
|
||||
const ossKey = KEYS.composite.ossItem({ itemID: variables.itemID });
|
||||
const ossData: IOperationSchemaDTO | undefined = client.getQueryData(ossKey);
|
||||
if (ossData) {
|
||||
client.setQueryData(ossKey, { ...ossData, location: variables.location });
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: libraryApi.libraryListKey }),
|
||||
...ossData.operations
|
||||
.map(item => {
|
||||
|
@ -33,6 +33,7 @@ export const useSetLocation = () => {
|
|||
})
|
||||
.filter(item => !!item)
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
const rsKey = KEYS.composite.rsItem({ itemID: variables.itemID });
|
||||
|
|
|
@ -16,12 +16,12 @@ export const useSetOwner = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'set-owner'],
|
||||
mutationFn: libraryApi.setOwner,
|
||||
onSuccess: (_, variables) => {
|
||||
onSuccess: async (_, variables) => {
|
||||
const ossKey = KEYS.composite.ossItem({ itemID: variables.itemID });
|
||||
const ossData: IOperationSchemaDTO | undefined = client.getQueryData(ossKey);
|
||||
if (ossData) {
|
||||
client.setQueryData(ossKey, { ...ossData, owner: variables.owner });
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: libraryApi.libraryListKey }),
|
||||
...ossData.operations
|
||||
.map(item => {
|
||||
|
|
|
@ -16,7 +16,7 @@ export const useUpdateItem = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, libraryApi.baseKey, 'update-item'],
|
||||
mutationFn: libraryApi.updateItem,
|
||||
onSuccess: (data: ILibraryItem) => {
|
||||
onSuccess: async (data: ILibraryItem) => {
|
||||
const itemKey =
|
||||
data.item_type === LibraryItemType.RSFORM
|
||||
? KEYS.composite.rsItem({ itemID: data.id })
|
||||
|
@ -30,7 +30,7 @@ export const useUpdateItem = () => {
|
|||
if (data.item_type === LibraryItemType.RSFORM) {
|
||||
const schema: IRSFormDTO | undefined = client.getQueryData(itemKey);
|
||||
if (schema) {
|
||||
return Promise.allSettled(
|
||||
await Promise.allSettled(
|
||||
schema.oss.map(item => client.invalidateQueries({ queryKey: KEYS.composite.ossItem({ itemID: item.id }) }))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useCreateInput = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'create-input'],
|
||||
mutationFn: ossApi.createInput,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.oss.id }).queryKey, data.oss);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useDeleteBlock = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'delete-block'],
|
||||
mutationFn: ossApi.deleteBlock,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useDeleteOperation = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'delete-operation'],
|
||||
mutationFn: ossApi.deleteOperation,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useExecuteOperation = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'execute-operation'],
|
||||
mutationFn: ossApi.executeOperation,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useMoveItems = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'move-items'],
|
||||
mutationFn: ossApi.moveItems,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useRelocateConstituents = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'relocate-constituents'],
|
||||
mutationFn: ossApi.relocateConstituents,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -10,9 +10,9 @@ export const useUpdateInput = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'update-input'],
|
||||
mutationFn: ossApi.updateInput,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
||||
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
||||
]);
|
||||
|
|
|
@ -13,11 +13,11 @@ export const useCreateConstituenta = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'create-constituenta'],
|
||||
mutationFn: rsformsApi.createConstituenta,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.schema.id }).queryKey, data.schema);
|
||||
updateTimestamp(data.schema.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -13,11 +13,11 @@ export const useDeleteConstituents = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'delete-constituents'],
|
||||
mutationFn: rsformsApi.deleteConstituents,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -13,11 +13,11 @@ export const useInlineSynthesis = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'inline-synthesis'],
|
||||
mutationFn: rsformsApi.inlineSynthesis,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -12,11 +12,11 @@ export const useProduceStructure = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'produce-structure'],
|
||||
mutationFn: rsformsApi.produceStructure,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.schema.id }).queryKey, data.schema);
|
||||
updateTimestamp(data.schema.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -13,11 +13,11 @@ export const useRenameConstituenta = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'rename-constituenta'],
|
||||
mutationFn: rsformsApi.renameConstituenta,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.schema.id }).queryKey, data.schema);
|
||||
updateTimestamp(data.schema.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -12,11 +12,11 @@ export const useResetAliases = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'reset-aliases'],
|
||||
mutationFn: rsformsApi.resetAliases,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -13,11 +13,11 @@ export const useSubstituteConstituents = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'substitute-constituents'],
|
||||
mutationFn: rsformsApi.substituteConstituents,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
||||
updateTimestamp(data.id);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
|
@ -13,10 +13,10 @@ export const useUpdateConstituenta = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'update-constituenta'],
|
||||
mutationFn: rsformsApi.updateConstituenta,
|
||||
onSuccess: (_, variables) => {
|
||||
onSuccess: async (_, variables) => {
|
||||
updateTimestamp(variables.itemID);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({ queryKey: [rsformsApi.baseKey] })
|
||||
]);
|
||||
|
|
|
@ -12,13 +12,13 @@ export const useUploadTRS = () => {
|
|||
const mutation = useMutation({
|
||||
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'load-trs'],
|
||||
mutationFn: rsformsApi.upload,
|
||||
onSuccess: data => {
|
||||
onSuccess: async data => {
|
||||
client.setQueryData(KEYS.composite.rsItem({ itemID: data.id }), data);
|
||||
client.setQueryData(KEYS.composite.libraryList, (prev: ILibraryItem[] | undefined) =>
|
||||
prev?.map(item => (item.id === data.id ? data : item))
|
||||
);
|
||||
|
||||
return Promise.allSettled([
|
||||
await Promise.allSettled([
|
||||
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
||||
client.invalidateQueries({
|
||||
queryKey: [rsformsApi.baseKey],
|
||||
|
|
Loading…
Reference in New Issue
Block a user