ConceptPortal-public/rsconcept/frontend/src/features/oss/backend/use-relocate-constituents.tsx

26 lines
915 B
TypeScript
Raw Normal View History

import { useMutation, useQueryClient } from '@tanstack/react-query';
import { KEYS } from '@/backend/configuration';
import { ossApi } from './api';
import { type IRelocateConstituentsDTO } from './types';
export const useRelocateConstituents = () => {
const client = useQueryClient();
const mutation = useMutation({
2025-02-19 19:26:29 +03:00
mutationKey: [KEYS.global_mutation, ossApi.baseKey, 'relocate-constituents'],
mutationFn: ossApi.relocateConstituents,
onSuccess: data => {
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
return Promise.allSettled([
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
client.invalidateQueries({ queryKey: [KEYS.rsform] })
]);
2025-02-19 19:26:29 +03:00
},
onError: () => client.invalidateQueries()
});
return {
relocateConstituents: (data: IRelocateConstituentsDTO) => mutation.mutateAsync(data)
};
};