2025-01-23 19:41:31 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
import { libraryApi } from '@/features/library';
|
2025-02-10 01:32:16 +03:00
|
|
|
import { rsformsApi } from '@/features/rsform/backend/api';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
|
|
|
import { ICstRelocateDTO, ossApi } from './api';
|
|
|
|
|
|
|
|
export const useRelocateConstituents = () => {
|
|
|
|
const client = useQueryClient();
|
|
|
|
const mutation = useMutation({
|
|
|
|
mutationKey: [ossApi.baseKey, 'relocate-constituents'],
|
|
|
|
mutationFn: ossApi.relocateConstituents,
|
2025-01-29 14:51:34 +03:00
|
|
|
onSuccess: data => {
|
2025-01-28 19:45:31 +03:00
|
|
|
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
2025-01-29 14:51:34 +03:00
|
|
|
return Promise.allSettled([
|
|
|
|
client.invalidateQueries({ queryKey: libraryApi.libraryListKey }),
|
|
|
|
client.invalidateQueries({ queryKey: [rsformsApi.baseKey] })
|
|
|
|
]);
|
2025-01-23 19:41:31 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
2025-02-11 20:15:34 +03:00
|
|
|
relocateConstituents: (data: ICstRelocateDTO) => mutation.mutateAsync(data)
|
2025-01-23 19:41:31 +03:00
|
|
|
};
|
|
|
|
};
|