2025-01-27 15:03:48 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
2025-02-12 20:53:31 +03:00
|
|
|
import { KEYS } from '@/backend/configuration';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
2025-02-12 20:53:31 +03:00
|
|
|
import { ossApi } from './api';
|
2025-02-21 21:15:05 +03:00
|
|
|
import { type ICstRelocateDTO } from './types';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
|
|
|
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'],
|
2025-01-27 15:03:48 +03:00
|
|
|
mutationFn: ossApi.relocateConstituents,
|
2025-01-29 14:52:07 +03:00
|
|
|
onSuccess: data => {
|
2025-01-28 19:47:24 +03:00
|
|
|
client.setQueryData(ossApi.getOssQueryOptions({ itemID: data.id }).queryKey, data);
|
2025-01-29 14:52:07 +03:00
|
|
|
return Promise.allSettled([
|
2025-02-12 20:53:31 +03:00
|
|
|
client.invalidateQueries({ queryKey: KEYS.composite.libraryList }),
|
|
|
|
client.invalidateQueries({ queryKey: [KEYS.rsform] })
|
2025-01-29 14:52:07 +03:00
|
|
|
]);
|
2025-02-19 19:26:29 +03:00
|
|
|
},
|
|
|
|
onError: () => client.invalidateQueries()
|
2025-01-27 15:03:48 +03:00
|
|
|
});
|
|
|
|
return {
|
2025-02-11 20:16:11 +03:00
|
|
|
relocateConstituents: (data: ICstRelocateDTO) => mutation.mutateAsync(data)
|
2025-01-27 15:03:48 +03:00
|
|
|
};
|
|
|
|
};
|