ConceptPortal-public/rsconcept/frontend/src/features/library/backend/useVersionUpdate.tsx

32 lines
993 B
TypeScript
Raw Normal View History

import { useMutation, useQueryClient } from '@tanstack/react-query';
import { IRSFormDTO } from '@/features/rsform/backend/types';
2025-02-12 21:36:25 +03:00
import { KEYS } from '@/backend/configuration';
import { libraryApi } from './api';
import { IVersionUpdateDTO } from './types';
export const useVersionUpdate = () => {
const client = useQueryClient();
const mutation = useMutation({
mutationKey: [libraryApi.baseKey, 'update-version'],
mutationFn: libraryApi.versionUpdate,
onSuccess: data => {
client.setQueryData(KEYS.composite.rsItem({ itemID: data.item }), (prev: IRSFormDTO | undefined) =>
!prev
? undefined
: {
...prev,
versions: prev.versions.map(version =>
version.id === data.id ? { ...version, description: data.description, version: data.version } : version
)
}
);
}
});
return {
versionUpdate: (data: IVersionUpdateDTO) => mutation.mutateAsync(data)
};
};