Skip to content

Commit

Permalink
feat: invalidate fetch queries on creating new chats
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthyyy committed May 23, 2024
1 parent 53b2868 commit dd1f7c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
DialogHeader,
DialogTitle,
} from "../ui/dialog";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import axios from "axios";
import { ALL_USERS_ENDPOINT } from "@/lib/constants";
import { ScrollArea } from "../ui/scroll-area";
Expand All @@ -24,6 +24,7 @@ import { useState } from "react";
import useUserProfile from "@/hooks/use-user-profile";

const NewConversationModal = () => {
const queryClient = useQueryClient();
const { data: session } = useSession();
const { data: userProfile, isPending: isUserProfilePending } =
useUserProfile();
Expand Down Expand Up @@ -90,6 +91,9 @@ const NewConversationModal = () => {
onClick={() => {
const convId = generateConversationId(user.id, userProfile?.id);
router.push(`/chat/${convId}`);
queryClient.invalidateQueries({
queryKey: ["conversations"],
});
setSearchTerm("");
onClose();
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { useRouter } from "next/navigation";
import { useModal } from "@/hooks/use-modal-store";
import { CREATE_GROUP_ENDPOINT } from "@/lib/constants";
import { useSession } from "next-auth/react";
import { useQueryClient } from "@tanstack/react-query";

const schema = z.object({
name: z.string().min(1, { message: "Name is required" }),
Expand All @@ -37,6 +38,7 @@ const schema = z.object({

const NewGroupModal = () => {
const { data: session } = useSession();
const queryClient = useQueryClient();
const { toast } = useToast();
const router = useRouter();
const { isOpen, onClose, type } = useModal();
Expand Down Expand Up @@ -65,6 +67,10 @@ const NewGroupModal = () => {
},
}
);

queryClient.invalidateQueries({
queryKey: ["groups"],
});
form.reset();
router.push(`/chat/group-${data.id}`);
onClose();
Expand Down

0 comments on commit dd1f7c3

Please sign in to comment.