| 12345678910111213141516171819202122232425262728293031323334 |
- "use client";
- import { useMutation, useQueryClient } from "@tanstack/react-query";
- import { useCurrentUser } from "@/hooks/use-current-user";
- async function deleteMovie(movieId: string) {
- const res = await fetch(`/api/movies/${movieId}`, {
- method: "DELETE",
- });
- if (!res.ok) {
- const data = await res.json().catch(() => ({}));
- throw new Error(data.error || "Failed to delete movie");
- }
- return res.json();
- }
- export function useDeleteMovie(groupId: string) {
- const queryClient = useQueryClient();
- const { data: currentUser } = useCurrentUser();
- return useMutation({
- mutationFn: deleteMovie,
- onSuccess: () => {
- void queryClient.invalidateQueries({ queryKey: ["group-movies", groupId] });
- if (currentUser) {
- void queryClient.invalidateQueries({
- queryKey: ["all-user-movies", currentUser.id],
- });
- }
- },
- });
- }
|