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 <noreply@anthropic.com>
This commit is contained in:
Arda Samadi 2026-07-01 16:00:23 +03:30
parent e60a03ac65
commit 3502168a8b
2 changed files with 38 additions and 2 deletions

View File

@ -1,7 +1,10 @@
import { Link } from "@remix-run/react"; import { Link } from "@remix-run/react";
import AppInput from "../AppInput"; import AppInput from "../AppInput";
import { useState } from "react"; import { useState } from "react";
import { useGetUserThreads } from "../../requestHandler/use-chat-hooks"; import {
useGetUserThreads,
useGetStoreThreads,
} from "../../requestHandler/use-chat-hooks";
import { import {
ThreadList, ThreadList,
ThreadParticipant, ThreadParticipant,
@ -20,7 +23,16 @@ interface ThreadsPageProps {
export default function ThreadsPage({ type, storeId }: ThreadsPageProps) { export default function ThreadsPage({ type, storeId }: ThreadsPageProps) {
const [searchValue, setSearchValue] = useState(""); 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 sortedThreads = threads?.sort((a, b) => {
const dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z"); const dateA = new Date(a.lastMessageTime || "2025-01-18T00:00:00.000Z");
const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z"); const dateB = new Date(b.lastMessageTime || "2025-01-18T00:00:00.000Z");

View File

@ -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 * Server-side function to get thread details
*/ */