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

33 lines
1021 B
TypeScript
Raw Normal View History

import { useMutation, useQueryClient } from '@tanstack/react-query';
import { IRSFormDTO, rsformsApi } from '@/features/rsform/backend/api';
2025-02-07 15:30:47 +03:00
import { IVersionUpdateDTO, libraryApi } from './api';
export const useVersionUpdate = () => {
const client = useQueryClient();
const mutation = useMutation({
mutationKey: [libraryApi.baseKey, 'update-version'],
mutationFn: libraryApi.versionUpdate,
onSuccess: data => {
client.setQueryData(
rsformsApi.getRSFormQueryOptions({ itemID: data.item }).queryKey,
(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)
};
};