mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-25 20:40:36 +03:00
26 lines
880 B
TypeScript
26 lines
880 B
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
import { KEYS } from '@/backend/configuration';
|
|
|
|
import { ossApi } from './api';
|
|
import { type IMoveItemsDTO } from './types';
|
|
|
|
export const useMoveItems = () => {
|
|
const client = useQueryClient();
|
|
const mutation = useMutation({
|
|
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'move-items'],
|
|
mutationFn: ossApi.moveItems,
|
|
onSuccess: async data => {
|
|
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
|
await Promise.allSettled([
|
|
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
|
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
|
]);
|
|
},
|
|
onError: () => client.invalidateQueries()
|
|
});
|
|
return {
|
|
moveItems: (data: { itemID: number; data: IMoveItemsDTO }) => mutation.mutateAsync(data)
|
|
};
|
|
};
|