2025-01-23 19:41:31 +03:00
|
|
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
|
|
|
import { rsformsApi } from '@/backend/rsform/api';
|
2025-01-28 19:45:31 +03:00
|
|
|
import { VersionID } from '@/models/library';
|
2025-01-23 19:41:31 +03:00
|
|
|
|
|
|
|
import { libraryApi } from './api';
|
|
|
|
|
|
|
|
export const useVersionRestore = () => {
|
|
|
|
const client = useQueryClient();
|
|
|
|
const mutation = useMutation({
|
|
|
|
mutationKey: [libraryApi.baseKey, 'restore-version'],
|
|
|
|
mutationFn: libraryApi.versionRestore,
|
|
|
|
onSuccess: data => {
|
2025-01-28 19:45:31 +03:00
|
|
|
client.setQueryData(rsformsApi.getRSFormQueryOptions({ itemID: data.id }).queryKey, data);
|
2025-01-29 14:51:34 +03:00
|
|
|
return client.invalidateQueries({ queryKey: [libraryApi.baseKey] });
|
2025-01-23 19:41:31 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return {
|
2025-01-28 19:45:31 +03:00
|
|
|
versionRestore: (data: { versionID: VersionID }, onSuccess?: () => void) => mutation.mutate(data, { onSuccess })
|
2025-01-23 19:41:31 +03:00
|
|
|
};
|
|
|
|
};
|