29 lines
876 B
TypeScript
29 lines
876 B
TypeScript
import * as api from "../service/ReviewService";
|
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
export const useGetReviews = (params?: Record<string, string | number>) => {
|
|
return useQuery({
|
|
queryKey: ["reviews", params],
|
|
queryFn: () => api.getReviews(params),
|
|
});
|
|
};
|
|
|
|
export const useGetReviewById = (id: string) => {
|
|
return useQuery({
|
|
queryKey: ["review", id],
|
|
queryFn: () => api.getReviewById(id),
|
|
});
|
|
};
|
|
|
|
export const useUpdateReviewStatus = () => {
|
|
const queryClient = useQueryClient();
|
|
return useMutation({
|
|
mutationFn: ({ id, status }: { id: string; status: string }) =>
|
|
api.updateReviewStatus(id, status),
|
|
onSuccess: (_, variables) => {
|
|
queryClient.invalidateQueries({ queryKey: ["reviews"] });
|
|
queryClient.invalidateQueries({ queryKey: ["review", variables.id] });
|
|
},
|
|
});
|
|
};
|