Files
mtdb_movie/common/resources/client/comments/requests/use-restore-comments.ts
maher 703f50a09d
Some checks failed
Build / run (push) Has been cancelled
first commit
2025-10-29 11:42:25 +01:00

33 lines
972 B
TypeScript
Executable File

import {useMutation} from '@tanstack/react-query';
import {apiClient} from '../../http/query-client';
import {BackendResponse} from '../../http/backend-response/backend-response';
import {toast} from '../../ui/toast/toast';
import {message} from '../../i18n/message';
import {showHttpErrorToast} from '../../utils/http/show-http-error-toast';
interface Response extends BackendResponse {
//
}
interface Payload {
commentIds: number[];
}
export function useRestoreComments() {
return useMutation({
mutationFn: (payload: Payload) => restoreComment(payload),
onSuccess: (response, payload) => {
toast(
message('Restored [one 1 comment|other :count comments]', {
values: {count: payload.commentIds.length},
}),
);
},
onError: err => showHttpErrorToast(err),
});
}
function restoreComment({commentIds}: Payload): Promise<Response> {
return apiClient.post('comment/restore', {commentIds}).then(r => r.data);
}