Portal/rsconcept/frontend/src/backend/library/useVersionUpdate.tsx

33 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-01-23 19:41:31 +03:00
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { IRSFormDTO, rsformsApi } from '@/backend/rsform/api';
2025-01-23 19:41:31 +03:00
2025-02-07 15:21:40 +03:00
import { IVersionUpdateDTO, libraryApi } from './api';
2025-01-23 19:41:31 +03:00
export const useVersionUpdate = () => {
const client = useQueryClient();
const mutation = useMutation({
mutationKey: [libraryApi.baseKey, 'update-version'],
mutationFn: libraryApi.versionUpdate,
onSuccess: data => {
2025-01-23 19:41:31 +03:00
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
)
}
2025-01-23 19:41:31 +03:00
);
}
});
return {
2025-02-07 15:21:40 +03:00
versionUpdate: (data: IVersionUpdateDTO, onSuccess?: () => void) => mutation.mutate(data, { onSuccess })
2025-01-23 19:41:31 +03:00
};
};