2025-01-23 19:41:31 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
2025-02-12 15:12:59 +03:00
|
|
|
import { useUpdateTimestamp } from '@/features/library';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
2025-02-12 21:36:03 +03:00
|
|
|
import { KEYS } from '@/backend/configuration';
|
|
|
|
|
2025-02-12 20:53:01 +03:00
|
|
|
import { rsformsApi } from './api';
|
|
|
|
import { IInlineSynthesisDTO } from './types';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
|
|
|
export const useInlineSynthesis = () => {
|
|
|
|
const client = useQueryClient();
|
|
|
|
const { updateTimestamp } = useUpdateTimestamp();
|
|
|
|
const mutation = useMutation({
|
2025-02-19 19:15:57 +03:00
|
|
|
mutationKey: [KEYS.global_mutation, rsformsApi.baseKey, 'inline-synthesis'],
|
2025-01-23 19:41:31 +03:00
|
|
|
mutationFn: rsformsApi.inlineSynthesis,
|
|
|
|
onSuccess: data => {
|
2025-01-28 19:45:31 +03:00
|
|
|
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
2025-01-23 19:41:31 +03:00
|
|
|
updateTimestamp(data.id);
|
2025-01-29 14:51:34 +03:00
|
|
|
|
|
|
|
return Promise.allSettled([
|
2025-02-12 20:53:01 +03:00
|
|
|
client.invalidateQueries({ queryKey: [KEYS.oss] }),
|
2025-01-29 14:51:34 +03:00
|
|
|
client.invalidateQueries({
|
|
|
|
queryKey: [rsformsApi.baseKey],
|
|
|
|
predicate: query => query.queryKey.length > 2 && query.queryKey[2] !== data.id
|
|
|
|
})
|
|
|
|
]);
|
2025-01-23 19:41:31 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
2025-02-12 12:20:52 +03:00
|
|
|
inlineSynthesis: (data: IInlineSynthesisDTO) => mutation.mutateAsync(data)
|
2025-01-23 19:41:31 +03:00
|
|
|
};
|
|
|
|
};
|