diff --git a/app/components/thread/ThreadsPage.tsx b/app/components/thread/ThreadsPage.tsx index c207772..eb949c3 100644 --- a/app/components/thread/ThreadsPage.tsx +++ b/app/components/thread/ThreadsPage.tsx @@ -1,7 +1,10 @@ import { Link } from "@remix-run/react"; import AppInput from "../AppInput"; import { useState } from "react"; -import { useGetUserThreads } from "../../requestHandler/use-chat-hooks"; +import { + useGetUserThreads, + useGetStoreThreads, +} from "../../requestHandler/use-chat-hooks"; import { ThreadList, ThreadParticipant, @@ -20,7 +23,16 @@ interface ThreadsPageProps { export default function ThreadsPage({ type, storeId }: ThreadsPageProps) { const [searchValue, setSearchValue] = useState(""); - const { data: threads, isLoading, isError, refetch } = useGetUserThreads(); + // Seller dashboard shows the STORE's inbox; the profile page shows the user's + // personal (buyer) chats. Two different endpoints so the two never mix. + const userThreads = useGetUserThreads(); + const storeThreads = useGetStoreThreads(type === "store" ? storeId : undefined); + const { + data: threads, + isLoading, + isError, + refetch, + } = type === "store" ? storeThreads : userThreads; const sortedThreads = threads?.sort((a, b) => { const dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z"); const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z"); diff --git a/app/requestHandler/use-chat-hooks.tsx b/app/requestHandler/use-chat-hooks.tsx index 5425ea4..a92b739 100644 --- a/app/requestHandler/use-chat-hooks.tsx +++ b/app/requestHandler/use-chat-hooks.tsx @@ -31,6 +31,30 @@ export function useGetUserThreads() { }); } +/** + * List a STORE's inbox (owner + staff), scoped to the store's own threads. + * Distinct from useGetUserThreads(), which returns the user's personal buyer chats. + */ +export function useGetStoreThreads(storeId?: string) { + const token = useAuthToken(); + + return useQuery({ + queryKey: ["getStoreThreads", storeId], + queryFn: async () => { + if (!token) { + throw new Error("Authentication token is required"); + } + const chatApi = createChatApi(token); + return await chatApi.apiChatV1ThreadsListList({ storeId }); + }, + enabled: !!token && !!storeId, + retry: 1, + retryDelay: 3000, + refetchOnWindowFocus: false, + refetchInterval: 20 * 1000, + }); +} + /** * Server-side function to get thread details */