From 3502168a8b17aa20ed377fcde0595c8b64451603 Mon Sep 17 00:00:00 2001 From: Arda Samadi Date: Wed, 1 Jul 2026 16:00:23 +0330 Subject: [PATCH] feat(seller-team): split buyer inbox vs store inbox in chat UI Seller dashboard threads (type="store") now fetch the store's inbox via useGetStoreThreads(storeId) -> /threads/list/?store_id=; the profile threads page (type="user") keeps the personal buyer inbox. Depends on the seller-team backend (store-aware threads + store_id-by-username), so it ships on this branch, not main. Co-Authored-By: Claude Opus 4.8 --- app/components/thread/ThreadsPage.tsx | 16 ++++++++++++++-- app/requestHandler/use-chat-hooks.tsx | 24 ++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) 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 */